public void Video_Join_Image_Sequence() { var imageSet = new List <ImageInfo>(); Directory.EnumerateFiles(TestResources.ImageCollection) .Where(file => file.ToLower().EndsWith(".png")) .ToList() .ForEach(file => { for (var i = 0; i < 15; i++) { imageSet.Add(new ImageInfo(file)); } }); var outputFile = new TemporaryFile("out.mp4"); var success = FFMpeg.JoinImageSequence(outputFile, images: imageSet.ToArray()); Assert.IsTrue(success); var result = FFProbe.Analyse(outputFile); Assert.AreEqual(3, result.Duration.Seconds); Assert.AreEqual(imageSet.First().Width, result.PrimaryVideoStream.Width); Assert.AreEqual(imageSet.First().Height, result.PrimaryVideoStream.Height); }
public void Video_Duration() { var video = FFProbe.Analyse(VideoLibrary.LocalVideo.FullName); var output = Input.OutputLocation(VideoType.Mp4); try { FFMpegArguments .FromFileInput(VideoLibrary.LocalVideo) .OutputToFile(output, false, opt => opt.WithDuration(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 2))) .ProcessSynchronously(); Assert.IsTrue(File.Exists(output)); var outputVideo = FFProbe.Analyse(output); 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 - 2, outputVideo.Duration.Seconds); } finally { if (File.Exists(output)) { File.Delete(output); } } }
public void Probe_Success_FromStream() { using var stream = File.OpenRead(VideoLibrary.LocalVideoWebm.FullName); var info = FFProbe.Analyse(stream); Assert.AreEqual(3, info.Duration.Seconds); }
public void Probe_Success() { var info = FFProbe.Analyse(VideoLibrary.LocalVideo.FullName); Assert.AreEqual(13, info.Duration.Seconds); Assert.AreEqual(".mp4", info.Extension); Assert.AreEqual(VideoLibrary.LocalVideo.FullName, info.Path); Assert.AreEqual("5.1", info.PrimaryAudioStream.ChannelLayout); Assert.AreEqual(6, info.PrimaryAudioStream.Channels); Assert.AreEqual("AAC (Advanced Audio Coding)", info.PrimaryAudioStream.CodecLongName); Assert.AreEqual("aac", info.PrimaryAudioStream.CodecName); Assert.AreEqual("LC", info.PrimaryAudioStream.Profile); Assert.AreEqual(381988, info.PrimaryAudioStream.BitRate); Assert.AreEqual(48000, info.PrimaryAudioStream.SampleRateHz); Assert.AreEqual(862991, info.PrimaryVideoStream.BitRate); Assert.AreEqual(16, info.PrimaryVideoStream.DisplayAspectRatio.Width); Assert.AreEqual(9, info.PrimaryVideoStream.DisplayAspectRatio.Height); Assert.AreEqual("yuv420p", info.PrimaryVideoStream.PixelFormat); Assert.AreEqual(1280, info.PrimaryVideoStream.Width); Assert.AreEqual(720, info.PrimaryVideoStream.Height); Assert.AreEqual(25, info.PrimaryVideoStream.AvgFrameRate); Assert.AreEqual(25, info.PrimaryVideoStream.FrameRate); Assert.AreEqual("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", info.PrimaryVideoStream.CodecLongName); Assert.AreEqual("h264", info.PrimaryVideoStream.CodecName); Assert.AreEqual(8, info.PrimaryVideoStream.BitsPerRawSample); Assert.AreEqual("Main", info.PrimaryVideoStream.Profile); }
public void Probe_Success() { var info = FFProbe.Analyse(TestResources.Mp4Video); Assert.AreEqual(3, info.Duration.Seconds); Assert.AreEqual("5.1", info.PrimaryAudioStream !.ChannelLayout); Assert.AreEqual(6, info.PrimaryAudioStream.Channels); Assert.AreEqual("AAC (Advanced Audio Coding)", info.PrimaryAudioStream.CodecLongName); Assert.AreEqual("aac", info.PrimaryAudioStream.CodecName); Assert.AreEqual("LC", info.PrimaryAudioStream.Profile); Assert.AreEqual(377351, info.PrimaryAudioStream.BitRate); Assert.AreEqual(48000, info.PrimaryAudioStream.SampleRateHz); Assert.AreEqual(1471810, info.PrimaryVideoStream !.BitRate); Assert.AreEqual(16, info.PrimaryVideoStream.DisplayAspectRatio.Width); Assert.AreEqual(9, info.PrimaryVideoStream.DisplayAspectRatio.Height); Assert.AreEqual("yuv420p", info.PrimaryVideoStream.PixelFormat); Assert.AreEqual(1280, info.PrimaryVideoStream.Width); Assert.AreEqual(720, info.PrimaryVideoStream.Height); Assert.AreEqual(25, info.PrimaryVideoStream.AvgFrameRate); Assert.AreEqual(25, info.PrimaryVideoStream.FrameRate); Assert.AreEqual("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", info.PrimaryVideoStream.CodecLongName); Assert.AreEqual("h264", info.PrimaryVideoStream.CodecName); Assert.AreEqual(8, info.PrimaryVideoStream.BitsPerRawSample); Assert.AreEqual("Main", info.PrimaryVideoStream.Profile); }
public void Probe_Success_FromStream() { using var stream = File.OpenRead(TestResources.WebmVideo); var info = FFProbe.Analyse(stream); Assert.AreEqual(3, info.Duration.Seconds); }
public void Video_With_Only_Audio_Should_Extract_Metadata() { var video = FFProbe.Analyse(TestResources.Mp4WithoutVideo); Assert.AreEqual(null, video.PrimaryVideoStream); Assert.AreEqual("aac", video.PrimaryAudioStream.CodecName); Assert.AreEqual(10, video.Duration.TotalSeconds, 0.5); }
private void ConvertFromStreamPipe(ContainerFormat type, params IArgument[] arguments) { var output = Input.OutputLocation(type); try { var input = FFProbe.Analyse(VideoLibrary.LocalVideoWebm.FullName); using var inputStream = File.OpenRead(input.Path); var processor = FFMpegArguments .FromPipeInput(new StreamPipeSource(inputStream)) .OutputToFile(output, false, opt => { foreach (var arg in arguments) { opt.WithArgument(arg); } }); var scaling = arguments.OfType <ScaleArgument>().FirstOrDefault(); var success = processor.ProcessSynchronously(); var outputVideo = FFProbe.Analyse(output); Assert.IsTrue(success); Assert.IsTrue(File.Exists(output)); Assert.IsTrue(Math.Abs((outputVideo.Duration - input.Duration).TotalMilliseconds) < 1000.0 / input.PrimaryVideoStream.FrameRate); if (scaling?.Size == null) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } else { if (scaling.Size.Value.Width != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, scaling.Size.Value.Width); } if (scaling.Size.Value.Height != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, scaling.Size.Value.Height); } Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } } finally { if (File.Exists(output)) { File.Delete(output); } } }
public void Video_With_Only_Audio_Should_Extract_Metadata() { var video = FFProbe.Analyse(VideoLibrary.LocalVideoAudioOnly.FullName); Assert.AreEqual(null, video.PrimaryVideoStream); Assert.AreEqual("aac", video.PrimaryAudioStream.CodecName); Assert.AreEqual(10, video.Duration.TotalSeconds, 0.5); // Assert.AreEqual(1.25, video.Size); }
public void Image_AddAudio() { using var outputFile = new TemporaryFile("out.mp4"); FFMpeg.PosterWithAudio(TestResources.PngImage, TestResources.Mp3Audio, outputFile); var analysis = FFProbe.Analyse(TestResources.Mp3Audio); Assert.IsTrue(analysis.Duration.TotalSeconds > 0); Assert.IsTrue(File.Exists(outputFile)); }
public void Audio_Save() { using var outputFile = new TemporaryFile("out.mp3"); FFMpeg.ExtractAudio(TestResources.Mp4Video, outputFile); var analysis = FFProbe.Analyse(outputFile); Assert.IsTrue(!analysis.VideoStreams.Any()); Assert.IsTrue(analysis.AudioStreams.Any()); }
public void Video_Snapshot_InMemory() { var input = FFProbe.Analyse(TestResources.Mp4Video); using var bitmap = FFMpeg.Snapshot(input); Assert.AreEqual(input.PrimaryVideoStream.Width, bitmap.Width); Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height); Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png); }
public async Task <MediaFile> AnalyzeFile(string content_type, FileInfo fileInfo) { var ffprobe = FFProbe.Analyse(fileInfo.FullName); var mapper = new MapperConfiguration(cfg => { cfg.CreateMap <FFMpegCore.AudioStream, Models.AudioStream>(); cfg.CreateMap <FFMpegCore.VideoStream, Models.VideoStream>(); cfg.CreateMap <FFMpegCore.MediaFormat, Models.MediaFormat>(); }).CreateMapper(); MP.Core.Models.Analysis analysis = new MP.Core.Models.Analysis(); analysis.AudioStreams = mapper.Map <List <Models.AudioStream> >(ffprobe.AudioStreams); analysis.VideoStreams = mapper.Map <List <Models.VideoStream> >(ffprobe.VideoStreams); analysis.Format = mapper.Map <Models.MediaFormat>(ffprobe.Format); MP.Core.Models.MediaFile mediaFile = new MP.Core.Models.MediaFile(); mediaFile.Analysis = analysis; mediaFile.FileName = fileInfo.Name; mediaFile.FileExt = fileInfo.Extension; mediaFile.FilePath = fileInfo.DirectoryName; mediaFile.Size = fileInfo.Length; mediaFile.ContentType = content_type; mediaFile.FilenameData = GetFilenameData(fileInfo.Name, content_type); mediaFile.BytesPerSecond = mediaFile.Size / (long)(analysis.Format.Duration.TotalSeconds); if (mediaFile.BytesPerSecond < 0) { mediaFile.BytesPerSecond = 0; } long pixelsPerFrame = 0; int maxWidth = 0; MP.Core.Models.VideoStream primaryVideoStream = null; foreach (MP.Core.Models.VideoStream v in analysis.VideoStreams) { if (v.Width > maxWidth) { maxWidth = v.Width; primaryVideoStream = v; } } if (primaryVideoStream != null) { pixelsPerFrame = primaryVideoStream.Width * primaryVideoStream.Height; } mediaFile.BytesPerSecondPerPixel = 0; if (pixelsPerFrame > 0) { mediaFile.BytesPerSecondPerPixel = (double)mediaFile.BytesPerSecond / (double)pixelsPerFrame; } return(mediaFile); }
public void Convert(ContainerFormat type, Action <IMediaAnalysis> validationMethod, params IArgument[] arguments) { var output = Input.OutputLocation(type); try { var input = FFProbe.Analyse(Input.FullName); var processor = FFMpegArguments .FromFileInput(VideoLibrary.LocalVideo) .OutputToFile(output, false, opt => { foreach (var arg in arguments) { opt.WithArgument(arg); } }); var scaling = arguments.OfType <ScaleArgument>().FirstOrDefault(); processor.ProcessSynchronously(); var outputVideo = FFProbe.Analyse(output); Assert.IsTrue(File.Exists(output)); Assert.AreEqual(outputVideo.Duration.TotalSeconds, input.Duration.TotalSeconds, 0.1); validationMethod?.Invoke(outputVideo); if (scaling?.Size == null) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } else { if (scaling.Size.Value.Width != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, scaling.Size.Value.Width); } if (scaling.Size.Value.Height != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, scaling.Size.Value.Height); } Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } } finally { if (File.Exists(output)) { File.Delete(output); } } }
public void Video_Snapshot_PersistSnapshot() { var outputPath = new TemporaryFile("out.png"); var input = FFProbe.Analyse(TestResources.Mp4Video); FFMpeg.Snapshot(input, outputPath); using var bitmap = Image.FromFile(outputPath); Assert.AreEqual(input.PrimaryVideoStream.Width, bitmap.Width); Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height); Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png); }
public void Audio_Add() { using var outputFile = new TemporaryFile("out.mp4"); var success = FFMpeg.ReplaceAudio(TestResources.Mp4WithoutAudio, TestResources.Mp3Audio, outputFile); var videoAnalysis = FFProbe.Analyse(TestResources.Mp4WithoutAudio); var audioAnalysis = FFProbe.Analyse(TestResources.Mp3Audio); var outputAnalysis = FFProbe.Analyse(outputFile); Assert.IsTrue(success); Assert.AreEqual(Math.Max(videoAnalysis.Duration.TotalSeconds, audioAnalysis.Duration.TotalSeconds), outputAnalysis.Duration.TotalSeconds, 0.15); Assert.IsTrue(File.Exists(outputFile)); }
public void ConvertFromPipe(ContainerFormat type, System.Drawing.Imaging.PixelFormat fmt, params IArgument[] arguments) { var output = Input.OutputLocation(type); try { var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, fmt, 256, 256)); var processor = FFMpegArguments.FromPipeInput(videoFramesSource).OutputToFile(output, false, opt => { foreach (var arg in arguments) { opt.WithArgument(arg); } }); var scaling = arguments.OfType <ScaleArgument>().FirstOrDefault(); processor.ProcessSynchronously(); var outputVideo = FFProbe.Analyse(output); Assert.IsTrue(File.Exists(output)); if (scaling?.Size == null) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, videoFramesSource.Width); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, videoFramesSource.Height); } else { if (scaling.Size.Value.Width != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, scaling.Size.Value.Width); } if (scaling.Size.Value.Height != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, scaling.Size.Value.Height); } Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, videoFramesSource.Width); Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, videoFramesSource.Height); } } finally { if (File.Exists(output)) { File.Delete(output); } } }
public void Video_StreamFile_OutputToMemoryStream() { var output = new MemoryStream(); FFMpegArguments .FromPipeInput(new StreamPipeSource(File.OpenRead(TestResources.WebmVideo)), options => options.ForceFormat("webm")) .OutputToPipe(new StreamPipeSink(output), options => options .ForceFormat("mpegts")) .ProcessSynchronously(); output.Position = 0; var result = FFProbe.Analyse(output); Console.WriteLine(result.Duration); }
public void Video_ToMP4_YUV444p() { using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}"); var success = FFMpegArguments .FromFileInput(TestResources.WebmVideo) .OutputToFile(outputFile, false, opt => opt .WithVideoCodec(VideoCodec.LibX264) .ForcePixelFormat("yuv444p")) .ProcessSynchronously(); Assert.IsTrue(success); var analysis = FFProbe.Analyse(outputFile); Assert.IsTrue(analysis.VideoStreams.First().PixelFormat == "yuv444p"); }
public bool Convert(ContainerFormat type, bool multithreaded = false, VideoSize size = VideoSize.Original) { var output = Input.OutputLocation(type); try { var input = FFProbe.Analyse(Input.FullName); FFMpeg.Convert(input, output, type, size: size, multithreaded: multithreaded); var outputVideo = FFProbe.Analyse(output); Assert.IsTrue(File.Exists(output)); Assert.AreEqual(outputVideo.Duration.TotalSeconds, input.Duration.TotalSeconds, 0.1); if (size == VideoSize.Original) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } else { Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, (int)size); } return(File.Exists(output) && outputVideo.Duration == input.Duration && ( ( size == VideoSize.Original && outputVideo.PrimaryVideoStream.Width == input.PrimaryVideoStream.Width && outputVideo.PrimaryVideoStream.Height == input.PrimaryVideoStream.Height ) || ( size != VideoSize.Original && outputVideo.PrimaryVideoStream.Width != input.PrimaryVideoStream.Width && outputVideo.PrimaryVideoStream.Height != input.PrimaryVideoStream.Height && outputVideo.PrimaryVideoStream.Height == (int)size ) )); } finally { if (File.Exists(output)) { File.Delete(output); } } }
// [DataRow(PixelFormat.Format48bppRgb)] public void RawVideoPipeSource_Ogv_Scale(System.Drawing.Imaging.PixelFormat pixelFormat) { using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}"); var videoFramesSource = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, pixelFormat, 256, 256)); FFMpegArguments .FromPipeInput(videoFramesSource) .OutputToFile(outputFile, false, opt => opt .WithVideoFilters(filterOptions => filterOptions .Scale(VideoSize.Ed)) .WithVideoCodec(VideoCodec.LibTheora)) .ProcessSynchronously(); var analysis = FFProbe.Analyse(outputFile); Assert.AreEqual((int)VideoSize.Ed, analysis.PrimaryVideoStream !.Width); }
public void Convert(ContainerFormat type, Action <IMediaAnalysis> validationMethod, params IArgument[] arguments) { using var outputFile = new TemporaryFile($"out{type.Extension}"); var input = FFProbe.Analyse(TestResources.Mp4Video); var processor = FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToFile(outputFile, false, opt => { foreach (var arg in arguments) { opt.WithArgument(arg); } }); var scaling = arguments.OfType <ScaleArgument>().FirstOrDefault(); processor.ProcessSynchronously(); var outputVideo = FFProbe.Analyse(outputFile); Assert.IsTrue(File.Exists(outputFile)); Assert.AreEqual(outputVideo.Duration.TotalSeconds, input.Duration.TotalSeconds, 0.1); validationMethod?.Invoke(outputVideo); if (scaling?.Size == null) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } else { if (scaling.Size.Value.Width != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, scaling.Size.Value.Width); } if (scaling.Size.Value.Height != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, scaling.Size.Value.Height); } Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } }
private void ConvertToStreamPipe(params IArgument[] arguments) { using var ms = new MemoryStream(); var processor = FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToPipe(new StreamPipeSink(ms), opt => { foreach (var arg in arguments) { opt.WithArgument(arg); } }); var scaling = arguments.OfType <ScaleArgument>().FirstOrDefault(); processor.ProcessSynchronously(); ms.Position = 0; var outputVideo = FFProbe.Analyse(ms); var input = FFProbe.Analyse(TestResources.Mp4Video); // Assert.IsTrue(Math.Abs((outputVideo.Duration - input.Duration).TotalMilliseconds) < 1000.0 / input.PrimaryVideoStream.FrameRate); if (scaling?.Size == null) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } else { if (scaling.Size.Value.Width != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, scaling.Size.Value.Width); } if (scaling.Size.Value.Height != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, scaling.Size.Value.Height); } Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } }
private void ConvertToStreamPipe(params IArgument[] inputArguments) { using var ms = new MemoryStream(); var arguments = FFMpegArguments.FromInputFiles(VideoLibrary.LocalVideo); foreach (var arg in inputArguments) { arguments.WithArgument(arg); } var streamPipeDataReader = new StreamPipeSink(ms); var processor = arguments.OutputToPipe(streamPipeDataReader); var scaling = arguments.Find <ScaleArgument>(); processor.ProcessSynchronously(); ms.Position = 0; var outputVideo = FFProbe.Analyse(ms); var input = FFProbe.Analyse(VideoLibrary.LocalVideo.FullName); // Assert.IsTrue(Math.Abs((outputVideo.Duration - input.Duration).TotalMilliseconds) < 1000.0 / input.PrimaryVideoStream.FrameRate); if (scaling?.Size == null) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } else { if (scaling.Size.Value.Width != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, scaling.Size.Value.Width); } if (scaling.Size.Value.Height != -1) { Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, scaling.Size.Value.Height); } Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width); Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height); } }
public void TranscodeToMemoryStream_Success() { using var output = new MemoryStream(); var success = FFMpegArguments .FromFileInput(TestResources.WebmVideo) .OutputToPipe(new StreamPipeSink(output), opt => opt .WithVideoCodec(VideoCodec.LibVpx) .ForceFormat("matroska")) .ProcessSynchronously(); Assert.IsTrue(success); output.Position = 0; var inputAnalysis = FFProbe.Analyse(TestResources.WebmVideo); var outputAnalysis = FFProbe.Analyse(output); Assert.AreEqual(inputAnalysis.Duration.TotalSeconds, outputAnalysis.Duration.TotalSeconds, 0.3); }
public void CaptureScreenTest() { var testFilePath = @"C:\Users\benp\test.mp4"; //var args = FFMpegArguments.FromScreenCapture(ScreenCaptureMethod.DShow, captureTarget: @"video=""UScreenCapture"":audio=""Stereo Mix"""); var args = FFMpegArguments.FromScreenCapture(ScreenCaptureMethod.GdiGrab); var processor = args.OutputToFile(testFilePath); var task = processor.CancellableThrough(out var cancelEvent); Task.Run(() => Thread.Sleep(TimeSpan.FromSeconds(5))).ContinueWith((t) => cancelEvent.Invoke()); var result = task.ProcessSynchronously(); var x = FFProbe.Analyse(testFilePath); Assert.IsTrue(result, "Failed to record"); Assert.IsTrue(x.Duration > TimeSpan.FromSeconds(1), "Resulting File too short"); }
public void Video_Duration() { var video = FFProbe.Analyse(TestResources.Mp4Video); var outputFile = new TemporaryFile("out.mp4"); FFMpegArguments .FromFileInput(TestResources.Mp4Video) .OutputToFile(outputFile, false, opt => opt.WithDuration(TimeSpan.FromSeconds(video.Duration.TotalSeconds - 2))) .ProcessSynchronously(); Assert.IsTrue(File.Exists(outputFile)); var outputVideo = FFProbe.Analyse(outputFile); 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 - 2, outputVideo.Duration.Seconds); }
public void Image_AddAudio() { var output = Input.OutputLocation(VideoType.Mp4); try { FFMpeg.PosterWithAudio(VideoLibrary.LocalCover.FullName, VideoLibrary.LocalAudio.FullName, output); var analysis = FFProbe.Analyse(VideoLibrary.LocalAudio.FullName); Assert.IsTrue(analysis.Duration.TotalSeconds > 0); Assert.IsTrue(File.Exists(output)); } finally { if (File.Exists(output)) { File.Delete(output); } } }
public void Video_TranscodeInMemory() { using var resStream = new MemoryStream(); var reader = new StreamPipeSink(resStream); var writer = new RawVideoPipeSource(BitmapSource.CreateBitmaps(128, System.Drawing.Imaging.PixelFormat.Format24bppRgb, 128, 128)); FFMpegArguments .FromPipeInput(writer) .OutputToPipe(reader, opt => opt .WithVideoCodec("vp9") .ForceFormat("webm")) .ProcessSynchronously(); resStream.Position = 0; var vi = FFProbe.Analyse(resStream); Assert.AreEqual(vi.PrimaryVideoStream.Width, 128); Assert.AreEqual(vi.PrimaryVideoStream.Height, 128); }
private void ConverterV2(FileDesc file) { FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = @"D:\Git\RocketMov\RocketMov\ffmpeg" }); var fileInfo = FFProbe.Analyse(file.PathIn); FFMpegArguments .FromFileInput(file.PathIn) .OutputToFile(file.PathOut, true, options => options .WithVideoCodec(VideoCodec.LibX264) .WithConstantRateFactor(21) .WithAudioCodec(AudioCodec.Aac) .WithVideoBitrate(_convertOptions.Bitrate) .WithFastStart() .Scale(_convertOptions.Width, _convertOptions.Height) .UsingThreads(4)) .NotifyOnProgress(onConvertProgress, fileInfo.Duration) .CancellableThrough(out _cancelConvertion) .ProcessSynchronously(); }