首先使用以下命令剪切视频:
const cutVideo = async (currentWord) => {
return new Promise((resolve, reject) => {
console.log('cutting video', currentWord.file)
ffmpeg(currentWord.file)
.videoCodec('libx264')
// .addOptions('-vf "setdar=ratio=16/9:max=1000"')
.on('start', command => console.log('command', command))
.on('error', reject)
.on('end', resolve)
.withSize('640x360')
.withAspect('16:9')
.applyAutopadding(true, 'black')
.saveToFile(currentWord.file.replace('-unfinished', ''), './')
})
}
稍后使用.mergeToFile()
命令将它们合并在一起:
const mergeFilesAsync = async function(files, folder, filename)
{
return new Promise((resolve, reject) => {
console.log('merging files', files)
var cmd = ffmpeg({ logger: console })
.videoCodec('libx264')
.on('start', command => console.log('command', command))
.on('error', reject)
.on('end', resolve)
for (var i = 0; i < files.length; i++)
{
const currentWord = files[i]
cmd.input(currentWord.file.replace('-unfinished', ''))
}
cmd.mergeToFile(folder + "/" + filename, folder);
});
}
在cutVideo功能中调整大小的视频的尺寸应为640x360,宽高比为16:9。
第一个处理的视频尺寸为:850××480,处理后的输出为:642××360(应为640x360)
处理后的第二个视频的尺寸为:1152××480,处理后的输出为:638××360
处理后的第三个视频的尺寸为853××480,处理后的输出为642×360。
fluent-ffmpeg生成的ffmpeg -i /Users/yagiz/Desktop/video-creator/what's-unfinished.mp4 -y -vcodec libx264 -filter:v scale=w='if(gt(a,1.7777777777777777),640,trunc(360*a/2)*2)':h='if(lt(a,1.7777777777777777),360,trunc(640/a/2)*2)',pad=w=640:h=360:x='if(gt(a,1.7777777777777777),0,(640-iw)/2)':y='if(lt(a,1.7777777777777777),0,(360-ih)/2)':color=black /Users/yagiz/Desktop/video-creator/what's.mp4
cutting video /Users/yagiz/Desktop/video-creator/up?-unfinished.mp4
和
ffmpeg -i /Users/yagiz/Desktop/video-creator/up?-unfinished.mp4 -y -vcodec libx264 -filter:v scale=w='if(gt(a,1.7777777777777777),640,trunc(360*a/2)*2)':h='if(lt(a,1.7777777777777777),360,trunc(640/a/2)*2)',pad=w=640:h=360:x='if(gt(a,1.7777777777777777),0,(640-iw)/2)':y='if(lt(a,1.7777777777777777),0,(360-ih)/2)':color=black /Users/yagiz/Desktop/video-creator/up?.mp4
我认为此命令中的1.77777值会产生实际项目的下限或上限。
知道问题出在哪里吗?
谢谢!
答案 0 :(得分:0)
根据fluent-ffmpeg documentation,当以固定的宽度和高度或百分比调用size()时,以及根本没有调用size()时,将忽略对Aspect()的调用。