admin管理员组文章数量:1332395
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")
本文标签: javascriptChange video resolution with JSStack Overflow
版权声明:本文标题:javascript - Change video resolution with JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742282720a2446390.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论