public static IVideoStream SetFormat(this IVideoStream stream, VideoFormat format) { switch (format) { case VideoFormat.h264x1080p: return(stream.SetSize(VideoSize.Hd1080).SetCodec(VideoCodec.H264)); case VideoFormat.h264x480p: return(stream.SetSize(VideoSize.Hd480).SetCodec(VideoCodec.H264)); case VideoFormat.h264x720p: return(stream.SetSize(VideoSize.Hd720).SetCodec(VideoCodec.H264)); } throw new ArgumentOutOfRangeException(nameof(format)); }
public static async Task <IConversionResult> generateBrokenSample(string master, string output, TimeSpan start, TimeSpan duration) { string temp = Path.GetFullPath(output) + "temp-" + Path.GetFileName(output); if (File.Exists(temp)) { File.Delete(temp); } IConversion bad = await FFmpeg.Conversions.FromSnippet.Split(master, temp, start, duration); bad.SetOverwriteOutput(true); bad.SetPixelFormat(randomPixelFormat()); // this does 90% of the crash randomizeScaleAndAspectRatio(bad); await bad.Start(); IMediaInfo meta = await FFmpeg.GetMediaInfo(temp); IVideoStream v = meta.VideoStreams.ToList().FirstOrDefault(); v.SetSize(randomVideoSize()); { var sub = SubtitleGenerator.New(); await sub.AddSubtitle(TimeSpan.FromSeconds(0), meta.Duration, " ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ 𓀐 ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ 𓀐 ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ 𓀐 ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ 𓀐 ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ 𓀐 ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺ͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩͩ 𓀐\n".Repeat(100)); v.AddSubtitles(sub.Filepath); } IAudioStream a = meta.AudioStreams.ToList().FirstOrDefault(); a.Reverse(); // the people who survive will get confused a.ChangeSpeed(0.5); var result = await FFmpeg.Conversions.New() .SetOverwriteOutput(true) .AddStream(v) .AddStream(a) .SetOutput(output) .SetPixelFormat(PixelFormat.yuv444p) .SetVideoSyncMethod(VideoSyncMethod.passthrough) .Start(); File.Delete(temp); return(result); }
// Grabs a screenshot from the specified video at the specified timestamp using `ffmpeg` // @param videoPath (String) the path to the video file // @param timestamp (String) the `ffmpeg` timestamp format (e.g. 00.00) // @param dimensions (Array) the dimension of the screenshot to generate // @return the TempFile containing the generated screenshot public static FileInfo GrabVideoPreview(string videoPath, string timestamp, int targetWidth = 0, int targetHeight = 0) { IMediaInfo mediaInfo = Task.Run(async() => await MediaInfo.Get(videoPath)).Result; IVideoStream videoStream = mediaInfo.VideoStreams.FirstOrDefault(); string output = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + FileExtensions.Jpg); var timestampDouble = double.Parse(timestamp, System.Globalization.CultureInfo.InvariantCulture); videoStream = videoStream.SetOutputFramesCount(1).SetSeek(TimeSpan.FromSeconds(timestampDouble)); if (targetWidth != 0 && targetHeight != 0) { videoStream = videoStream.SetSize(new VideoSize(targetWidth, targetHeight)); } Conversion.New().AddStream(videoStream).SetOutput(output); return(new FileInfo(output)); }