[英]node-fluent-ffmpeg doesn't resize videos correctly when given specific size
首先使用此命令剪切視頻:
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
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 值會產生實際項目的下限或上限。
知道問題出在哪里嗎?
謝謝!
根據fluent-ffmpeg 文檔,當以固定寬度和高度或百分比調用 size() 時,以及根本未調用 size() 時,將忽略對 aspect() 的調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.