Reputation: 13
I'm currently converting a mov video to a mp4 video and applying a filter_complex, and it's working:
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.
My first bet is to use the ConvertSettings parameter to add the filter_complex in the CustomOutputArgs. 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?
Thank you!
Upvotes: 1
Views: 5565
Reputation: 9235
The following call is identical to your 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. This can be easily handled by additional ffmpeg output option:
-pix_fmt yuv420p
Upvotes: 3