【问题标题】:node-fluent-ffmpeg doesn't resize videos correctly when given specific size给定特定大小时,node-fluent-ffmpeg 无法正确调整视频大小
【发布时间】:2019-09-04 23:58:11
【问题描述】:

版本信息

  • fluent-ffmpeg 版本:2.1.2
  • ffmpeg 版本:ffmpeg 版本 4.1.3
  • 操作系统:mac os x mojave 10.14.3

代码重现

首先使用此命令剪切视频:

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命令:

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 值会产生实际项目的下限或上限。

知道问题出在哪里吗?

谢谢!

【问题讨论】:

  • 填充后应该有一个setsar=1 过滤器。
  • 你能更正代码@Gyan
  • 不懂 fluent-ffmpeg 语法。
  • 你找到解决办法了吗?
  • 我没有找到。 @OwenM

标签: node.js ffmpeg video-processing fluent-ffmpeg


【解决方案1】:

根据fluent-ffmpeg documentation,当 size() 以固定的宽度和高度或百分比调用时,以及根本没有调用 size() 时,将忽略对 aspect() 的调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 2015-05-18
    • 2015-07-03
    • 1970-01-01
    • 2018-09-26
    • 2021-11-10
    • 1970-01-01
    相关资源
    最近更新 更多