简体   繁体   English

如何在filter_complex中使用NReco ffmpeg ConvertMedia

[英]How to use NReco ffmpeg ConvertMedia with filter_complex

I'm currently converting a mov video to a mp4 video and applying a filter_complex, and it's working: 我正在将mov视频转换为mp4视频并应用filter_complex,它正在工作:

    var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
    ffMpeg.Invoke("-y -i \"" + input/ + "\" -filter_complex \"[0] yadif=0:-1:0,scale=iw*sar:ih,scale='if(gt(a,16/9),1280,-2)':'if(gt(a,16/9),-2,720)'[scaled];[scaled] pad=1280:720:(ow-iw)/2:(oh-ih)/2:black \" -c:v libx264 -c:a mp3 -ab 128k " + output + ".mp4");

However, I would like to do the same thing, but using the ConvertMedia method of the class FFMpegConverter, in order to use the ConvertProgressEventArgs available, as stated here . 然而,我愿做同样的事情,但使用类FFMpegConverter的ConvertMedia方法, 以利用现有的ConvertProgressEventArgs,如前所述这里

My first bet is to use the ConvertSettings parameter to add the filter_complex in the CustomOutputArgs. 我的第一个赌注是使用ConvertSettings参数在CustomOutputArgs中添加filter_complex。 I'm trying the following, but it's not converting properly the video (it can't be played). 我正在尝试以下方法,但它没有正确转换视频(无法播放)。

    ffMpeg.ConvertMedia(this.Video /*+ ".mov"*/, NReco.VideoConverter.Format.mov , outPutVideo1 + ".mp4", NReco.VideoConverter.Format.mp4, new NReco.VideoConverter.ConvertSettings()
                        {
                            CustomOutputArgs = " -filter_complex \"[0] yadif=0:-1:0,scale=iw*sar:ih,scale='if(gt(a,16/9),1280,-2)':'if(gt(a,16/9),-2,720)'[scaled];[scaled] pad=1280:720:(ow-iw)/2:(oh-ih)/2:black \" -c:v libx264 -c:a mp3 -ab 128k " + outPutVideo1 + ".mp4"
                        });

Do you have any ideas on how to achieve this? 您对如何实现这一点有任何想法吗? Or do you know if it's possible to use the ConvertProgress when using the Invoke method? 或者你知道在使用Invoke方法时是否可以使用ConvertProgress?

Thank you! 谢谢!

The following call is identical to your ffmpeg.Invoke: 以下调用您的ffmpeg.Invoke 相同

ffMpeg.ConvertMedia(this.Video /*+ ".mov"*/, 
    null, // autodetect by input file extension 
    outPutVideo1 + ".mp4", 
    null, // autodetect by output file extension 
    new NReco.VideoConverter.ConvertSettings() {
        CustomOutputArgs = " -filter_complex \"[0] yadif=0:-1:0,scale=iw*sar:ih,scale='if(gt(a,16/9),1280,-2)':'if(gt(a,16/9),-2,720)'[scaled];[scaled] pad=1280:720:(ow-iw)/2:(oh-ih)/2:black \" -c:v libx264 -c:a mp3 -ab 128k "
    }
);

Resulting mp4 file may be not playable by some codecs (say, Windows Media Player) if input video has pixel format that differs from yuv420p. 如果输入视频的像素格式与yuv420p不同,则某些编解码器(例如,Windows Media Player)可能无法播放生成的mp4文件。 This can be easily handled by additional ffmpeg output option: 这可以通过额外的ffmpeg输出选项轻松处理:

-pix_fmt yuv420p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM