柚子快报邀请码778899分享:视频处理工具

http://www.51969.com/

ffmpeg非常好用

Win10 下安装

https://github.com/BtbN/FFmpeg-Builds/releases

windows 压缩包,解压,配置好环境路径

改变视频分辨率

$ ffmpeg \

-i input.mp4 \

-vf scale=480:-1 \

output.mp4

cd /d D:\exercise\mp4

ffmpeg -i 1.mp4 -vf scale=1280:-1 1280.mp4

ffmpeg scale

如果想要保持宽高比,那么我们需要先手动固定一个元素

,比如宽度,或者高度,然后另外一个视情况而定。用下面的写法:

ffmpeg -i input.jpg -vf scale=320:-1 output_320.png

https://zhuanlan.zhihu.com/p/143268167

nodejs 批量处理文件

/**

* 文件说明:

*

* 遍历出所有的视频文件出来,压缩,生成新的视频文件,再删除了旧的视频文件

*

* 运行:

* node compress-video

*

*/

var fs = require('fs');

var path = require('path');

var exec = require('child_process').exec;

function walkSync(currentDirPath, callback) {

fs.readdirSync(currentDirPath, { withFileTypes: true }).forEach(function(dirent) {

var filePath = path.join(currentDirPath, dirent.name);

if (dirent.isFile()) {

callback(filePath, dirent);

} else if (dirent.isDirectory()) {

walkSync(filePath, callback);

}

});

}

var resDir = `.`;

var arrCmd = [];

walkSync(resDir, function(filePath, stat) {

var isVideo = (filePath.indexOf(".mp4") >= 0);

if (!isVideo) {

return ;

}

var dirName = path.dirname(filePath);

var fileName = path.basename(filePath);

var newFilePath = dirName + "/min-" + fileName;

var cmd = "ffmpeg -i \"" + filePath +"\" -vf scale=1280:-1 \"" + newFilePath +"\"";

var obj = {};

obj.cmd = cmd;

obj.oldFilePath = filePath;

obj.newFilePath = newFilePath;

arrCmd.push(obj);

console.log(cmd);

});

console.log("-----------");

arrCmd.forEach((obj) => {

let cmd = obj.cmd;

let oldFilePath = obj.oldFilePath;

exec(cmd, function(error, stdout, stderr) {

if(error){

console.error(error);

} else {

var msg = cmd + " success!";

console.log(msg);

fs.unlinkSync(oldFilePath);

}

});

});

柚子快报邀请码778899分享:视频处理工具

http://www.51969.com/

查看原文