/// <summary> /// Converts given input file to output file. /// </summary> /// <param name="inputFilename">Input video file name/path</param> /// <param name="outputFilename">Input video file name/path</param> /// <param name="options">Output options</param> /// <param name="process">FFmpeg process</param> /// <param name="inputArguments">Input arguments (such as -f, -v:c, -video_size, -ac, -ar...)</param> /// <param name="showOutput">Show output to terminal. Error stream will not be redirected if this is set to true.</param> /// <param name="ffmpegExecutable">Name or path to the ffmpeg executable</param> public static void FileToFile(string inputFilename, string outputFilename, EncoderOptions options, out Process process, string inputArguments = "", bool showOutput = false, string ffmpegExecutable = "ffmpeg") { var output = FFmpegWrapper.ExecuteCommand(ffmpegExecutable, $"{inputArguments} -i \"{inputFilename}\" " + $"-c:v {options.EncoderName} {options.EncoderArguments} -f {options.Format} \"{outputFilename}\"", showOutput); process = output; }
public async Task FFmpegWrapperProgressTest() { var path = Res.GetPath(Res.Video_Mp4); var opath = "out-test-v-0.mp4"; double lastval = -1; try { var video = new VideoReader(path); await video.LoadMetadataAsync(); var dur = video.Metadata.Duration; video.Dispose(); Assert.True(Math.Abs(dur - 5.533333) < 0.01); var p = FFmpegWrapper.ExecuteCommand("ffmpeg", $"-i \"{path}\" -c:v libx264 -f mp4 \"{opath}\""); var progress = FFmpegWrapper.RegisterProgressTracker(p, dur); progress.ProgressChanged += (s, prg) => lastval = prg; p.WaitForExit(); await Task.Delay(300); Assert.True(lastval > 50 && lastval <= 100); video = new VideoReader(opath); await video.LoadMetadataAsync(); Assert.True(video.Metadata.AvgFramerate == 30); Assert.True(video.Metadata.AvgFramerateText == "30/1"); Assert.True(Math.Abs(video.Metadata.Duration - 5.533333) < 0.01); Assert.True(video.Metadata.Width == 560); Assert.True(video.Metadata.Height == 320); video.Dispose(); } finally { if (File.Exists(opath)) { File.Delete(opath); } } }
public async Task FFmpegWrapperProgressTest() { var path = Res.GetPath(Res.Audio_Ogg); var opath = "out-test.mp3"; double lastval = -1; try { var audio = new AudioReader(path); await audio.LoadMetadataAsync(); var dur = audio.Metadata.Duration; audio.Dispose(); Assert.True(Math.Abs(dur - 1.515102) < 0.01); var p = FFmpegWrapper.ExecuteCommand("ffmpeg", $"-i \"{path}\" \"{opath}\""); var progress = FFmpegWrapper.RegisterProgressTracker(p, dur); progress.ProgressChanged += (s, prg) => lastval = prg; p.WaitForExit(); await Task.Delay(300); Assert.True(lastval > 50 && lastval <= 100); audio = new AudioReader(opath); await audio.LoadMetadataAsync(); Assert.True(audio.Metadata.Channels == 2); Assert.True(audio.Metadata.Streams.Length == 1); Assert.True(Math.Abs(audio.Metadata.Duration - 1.515102) < 0.2); audio.Dispose(); } finally { if (File.Exists(opath)) { File.Delete(opath); } } }