public static void Run() { //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe. ResourceManagement.CommandConfiguration = CommandConfiguration.Create( @"c:\source\ffmpeg\bin\temp", @"c:\source\ffmpeg\bin\ffmpeg.exe", @"c:\source\ffmpeg\bin\ffprobe.exe"); //create a factory var factory = CommandFactory.Create(); //create a command adding a two audio and video files var command = factory.CreateOutputCommand() .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetAudioFile()) .AddInput(Assets.Utilities.GetAudioFile()); //select the first two video streams and run concat filter var videoConcat = command.Select(command.Take(0), command.Take(1)) .Filter(Filterchain.FilterTo <VideoStream>(new Filters.Concat())); //select the first two audio streams and run concat filter var audioConcat = command.Select(command.Take(2), command.Take(3)) .Filter(Filterchain.FilterTo <VideoStream>(new Filters.Concat(1, 0))); command.Select(audioConcat, videoConcat) .MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); //render the output factory.Render(); }
public static void Run() { //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe. ResourceManagement.CommandConfiguration = CommandConfiguration.Create( @"c:\source\ffmpeg\bin\temp", @"c:\source\ffmpeg\bin\ffmpeg.exe", @"c:\source\ffmpeg\bin\ffprobe.exe"); //create a factory var factory = CommandFactory.Create(); //set up the output and input settings var inputSettings = SettingsCollection.ForInput(new SeekPositionInput(1d)); var outputSettings = SettingsCollection.ForOutput( new BitRateVideo(3000), new DurationOutput(10d)); //create a command adding a two audio files var command = factory.CreateOutputCommand(); var output = command.WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings) .To <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", outputSettings) .First(); //use the metadata helper calculation engine to determine a snapshot of what the output duration should be. var metadataInfo = MetadataHelpers.GetMetadataInfo(command, output.GetStreamIdentifier()); System.Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("Metadata snapshot:"); Console.WriteLine(string.Format("Duration: {0}", metadataInfo.VideoStream.VideoMetadata.Duration)); Console.WriteLine(string.Format("Has Video: {0}", metadataInfo.HasVideo)); Console.WriteLine(string.Format("Has Audio: {0}", metadataInfo.HasAudio)); System.Console.ForegroundColor = ConsoleColor.White; }
public void SettingsCollection_MergeRange() { var startAtDefault = new SeekPositionInput(2); var vcodecDefault = new CodecVideo(VideoCodecType.Copy); var settingsCollectionI = SettingsCollection.ForInput(new SeekPositionInput(1)); var settingsCollectionO = SettingsCollection.ForOutput(new CodecVideo(VideoCodecType.Libx264)); var settingsCollectionMergeI = SettingsCollection.ForInput(startAtDefault); var settingsCollectionMergeO = SettingsCollection.ForOutput(vcodecDefault); Assert.Throws <ArgumentException>(() => settingsCollectionI.MergeRange(settingsCollectionMergeO, FFmpegMergeOptionType.OldWins)); Assert.Throws <ArgumentException>(() => settingsCollectionO.MergeRange(settingsCollectionMergeI, FFmpegMergeOptionType.OldWins)); Assert.Throws <ArgumentException>(() => settingsCollectionI.MergeRange(settingsCollectionMergeO, FFmpegMergeOptionType.NewWins)); Assert.Throws <ArgumentException>(() => settingsCollectionO.MergeRange(settingsCollectionMergeI, FFmpegMergeOptionType.NewWins)); settingsCollectionI.MergeRange(settingsCollectionMergeI, FFmpegMergeOptionType.OldWins); settingsCollectionO.MergeRange(settingsCollectionMergeO, FFmpegMergeOptionType.OldWins); var startAtSetting = settingsCollectionI.Items[0] as SeekPositionInput; var vcodecSetting = settingsCollectionO.Items[0] as CodecVideo; Assert.False(startAtSetting != null && startAtSetting.Length == startAtDefault.Length); Assert.False(vcodecSetting != null && vcodecSetting.Codec == vcodecDefault.Codec); settingsCollectionI.MergeRange(settingsCollectionMergeI, FFmpegMergeOptionType.NewWins); settingsCollectionO.MergeRange(settingsCollectionMergeO, FFmpegMergeOptionType.NewWins); startAtSetting = settingsCollectionI.Items[0] as SeekPositionInput; vcodecSetting = settingsCollectionO.Items[0] as CodecVideo; Assert.True(startAtSetting != null && startAtSetting.Length == startAtDefault.Length); Assert.True(vcodecSetting != null && vcodecSetting.Codec == vcodecDefault.Codec); }
public void RenderVideoWEffects() { #if DEBUG ResourceManagement.CommandConfiguration = CommandConfiguration.Create( "c:/source/ffmpeg/bin/temp", "c:/source/ffmpeg/bin/ffmpeg.exe", "c:/source/ffmpeg/bin/ffprobe.exe"); var outputSettings = SettingsCollection.ForOutput( new OverwriteOutput(), new CodecVideo(VideoCodecType.Libx264), new BitRateVideo(3000), new BitRateTolerance(3000), new FrameRate(30)); var factory = CommandFactory.Create(); factory.CreateOutputCommand() .WithInput <VideoStream>(Assets.Utilities.GetVideoFile()) .WithInput <VideoStream>(Assets.Utilities.GetVideoFile()) .Filter(new CrossfadeConcatenate(1)) .MapTo <Mp4>("c:/source/ffmpeg/bin/temp/output-test.mp4", outputSettings); factory.Render(); #endif }
public static void Run() { //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe. ResourceManagement.CommandConfiguration = CommandConfiguration.Create( @"c:\source\ffmpeg\bin\temp", @"c:\source\ffmpeg\bin\ffmpeg.exe", @"c:\source\ffmpeg\bin\ffprobe.exe"); //create a factory var factory = CommandFactory.Create(); //create a command adding a video and audio file var command = factory.CreateOutputCommand() .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetAudioFile()); //select the first two streams from the input command var splitVideo = command.Take(0) .Filter(Filterchain.FilterTo <VideoStream>(new Split(2))); var splitAudio = command.Take(1) .Filter(Filterchain.FilterTo <AudioStream>(new ASplit(2))); //map the first audio and video stream to the output command.Select(splitVideo.Take(0), splitAudio.Take(0)) .MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); command.Select(splitVideo.Take(1), splitAudio.Take(1)) .MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\bar.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); //render the output factory.Render(); }
public void SettingsCollection_AllowMultiple() { var settingsCollectionO = SettingsCollection.ForOutput(); settingsCollectionO.Add(new Map("test1")); settingsCollectionO.Add(new Map("test2")); Assert.True(settingsCollectionO.Count == 2); }
public void SettingsCollection_RemoveAll() { var settingsCollectionI = SettingsCollection.ForInput(new SeekPositionInput(1), new DurationInput(2)); var settingsCollectionO = SettingsCollection.ForOutput(new RemoveAudio(), new OverwriteOutput()); Assert.True(settingsCollectionI.Count == 2); Assert.True(settingsCollectionO.Count == 2); settingsCollectionI.RemoveAll(s => true); settingsCollectionO.RemoveAll(s => true); Assert.True(settingsCollectionI.Count == 0); Assert.True(settingsCollectionO.Count == 0); }
public void SettingsCollection_RemoveAt() { var settingsCollectionI = SettingsCollection.ForInput(new StartAt(1), new DurationInput(2)); var settingsCollectionO = SettingsCollection.ForOutput(new RemoveAudio(), new OverwriteOutput()); Assert.True(settingsCollectionI.Count == 2); Assert.True(settingsCollectionO.Count == 2); settingsCollectionI.RemoveAt(0); settingsCollectionO.RemoveAt(0); Assert.True(settingsCollectionI.Count == 1); Assert.True(settingsCollectionO.Count == 1); }
public void SettingsCollection_Add() { var settingsCollectionI = SettingsCollection.ForInput(); var settingsCollectionO = SettingsCollection.ForOutput(); Assert.Throws <ArgumentException>(() => settingsCollectionI.Add(new OverwriteOutput())); Assert.Throws <ArgumentException>(() => settingsCollectionO.Add(new SeekPositionInput(1))); settingsCollectionI.Add(new SeekPositionInput(1)); settingsCollectionO.Add(new OverwriteOutput()); Assert.True(settingsCollectionI.Count == 1); Assert.True(settingsCollectionO.Count == 1); }
public void InputSettingsToOutputSettingsOverDuration_Verify() { var inputSettings = SettingsCollection.ForInput(new StartAt(1d)); var outputSettings = SettingsCollection.ForOutput( new BitRateVideo(3000), new DurationOutput(10d)); var output = CommandFactory.Create() .CreateOutputCommand() .WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings) .To <Mp4>(outputSettings) .First(); var metadataInfo = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier()); Assert.True(metadataInfo.VideoStream.VideoMetadata.Duration == TimeSpan.FromSeconds(9)); // we have a 10 second video, and start 1 second in, this should only be 9 Assert.True(metadataInfo.VideoStream.VideoMetadata.BitRate == 3000000L); }
public void InputSettingsToOutputSettings_Verify() { var inputSettings = SettingsCollection.ForInput(new SeekPositionInput(1d)); var outputSettings = SettingsCollection.ForOutput( new BitRateVideo(3000), new DurationOutput(5d)); var output = CommandFactory.Create() .CreateOutputCommand() .WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings) .To <Mp4>(outputSettings) .First(); var metadataInfo = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier()); Assert.True(metadataInfo.VideoStream.VideoMetadata.Duration == TimeSpan.FromSeconds(5)); Assert.True(metadataInfo.VideoStream.VideoMetadata.BitRate == 3000000L); }
public static void Run() { //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe. ResourceManagement.CommandConfiguration = CommandConfiguration.Create( @"c:\source\ffmpeg\bin\temp", @"c:\source\ffmpeg\bin\ffmpeg.exe", @"c:\source\ffmpeg\bin\ffprobe.exe"); //create a factory var factory = CommandFactory.Create(); //create a command adding a video file var command = factory.CreateOutputCommand() .AddInput(Assets.Utilities.GetVideoFile(), SettingsCollection.ForInput(new SeekTo(2))) .To <Jpg>(@"c:\source\ffmpeg\bin\temp\foo.jpg", SettingsCollection.ForOutput(new VideoFrames(1), new OverwriteOutput())); //render the output factory.Render(); }
public static void Run() { //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe. ResourceManagement.CommandConfiguration = CommandConfiguration.Create( @"c:\source\ffmpeg\bin\temp", @"c:\source\ffmpeg\bin\ffmpeg.exe", @"c:\source\ffmpeg\bin\ffprobe.exe"); //create a factory var factory = CommandFactory.Create(); //create a command adding a video file var command = factory.CreateOutputCommand() .AddInput(Assets.Utilities.GetVideoFile()) .OnSuccess(OnSuccessAction) .OnError(OnErrorAction) .To <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); factory.Render(); }
public static void Run() { //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe. ResourceManagement.CommandConfiguration = CommandConfiguration.Create( @"c:\source\ffmpeg\bin\temp", @"c:\source\ffmpeg\bin\ffmpeg.exe", @"c:\source\ffmpeg\bin\ffprobe.exe"); //create a factory var factory = CommandFactory.Create(); //create a command adding a two audio files factory.CreateOutputCommand() .WithInput <AudioStream>(Assets.Utilities.GetAudioFile()) .WithInput <AudioStream>(Assets.Utilities.GetAudioFile()) .Filter(Filterchain.FilterTo <AudioStream>(new Filters.Concat(1, 0))) .MapTo <M4A>(@"c:\source\ffmpeg\bin\temp\foo.m4a", SettingsCollection.ForOutput(new OverwriteOutput())); //render the output factory.Render(); }
public void InputSettingsToFilterToOutputSettings_Verify() { var baseline = Resource.From(Utilities.GetVideoFile()) .LoadMetadata() .Streams .OfType <VideoStream>() .First(); var calculatedSeconds = ((baseline.Info.VideoMetadata.Duration.TotalSeconds - 1) * 3d) - 2d; var calculatedDuration = TimeSpan.FromSeconds(calculatedSeconds); var inputSettings = SettingsCollection.ForInput(new StartAt(1d)); var outputSettings = SettingsCollection.ForOutput( new BitRateVideo(3000), new DurationOutput(5d)); var filterchain = Filterchain.FilterTo <VideoStream>(new Split(3)); var split = CommandFactory.Create() .CreateOutputCommand() .WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings) .Filter(filterchain); var concat1 = split.Command .Select(split.StreamIdentifiers[0]) .Select(split.StreamIdentifiers[1]) .Filter(new Dissolve(1d)); var concat2 = concat1.Select(split.StreamIdentifiers[2]) .Filter(new Dissolve(1d)); var output = concat2.MapTo <Mp4>(outputSettings).First(); var metadataInfo1 = MetadataHelpers.GetMetadataInfo(concat2.Command, concat2.StreamIdentifiers.FirstOrDefault()); var metadataInfo2 = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier()); Assert.True(metadataInfo1.VideoStream.VideoMetadata.Duration == calculatedDuration); Assert.True(metadataInfo2.VideoStream.VideoMetadata.Duration == TimeSpan.FromSeconds(5)); Assert.True(metadataInfo2.VideoStream.VideoMetadata.BitRate == 3000000L); }
public void SettingsCollection_AddRange() { var settingsCollectionI = SettingsCollection.ForInput(); var settingsCollectionO = SettingsCollection.ForOutput(); var settingsCollectionAddI = SettingsCollection.ForInput(new SeekPositionInput(1), new DurationInput(1)); var settingsCollectionAddO = SettingsCollection.ForOutput(new OverwriteOutput(), new RemoveAudio()); Assert.Throws <ArgumentNullException>(() => settingsCollectionI.AddRange(null)); Assert.Throws <ArgumentNullException>(() => settingsCollectionO.AddRange(null)); settingsCollectionI.AddRange(settingsCollectionAddI); settingsCollectionO.AddRange(settingsCollectionAddO); Assert.Throws <ArgumentException>(() => settingsCollectionI.AddRange(settingsCollectionAddO)); Assert.Throws <ArgumentException>(() => settingsCollectionO.AddRange(settingsCollectionAddI)); Assert.Throws <ArgumentException>(() => settingsCollectionI.AddRange(settingsCollectionAddI)); Assert.Throws <ArgumentException>(() => settingsCollectionO.AddRange(settingsCollectionAddO)); Assert.True(settingsCollectionI.Count == 2); Assert.True(settingsCollectionO.Count == 2); }
private static void RemuxToMpeg4Container(JobConfiguration jobConfiguration) { CommandFactory factory = CommandFactory.Create(); FFmpegCommand command = factory.CreateOutputCommand(); CommandStage chain = command.WithInput <VideoStream>(jobConfiguration.InputFile); SettingsCollection outputSettings = SettingsCollection.ForOutput(new CodecVideo(VideoCodecType.Copy), new CodecAudio(AudioCodecType.Copy)); chain.To <Mp4>(jobConfiguration.OutputFile, outputSettings); Console.WriteLine($"Remuxing {jobConfiguration.InputFile}"); try { factory.Render(); // Console.WriteLine($"Remuxed {jobConfiguration.OutputFile}"); if (jobConfiguration.RemoveInputFileAfterRemux && File.Exists(jobConfiguration.OutputFile)) { File.Delete(jobConfiguration.InputFile); } } catch (FFmpegRenderingException e) { Console.WriteLine($"Remuxing failed for file {jobConfiguration.InputFile}: {e.Message}"); } }
public static void Run() { //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe. ResourceManagement.CommandConfiguration = CommandConfiguration.Create( @"c:\source\ffmpeg\bin\temp", @"c:\source\ffmpeg\bin\ffmpeg.exe", @"c:\source\ffmpeg\bin\ffprobe.exe"); //create a factory var factory = CommandFactory.Create(); //OPTION 1: // - this option uses the add input method, which adds the input to the command // but does not add any streams to a stage object. var option1 = factory.CreateOutputCommand() .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetAudioFile()); //select the first two streams from the input command var stage = option1.Select(option1.Take(0), option1.Take(1)); //map that directly to an output stream stage.MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); //OPTION 2: // - this option uses the with input method which adds the input to the command // and also adds the streams from the input file to a staging object var option2 = factory.CreateOutputCommand() .WithInput <VideoStream>(Assets.Utilities.GetVideoFile()) .WithInput <AudioStream>(Assets.Utilities.GetAudioFile()) .MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\bar.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); factory.Render(); }
public static CommandOutput Create(IContainer outputToUse) { return(Create(outputToUse, SettingsCollection.ForOutput())); }
public void SettingsCollection_ForAny() { SettingsCollection.ForOutput(new SampleRate(44100)); SettingsCollection.ForInput(new SampleRate(44100)); }
public void SettingsCollection_ForOutput_Invalid() { Assert.Throws <ArgumentException>(() => SettingsCollection.ForOutput(new SeekPositionInput(1))); }
public void SettingsCollection_ForOutput_Valid() { var settingsCollection = SettingsCollection.ForOutput(new OverwriteOutput()); Assert.True(settingsCollection.Count == 1); }
public void SettingsCollection_ForAny() { Assert.DoesNotThrow(() => SettingsCollection.ForOutput(new SampleRate(44100))); Assert.DoesNotThrow(() => SettingsCollection.ForInput(new SampleRate(44100))); }
public static List <CommandOutput> To <TOutputType>(this CommandStage stage) where TOutputType : class, IContainer, new() { return(stage.To <TOutputType>(SettingsCollection.ForOutput())); }
public static List <CommandOutput> To <TOutputType>(this FFmpegCommand command) where TOutputType : class, IContainer, new() { return(command.To <TOutputType>(SettingsCollection.ForOutput())); }
private async void MakeButton_OnClick(object sender, RoutedEventArgs e) { var source = FFmePlayer.Source; var fileName = Path.GetFileName(source.AbsoluteUri); var tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp"); var targetFile = source.AbsolutePath; if (!source.IsFile) { try { using (WebClient webClient = new WebClient()) { targetFile = Path.Combine(tempPath, fileName + ".mp4"); webClient.DownloadFile(source.AbsoluteUri, targetFile); } } catch (Exception ex) { await this.ShowMessageAsync("tips", "can not download from url:" + source.AbsoluteUri); return; } } FileInfo fileInfo = new FileInfo(targetFile); if (fileInfo.Length > 10 * 1024 * 1024) { await this.ShowMessageAsync("too large", "the video file is large more than 10mb."); } var gifFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, OutputPath, Path.GetFileNameWithoutExtension(fileName) + ".gif"); var index = SizeComboBox.SelectedIndex; var size = _sizeDict[index]; double frameRate; if (!double.TryParse(FrameRateTextBox.Text, out frameRate)) { frameRate = 10; } var outputSettings = SettingsCollection.ForOutput( new CustomFilter(string.Format("\"scale={0}:{1}\"", size.Item1, size.Item2)) , new FrameRate(frameRate) , new OverwriteOutput()); try { var factory = CommandFactory.Create(); factory.CreateOutputCommand() .WithInput <VideoStream>(targetFile) .MapTo <Gif>(gifFileName, outputSettings); factory.Render(); Clipboard.SetText(gifFileName); await this.ShowMessageAsync("tips", "make success. gif path was copyed to clipboard"); } catch (Exception ex) { throw; } }