private async Task Convert() { DialogResult result = dialogSaveOutput.ShowDialog(); string outputPath = ""; if (result == DialogResult.OK) { outputPath = dialogSaveOutput.FileName; } else { return; } txtOutput.Text = ""; prgProgressBar.Value = 0; string audio = dialogOpenAudioFile.FileName; string image = dialogOpenCoverArt.FileName; await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official); // FFMpeg arguments based on this answer // https://superuser.com/a/1041818 IConversion conversion = FFmpeg.Conversions.New(); conversion .SetOutput(outputPath) .SetOverwriteOutput(true) .AddParameter("-loop 1") .AddParameter("-y") .AddParameter($"-i {image}") .AddParameter($"-i {audio}") .AddParameter("-shortest") .AddParameter("-framerate 2") .AddParameter("-acodec copy") .AddParameter("-vcodec mjpeg") .AddParameter("-preset ultrafast"); string ffmpegParams = conversion.Build(); txtOutput.AppendText($"ffmpeg {ffmpegParams}{Environment.NewLine}"); conversion.OnDataReceived += Conversion_OnDataReceived; conversion.OnProgress += Conversion_OnProgress; try { _state = State.Converting; btnCreate.Text = Language.Stop; IConversionResult conversionResult = await conversion.Start(_cts.Token); } catch (OperationCanceledException) { } catch (Exception ex) { _state = State.Ready; btnCreate.Text = Language.Convert; txtOutput.AppendText(Environment.NewLine + Environment.NewLine + ex.Message); } }
public async Task BurnSubtitlesWithParametersTest() { IMediaInfo inputFile = await MediaInfo.Get(Resources.MkvWithAudio); string outputPath = Path.ChangeExtension(Path.GetTempFileName(), FileExtensions.Mp4); IConversion conversion = Conversion.New() .AddStream(inputFile.VideoStreams.First() .AddSubtitles(Resources.SubtitleSrt, "UTF-8", "Fontsize=20,PrimaryColour=&H00ffff&,MarginV=30", new VideoSize(1024, 768))) .SetOutput(outputPath); IConversionResult conversionResult = await conversion.Start(); Assert.True(conversionResult.Success); IMediaInfo mediaInfo = await MediaInfo.Get(outputPath); Assert.Equal(TimeSpan.FromSeconds(9), mediaInfo.Duration); Assert.Equal(TimeSpan.FromSeconds(9), mediaInfo.Duration); Assert.Equal("h264", mediaInfo.VideoStreams.First().Format); Assert.False(mediaInfo.AudioStreams.Any()); Assert.Contains($":charenc=UTF-8:force_style='Fontsize=20,PrimaryColour=&H00ffff&,MarginV=30':original_size=1024x768", conversion.Build()); }
public async Task BurnSubtitlesWithParametersTest() { IMediaInfo inputFile = await FFmpeg.GetMediaInfo(Resources.MkvWithAudio); string outputPath = _storageFixture.GetTempFileName(FileExtensions.Mp4); IConversion conversion = FFmpeg.Conversions.New() .AddStream(inputFile.VideoStreams.First() .AddSubtitles(Resources.SubtitleSrt, VideoSize.Xga, "UTF-8", "Fontsize=20,PrimaryColour=&H00ffff&,MarginV=30")) .SetOutput(outputPath); IConversionResult conversionResult = await conversion.Start(); IMediaInfo mediaInfo = await FFmpeg.GetMediaInfo(outputPath); Assert.Equal(9, mediaInfo.Duration.Seconds); Assert.Equal("h264", mediaInfo.VideoStreams.First().Codec); Assert.False(mediaInfo.AudioStreams.Any()); Assert.Contains($":charenc=UTF-8:force_style='Fontsize=20,PrimaryColour=&H00ffff&,MarginV=30':original_size=1024x768", conversion.Build()); }