I'm developing a video storage service for users and I need that large videos (v.g. 4K) can be pressed to 1080p before saving them. Is there a JS library (browser or Node) that helps with this task? Maybe a webservice?
I also accept language suggestions.
I'm developing a video storage service for users and I need that large videos (v.g. 4K) can be pressed to 1080p before saving them. Is there a JS library (browser or Node) that helps with this task? Maybe a webservice?
I also accept language suggestions.
Share Improve this question asked Jan 21, 2020 at 20:32 StevenSteven 3313 silver badges14 bronze badges2 Answers
Reset to default 10When it es to downscaling video, the most accessible option is ffmpeg.
There is a package that makes using ffmpeg in node.js easier: https://www.npmjs./package/fluent-ffmpeg
For example, downscaling a video to 1080p and 720p:
var ffmpeg = require('fluent-ffmpeg');
function baseName(str) {
var base = new String(str).substring(str.lastIndexOf('/') + 1);
if(base.lastIndexOf(".") != -1) {
base = base.substring(0, base.lastIndexOf("."));
}
return base;
}
var args = process.argv.slice(2);
args.forEach(function (val, index, array) {
var filename = val;
var basename = baseName(filename);
console.log(index + ': Input File ... ' + filename);
ffmpeg(filename)
.output(basename + '-1280x720.mp4')
.videoCodec('libx264')
.size('1280x720')
.output(basename + '-1920x1080.mp4')
.videoCodec('libx264')
.size('1920x1080')
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('progress', function(progress) {
console.log('... frames: ' + progress.frames);
})
.on('end', function() {
console.log('Finished processing');
})
.run();
});
(source: https://gist.github./dkarchmer/635496ff9280011b3eef)
You don't need any node packages to run ffmpeg, you could make use of the child_process
API in node.js.
The ffmpeg package has to be installed on the server that will be running your application.
.format("h264") √ .format("mp4") ×
or add .outputOptions(['-movflags isml+frag_keyframe']) .format("mp4")
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742282721a4414785.html
评论列表(0条)