/// <summary> /// split video by time lines in Dir /// </summary> /// <param name="timeLines">time lines</param> public void Split(TimeLineVolume[] timeLines) { char sep = Path.DirectorySeparatorChar; FFMpeg ffmpeg = new FFMpeg(); for (int i = 0; i < timeLines.Length; i++) { ArgumentContainer container = new ArgumentContainer(); // input arg container.Add(new InputArgument(Source)); // split arg container.Add(new SplitArgument(timeLines[i])); // output path VideoPartInfo partInfo = new VideoPartInfo() { IsNoise = timeLines[i].Volume == VolumeValue.Noise ? true: false, Name = "videoPart", FileExtension = SourceExtension, Number = i, }; string outputPath = $"{Dir.FullName}{sep}{partInfo.FullName}"; container.Add(new OutputArgument(outputPath)); // convert ffmpeg.Convert(container); } }
public void Video_Duration() { var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo); var output = Input.OutputLocation(VideoType.Mp4); var arguments = new ArgumentContainer(); arguments.Add(new InputArgument(VideoLibrary.LocalVideo)); arguments.Add(new DurationArgument(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 5))); arguments.Add(new OutputArgument(output)); try { Encoder.Convert(arguments); Assert.IsTrue(File.Exists(output.FullName)); var outputVideo = new VideoInfo(output.FullName); Assert.AreEqual(video.Duration.Days, outputVideo.Duration.Days); Assert.AreEqual(video.Duration.Hours, outputVideo.Duration.Hours); Assert.AreEqual(video.Duration.Minutes, outputVideo.Duration.Minutes); Assert.AreEqual(video.Duration.Seconds - 5, outputVideo.Duration.Seconds); } finally { if (File.Exists(output.FullName)) { output.Delete(); } } }
public void Video_ToMP4_Resize_Args() { var container = new ArgumentContainer(); container.Add(new ScaleArgument(VideoSize.Ld)); container.Add(new VideoCodecArgument(VideoCodec.LibX264)); Convert(VideoType.Mp4, container); }
public void Video_ToOGV_Resize_Args() { var container = new ArgumentContainer(); container.Add(new ScaleArgument(VideoSize.Ed)); container.Add(new VideoCodecArgument(VideoCodec.LibTheora)); Convert(VideoType.Ogv, container); }
public void Video_ToTS_Args() { var container = new ArgumentContainer(); container.Add(new CopyArgument()); container.Add(new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB)); container.Add(new ForceFormatArgument(VideoCodec.MpegTs)); Convert(VideoType.Ts, container); }
public void Convert(VideoType type, ArgumentContainer container) { var output = Input.OutputLocation(type); try { var input = VideoInfo.FromFileInfo(Input); var arguments = new ArgumentContainer { new InputArgument(input) }; foreach (var arg in container) { arguments.Add(arg.Value); } arguments.Add(new OutputArgument(output)); var scaling = container.Find <ScaleArgument>(); Encoder.Convert(arguments); var outputVideo = new VideoInfo(output.FullName); Assert.IsTrue(File.Exists(output.FullName)); Assert.AreEqual(outputVideo.Duration, input.Duration); if (scaling == null) { Assert.AreEqual(outputVideo.Width, input.Width); Assert.AreEqual(outputVideo.Height, input.Height); } else { if (scaling.Value.Width != -1) { Assert.AreEqual(outputVideo.Width, scaling.Value.Width); } if (scaling.Value.Height != -1) { Assert.AreEqual(outputVideo.Height, scaling.Value.Height); } Assert.AreNotEqual(outputVideo.Width, input.Width); Assert.AreNotEqual(outputVideo.Height, input.Height); } } finally { if (File.Exists(output.FullName)) { File.Delete(output.FullName); } } }
public void Builder_BuildString_Concat() { var container = new ArgumentContainer(); container.Add(new ConcatArgument(concatFiles)); container.Add(new OutputArgument("output.mp4")); var str = builder.BuildArguments(container); Assert.AreEqual(str, "-i \"concat:1.mp4|2.mp4|3.mp4|4.mp4\" \"output.mp4\""); }
private string GetArgumentsString(params Argument[] args) { var container = new ArgumentContainer(); container.Add(new InputArgument("input.mp4")); foreach (var a in args) { container.Add(a); } container.Add(new OutputArgument("output.mp4")); return(builder.BuildArguments(container)); }
private void ButAppend_Click(object sender, EventArgs e) { if (IsFormComplete) { ArgumentContainer.Add(new CustomAttributeNamedArgument(ItemName.Text, AttributeArgumentEditor.SelectedArgument)); DialogResult = DialogResult.OK; } else { DialogResult = DialogResult.None; } }
private static ArgumentContainer <string, object> GetFxForwardPCE(ArgumentContainer <string, object> argumentList) { ArgumentContainer <string, object> result = new ArgumentContainer <string, object>(); try { var settleDate = ArrayOrItemToList <DateTime>((Array)argumentList["SettleDate"]); var recAmount = ArrayOrItemToList <decimal>((Array)argumentList["RecAmount"]); var recCurrency = ArrayOrItemToList <string>((Array)argumentList["RecCurrency"]); var payAmount = ArrayOrItemToList <decimal>((Array)argumentList["PayAmount"]); var payCurrency = ArrayOrItemToList <string>((Array)argumentList["PayCurrency"]); DateTime evaluationDate = (DateTime)argumentList["EvaluationDate"]; String pceCalculationCurrency = (string)argumentList["PCECalculationCurrency"]; Result brResult = GetFxForwardPCE(settleDate.ToArray(), recAmount.ToArray(), recCurrency.ToArray(), payAmount.ToArray(), payCurrency.ToArray(), evaluationDate, pceCalculationCurrency); List <int> resultTimeBuckets = new List <int>(); List <double> resultPCE = new List <double>(); foreach (ExposureBucket eb in brResult.Buckets) { resultTimeBuckets.Add(eb.Term); resultPCE.Add(eb.PE); } result.Add("TimeBuckets", resultTimeBuckets.ToArray()); result.Add("PCE", resultPCE.ToArray()); } catch (Exception e) { result.Add("exception.Message", e.Message); result.Add("exception.StackTrace", e.StackTrace); } return(result); }
/// <summary> /// Convert a video do a different format. /// </summary> /// <param name="source">Input video source.</param> /// <param name="output">Output information.</param> /// <param name="type">Target conversion video type.</param> /// <param name="speed">Conversion target speed/quality (faster speed = lower quality).</param> /// <param name="size">Video size.</param> /// <param name="audioQuality">Conversion target audio quality.</param> /// <param name="multithreaded">Is encoding multithreaded.</param> /// <returns>Output video information.</returns> public VideoInfo Convert( VideoInfo source, FileInfo output, VideoType type = VideoType.Mp4, Speed speed = Speed.SuperFast, VideoSize size = VideoSize.Original, AudioQuality audioQuality = AudioQuality.Normal, bool multithreaded = false) { FFMpegHelper.ConversionExceptionCheck(source.ToFileInfo(), output); FFMpegHelper.ExtensionExceptionCheck(output, FileExtension.ForType(type)); FFMpegHelper.ConversionSizeExceptionCheck(source); _totalTime = source.Duration; var scale = VideoSize.Original == size ? 1 : (double)source.Height / (int)size; var outputSize = new Size( (int)(source.Width / scale), (int)(source.Height / scale) ); if (outputSize.Width % 2 != 0) { outputSize.Width += 1; } var container = new ArgumentContainer(); switch (type) { case VideoType.Mp4: container.Add( new InputArgument(source), new ThreadsArgument(multithreaded), new ScaleArgument(outputSize), new VideoCodecArgument(VideoCodec.LibX264, 2400), new SpeedArgument(speed), new AudioCodecArgument(AudioCodec.Aac, audioQuality), new OutputArgument(output) ); break; case VideoType.Ogv: container.Add( new InputArgument(source), new ThreadsArgument(multithreaded), new ScaleArgument(outputSize), new VideoCodecArgument(VideoCodec.LibTheora, 2400), new SpeedArgument(speed), new AudioCodecArgument(AudioCodec.LibVorbis, audioQuality), new OutputArgument(output) ); break; case VideoType.Ts: container.Add( new InputArgument(source), new CopyArgument(), new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB), new ForceFormatArgument(VideoCodec.MpegTs), new OutputArgument(output) ); break; } if (!RunProcess(container, output)) { throw new FFMpegException(FFMpegExceptionType.Conversion, $"The video could not be converted to {Enum.GetName(typeof(VideoType), type)}"); } _totalTime = TimeSpan.MinValue; return(new VideoInfo(output)); }
private void btnPre_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(txtVideoUrl.Text)) { MessageBox.Show("You Must Set a Video!", "Warning", MessageBoxButton.OK, MessageBoxImage.Error); return; } container.Clear(); var ran = new Random(); a = DateTime.Now.ToString("MM-dd-hh-mm"); File.WriteAllText(Path.GetTempPath() + "Script" + a + ".avs", Builder.Build(false)); SaveFileDialog s = new SaveFileDialog { Filter = "Video Files(*.mp4/*.mkv)|*.mp4;*.mkv", DefaultExt = '.' + cbFormat.Text.ToLower() }; if (s.ShowDialog() == false) { MessageBox.Show("You must choose a path.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // encoder.ExtractAudio(new VideoInfo(new FileInfo(Builder.GetMainVideo())),new FileInfo(Path.GetTempPath() + "Sound" + a + ".mp3")) container.Add(new InputArgument(new string[] { Builder.GetMainVideo(), Path.GetTempPath() + "Script" + a + ".avs" })); container.Add(new ThreadsArgument(true)); container.Add(new LogArgument(Path.GetTempPath() + @"log" + a + ".txt")); string u = cbEncoder.Text.ToLower(); switch (u) { case "libx264": { container.Add(new VideoCodecArgument(VideoCodec.LibX264)); break; } case "libx265": { container.Add(new BestCodecArgument(true)); break; } case "vp9": { container.Add(new BestCodecArgument(false)); break; } } u = cbSpeed.Text.Replace(" ", ""); SpeedArgument sa = new SpeedArgument(Speed.Medium); switch (u) { case "VerySlow": { sa = new SpeedArgument(Speed.VerySlow); break; } case "Slower": { sa = new SpeedArgument(Speed.Slower); break; } case "Slow": { sa = new SpeedArgument(Speed.Slow); break; } case "Medium": { sa = new SpeedArgument(Speed.Medium); break; } case "Fast": { sa = new SpeedArgument(Speed.Fast); break; } case "Faster": { sa = new SpeedArgument(Speed.Faster); break; } case "VeryFast": { sa = new SpeedArgument(Speed.VeryFast); break; } case "SuperFast": { sa = new SpeedArgument(Speed.SuperFast); break; } case "UltraFast": { sa = new SpeedArgument(Speed.UltraFast); break; } } container.Add(sa); AudioCodecArgument ac = new AudioCodecArgument(AudioCodec.Aac); switch (cbAudioCodec.Text.Replace(" ", "").ToLower()) { case "aac": { ac = new AudioCodecArgument(AudioCodec.Aac); break; } default: { ac = new AudioCodecArgument(AudioCodec.LibVorbis); break; } } container.Add(ac); container.Add(new MapArgument(new string[] { "1:v:0", "0:a:0" })); // if (!string.IsNullOrEmpty(NumberTextBox.Text)) // { // container.Add(new QualityArgument(double.Parse(NumberTextBox.Text))); // } container.Add(new OutputArgument(s.FileName.Trim())); container.Add(new OverrideArgument()); V = s.FileName; Task t = Task.Run(() => { try { encoder.Convert(container); } catch (FFMpegCore.FFMPEG.Exceptions.FFMpegException er) { MessageBox.Show(er.Message + "\n" + er.Source + "\n" + er.Type, er.InnerException?.Message, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } }); tt.Interval = TimeSpan.FromMilliseconds(400); tt.Tick += Tt_Tick; tt.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error); } }