### Install FFmpeg Ubuntu Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Command to install FFmpeg and `libgdiplus` on Ubuntu systems using the `apt-get` package manager. This command requires root privileges. ```bash sudo apt-get install -y ffmpeg libgdiplus ``` -------------------------------- ### Install FFmpeg using Chocolatey Windows Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Command to install FFmpeg on Windows using Chocolatey package manager. The `-y` flag automatically confirms any prompts during installation. ```bash choco install ffmpeg -y ``` -------------------------------- ### Basic Video Conversion with FFMpegArguments (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Demonstrates basic video conversion using FFMpegArguments.FromFileInput. This example shows how to convert a video to H.264/AAC format with scaling for web playback and also an asynchronous conversion to WebM with progress tracking. It utilizes fluent API for setting codecs, bitrates, filters, and output options. ```csharp using FFMpegCore; using FFMpegCore.Enums; // Convert video to H.264/AAC with scaling for web playback FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4", true, options => options .WithVideoCodec(VideoCodec.LibX264) .WithConstantRateFactor(21) .WithAudioCodec(AudioCodec.Aac) .WithVariableBitrate(4) .WithVideoFilters(filterOptions => filterOptions .Scale(VideoSize.Hd)) .WithFastStart()) .ProcessSynchronously(); // Asynchronous conversion with progress tracking var mediaInfo = await FFProbe.AnalyseAsync("/path/to/input.mp4"); await FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.webm", true, options => options .WithVideoCodec(VideoCodec.LibVpx) .WithVideoBitrate(2400) .WithAudioCodec(AudioCodec.LibVorbis) .WithAudioBitrate(AudioQuality.Normal)) .NotifyOnProgress(percent => Console.WriteLine($"Progress: {percent}%"), mediaInfo.Duration) .ProcessAsynchronously(); ``` -------------------------------- ### Install FFmpeg using Homebrew Mac Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Command to install FFmpeg and `mono-libgdiplus` on macOS using the Homebrew package manager. This ensures FFmpeg is available in the system's PATH. ```bash brew install ffmpeg mono-libgdiplus ``` -------------------------------- ### Apply Audio Filters with FFMpegCore Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Applies audio filters such as normalization, high-pass, low-pass, and audio gating using FFMpegCore. This example demonstrates setting audio codec, bitrate, and sampling rate for MP3 output. ```csharp using FFMpegCore; using FFMpegCore.Enums; // Apply audio filters FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4", true, options => options .WithAudioCodec(AudioCodec.Aac) .WithAudioFilters(filterOptions => filterOptions .DynamicNormalizer() .HighPass(200) .LowPass(3000) .AudioGate())) .ProcessSynchronously(); // Set audio bitrate and sampling rate FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp3", true, options => options .DisableChannel(Channel.Video) .WithAudioCodec(AudioCodec.LibMp3Lame) .WithAudioBitrate(320) .WithAudioSamplingRate(44100)) .ProcessSynchronously(); ``` -------------------------------- ### Convert Video File with FFMpeg Arguments Builder (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Illustrates converting a video file using FFMpegArguments. This example converts to H.264/AAC, scales to 720p, and optimizes for web playback with faststart. It requires input and output file paths and utilizes a fluent API for setting codecs, filters, and options. ```csharp FFMpegArguments .FromFileInput(inputPath) .OutputToFile(outputPath, false, options => options .WithVideoCodec(VideoCodec.LibX264) .WithConstantRateFactor(21) .WithAudioCodec(AudioCodec.Aac) .WithVariableBitrate(4) .WithVideoFilters(filterOptions => filterOptions .Scale(VideoSize.Hd)) .WithFastStart()) .ProcessSynchronously(); ``` -------------------------------- ### FFmpeg Configuration JSON Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md An example of a `ffmpeg.config.json` file used to configure FFmpeg binary and temporary file directories. This configuration is read on the first use of the library. ```json { "BinaryFolder": "./bin", "TemporaryFilesFolder": "/tmp" } ``` -------------------------------- ### Convert Media Between Streams with FFMpeg (Async) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Shows how to convert media between streams using FFMpegArguments. This example uses StreamPipeSource and StreamPipeSink for input and output, specifying VP9 video codec and WebM format. It's suitable for on-the-fly processing without saving intermediate files. ```csharp await FFMpegArguments .FromPipeInput(new StreamPipeSource(inputStream)) .OutputToPipe(new StreamPipeSink(outputStream), options => options .WithVideoCodec("vp9") .ForceFormat("webm")) .ProcessAsynchronously(); ``` -------------------------------- ### Auto-Download FFMpeg Binaries - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Automatically downloads the latest FFMpeg and FFProbe binaries for the current operating system at runtime. This simplifies setup by ensuring the necessary executables are available. It allows specifying the version and which binaries to download. ```csharp using FFMpegCore; using FFMpegCore.Extensions.Downloader; using FFMpegCore.Extensions.Downloader.Enums; // Download latest FFMpeg and FFProbe binaries GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "./ffmpeg" }); var downloadedFiles = await FFMpegDownloader.DownloadBinaries( version: FFMpegVersions.LatestAvailable, binaries: FFMpegBinaries.FFMpeg | FFMpegBinaries.FFProbe); foreach (var file in downloadedFiles) { Console.WriteLine($"Downloaded: {file}"); } ``` -------------------------------- ### Progress Notifications and Cancellation in FFMpegCore Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Monitors conversion progress and implements cancellation support using FFMpegCore. It shows how to get media information, notify on progress by percentage or time, and handle cancellation through a CancellationTokenSource or manual cancellation action. ```csharp using FFMpegCore; var mediaInfo = await FFProbe.AnalyseAsync("/path/to/input.mp4"); using var cts = new CancellationTokenSource(); // Progress by percentage await FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4", true, options => options .WithVideoCodec(VideoCodec.LibX264)) .NotifyOnProgress(percentage => { Console.WriteLine($"Progress: {percentage:F2}%"); }, mediaInfo.Duration) .NotifyOnOutput(output => Console.WriteLine($"Output: {output}")) .NotifyOnError(error => Console.WriteLine($"Error: {error}")) .CancellableThrough(cts.Token) .ProcessAsynchronously(); // Progress by time await FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4") .NotifyOnProgress(time => { Console.WriteLine($"Processed: {time}"); }) .ProcessAsynchronously(); // Manual cancellation Action cancelAction; var task = FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4") .CancellableThrough(out cancelAction, timeout: 5000) .ProcessAsynchronously(); // Call cancelAction() to cancel the operation ``` -------------------------------- ### Query Available Codecs with FFMpeg.GetCodecs Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Retrieves information about available codecs, container formats, and pixel formats supported by the FFMpeg installation using FFMpegCore. It demonstrates how to get all codecs, filter by type (video/audio), and check for specific codec availability. ```csharp using FFMpegCore; using FFMpegCore.Enums; // Get all available codecs var allCodecs = FFMpeg.GetCodecs(); // Get video codecs only var videoCodecs = FFMpeg.GetVideoCodecs(); // Get audio codecs only var audioCodecs = FFMpeg.GetAudioCodecs(); // Check for specific codec if (FFMpeg.TryGetCodec("libx264", out var codec)) { Console.WriteLine($"Codec: {codec.Name}"); Console.WriteLine($"Type: {codec.Type}"); Console.WriteLine($"Can Encode: {codec.EncoderName != null}"); Console.WriteLine($"Can Decode: {codec.DecoderName != null}"); } // Get available container formats var formats = FFMpeg.GetContainerFormats(); // Get available pixel formats var pixelFormats = FFMpeg.GetPixelFormats(); ``` -------------------------------- ### Create Subclip from Video with FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Explains how to extract a portion of a video file to create a subclip. This function requires the input and output paths, along with start and end TimeSpans to define the segment to be extracted. ```csharp FFMpeg.SubVideo(inputPath, outputPath, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30) ); ``` -------------------------------- ### Get Packet Information from Media Files with FFProbe (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Retrieves packet-level information from a media file, essential for low-level stream analysis. It provides details such as stream index, presentation timestamp (PTS), and packet size. Supports synchronous and asynchronous retrieval. ```csharp using FFMpegCore; // Get packet information var packets = FFProbe.GetPackets("/path/to/video.mp4"); foreach (var packet in packets.Packets) { Console.WriteLine($"Stream Index: {packet.StreamIndex}"); Console.WriteLine($"PTS: {packet.PtsTime}"); Console.WriteLine($"Size: {packet.Size} bytes"); } // Asynchronous version var asyncPackets = await FFProbe.GetPacketsAsync("/path/to/video.mp4"); ``` -------------------------------- ### FFMpegArguments: Stream-Based Processing (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Enables processing media data directly from streams without intermediate files. This example shows converting from an input stream to an output stream and processing raw video frames from memory. It requires FFMpegCore and System.IO namespaces. ```csharp using FFMpegCore; using FFMpegCore.Pipes; using System.IO; // Convert from input stream to output stream using var inputStream = File.OpenRead("/path/to/input.mp4"); using var outputStream = File.Create("/path/to/output.webm"); await FFMpegArguments .FromPipeInput(new StreamPipeSource(inputStream)) .OutputToPipe(new StreamPipeSink(outputStream), options => options .WithVideoCodec("vp9") .ForceFormat("webm")) .ProcessAsynchronously(); // Process raw video frames from memory IEnumerable GenerateFrames(int count) { for (int i = 0; i < count; i++) { // Generate or receive frames programmatically yield return GetNextFrame(); } } var videoFramesSource = new RawVideoPipeSource(GenerateFrames(120)) { FrameRate = 30 }; await FFMpegArguments .FromPipeInput(videoFramesSource) .OutputToFile("/path/to/output.mp4", true, options => options .WithVideoCodec(VideoCodec.LibX264)) .ProcessAsynchronously(); ``` -------------------------------- ### Get Frame Information from Media Files with FFProbe (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Retrieves detailed information about individual frames within a media file, including media type, presentation timestamp (PTS), and whether the frame is a key frame. Supports both synchronous and asynchronous operations. ```csharp using FFMpegCore; // Get frame information from a video file var frames = FFProbe.GetFrames("/path/to/video.mp4"); foreach (var frame in frames.Frames) { Console.WriteLine($"Frame Type: {frame.MediaType}"); Console.WriteLine($"PTS: {frame.PtsTime}"); Console.WriteLine($"Key Frame: {frame.KeyFrame}"); } // Asynchronous version var asyncFrames = await FFProbe.GetFramesAsync("/path/to/video.mp4"); ``` -------------------------------- ### FFMpeg.SubVideo: Extract Video Segment (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Creates a new video file containing only a specified segment of the original video. Users can define the start and end times for the extraction. An asynchronous version with cancellation support is also available. Requires FFMpegCore. ```csharp using FFMpegCore; // Extract a 30-second clip starting at 1 minute FFMpeg.SubVideo( "/path/to/input.mp4", "/path/to/clip.mp4", TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1).Add(TimeSpan.FromSeconds(30))); // Async version with cancellation support await FFMpeg.SubVideoAsync( "/path/to/input.mp4", "/path/to/clip.mp4", TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(60), cancellationToken); ``` -------------------------------- ### Configure FFMpeg Paths via JSON and Code Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Demonstrates configuring FFMpeg paths and other options using a JSON configuration file or programmatically. The configuration is automatically loaded from `ffmpeg.config.json` on first use, but can be overridden with `GlobalFFOptions.Configure`. ```csharp using FFMpegCore; // Configuration is automatically loaded from ffmpeg.config.json on first use var mediaInfo = FFProbe.Analyse("/path/to/video.mp4"); // Or configure programmatically and override GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "/usr/local/bin", TemporaryFilesFolder = "/var/tmp", WorkingDirectory = "/home/user/media", UseCache = true }); ``` -------------------------------- ### Configure FFMpeg Binary Paths and Options - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Configures global settings for the FFMpegCore library, including the location of FFMpeg and FFProbe binaries and the directory for temporary files. It supports both direct configuration and action-based configuration, as well as per-run overrides. ```csharp using FFMpegCore; // Configure binary folder and temp directory GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" }); // Configure using action GlobalFFOptions.Configure(options => { options.BinaryFolder = "./ffmpeg-binaries"; options.WorkingDirectory = "./media"; }); // Per-run configuration override await FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4") .Configure(options => options.WorkingDirectory = "./custom-working-dir") .Configure(options => options.TemporaryFilesFolder = "./custom-temp") .ProcessAsynchronously(); ``` -------------------------------- ### Create Video from Image Sequence with FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Shows how to create a video file from a sequence of images. This method takes the output path, frame rate, and a variable list of ImageInfo objects representing the image files. Useful for creating videos from image series. ```csharp FFMpeg.JoinImageSequence(@"..\joined_video.mp4", frameRate: 1, ImageInfo.FromPath(@"..\1.png"), ImageInfo.FromPath(@"..\2.png"), ImageInfo.FromPath(@"..\3.png") ); ``` -------------------------------- ### Combine Image with Audio to Create Video - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Creates a video file using a static image as the visual component and an audio file for the sound. This is commonly used for creating music videos or visualizers for podcasts. It takes paths for the image, audio, and the desired output video. ```csharp using FFMpegCore; // Create video with poster image and audio FFMpeg.PosterWithAudio( "/path/to/image.jpg", "/path/to/audio.mp3", "/path/to/output.mp4"); ``` -------------------------------- ### Analyze Media File with FFProbe (Async/Sync) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Demonstrates how to analyze media files using FFProbe. It shows both asynchronous and synchronous methods for retrieving media information. This requires the input file path as a string. ```csharp var mediaInfo = await FFProbe.AnalyseAsync(inputPath); var mediaInfo = FFProbe.Analyse(inputPath); ``` -------------------------------- ### Combine Image with Audio using FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Shows how to combine a static image with an audio file to create a video, often used for platforms like YouTube. It offers two syntaxes: a direct FFMpeg call or an extension method on the Image object. ```csharp FFMpeg.PosterWithAudio(inputPath, inputAudioPath, outputPath); // or var image = Image.FromFile(inputImagePath); image.AddAudio(inputAudioPath, outputPath); ``` -------------------------------- ### Configure Global FFmpeg Options C# Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Demonstrates how to configure global FFmpeg options, such as the binary folder and temporary files folder, using the `GlobalFFOptions` class. This affects all subsequent FFmpeg operations unless overridden. ```csharp // setting global options GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" }); // or GlobalFFOptions.Configure(options => options.BinaryFolder = "./bin"); // on some systems the absolute path may be required, in which case GlobalFFOptions.Configure(new FFOptions { BinaryFolder = Server.MapPath("./bin"), TemporaryFilesFolder = Server.MapPath("/tmp") }); ``` -------------------------------- ### Video Format Conversion with Presets - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Converts video files from one format to another using predefined quality and speed presets. It allows specifying input and output paths, container format, speed, video size, and audio quality. This simplifies common conversion tasks. ```csharp using FFMpegCore; using FFMpegCore.Enums; // Convert to MP4 with quality settings FFMpeg.Convert( "/path/to/input.avi", "/path/to/output.mp4", ContainerFormat.Mp4, speed: Speed.Medium, size: VideoSize.Hd, audioQuality: AudioQuality.Good, multithreaded: true); // Convert to WebM FFMpeg.Convert( "/path/to/input.mp4", "/path/to/output.webm", ContainerFormat.WebM, speed: Speed.Fast, size: VideoSize.Original, audioQuality: AudioQuality.Normal); ``` -------------------------------- ### Process FFmpeg with Per-Run Options C# Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Shows how to process FFmpeg tasks with specific options for a single run, overriding global configurations if necessary. This allows for flexible control over FFmpeg execution for individual operations. ```csharp await FFMpegArguments .FromFileInput(inputPath) .OutputToFile(outputPath) .ProcessAsynchronously(true, new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "/tmp" }); // or combined, setting global defaults and adapting per-run options GlobalFFOptions.Configure(new FFOptions { BinaryFolder = "./bin", TemporaryFilesFolder = "./globalTmp", WorkingDirectory = "./" }); await FFMpegArguments .FromFileInput(inputPath) .OutputToFile(outputPath) .Configure(options => options.WorkingDirectory = "./CurrentRunWorkingDir") .Configure(options => options.TemporaryFilesFolder = "./CurrentRunTmpFolder") .ProcessAsynchronously(); ``` -------------------------------- ### Create RawVideoPipeSource and Process Video C# Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Creates a `RawVideoPipeSource` from a sequence of video frames and processes it to an output file using a specified video codec. It sets the frame rate for the source and uses FFmpeg for encoding. ```csharp var videoFramesSource = new RawVideoPipeSource(CreateFrames(64)) { FrameRate = 30 //set source frame rate }; await FFMpegArguments .FromPipeInput(videoFramesSource) .OutputToFile(outputPath, false, options => options .WithVideoCodec(VideoCodec.LibVpx)) .ProcessAsynchronously(); ``` -------------------------------- ### FFMpegArguments: Combine Inputs and Map Streams (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Demonstrates how to combine multiple input files and map specific streams for advanced operations. This includes adding audio to video, concatenating videos using demux concat, and selecting specific video/audio streams. It utilizes FFMpegArguments from the FFMpegCore library. ```csharp using FFMpegCore; using FFMpegCore.Enums; // Add audio track to video FFMpegArguments .FromFileInput("/path/to/video.mp4") .AddFileInput("/path/to/audio.mp3") .OutputToFile("/path/to/output.mp4", true, options => options .CopyChannel() .WithAudioCodec(AudioCodec.Aac) .WithAudioBitrate(AudioQuality.Good) .UsingShortest()) .ProcessSynchronously(); // Concatenate multiple videos using demux concat FFMpegArguments .FromDemuxConcatInput(new[] { "/path/to/part1.mp4", "/path/to/part2.mp4", "/path/to/part3.mp4" }) .OutputToFile("/path/to/combined.mp4", true, options => options .CopyChannel()) .ProcessSynchronously(); // Select specific streams FFMpegArguments .FromFileInput("/path/to/input.mkv") .OutputToFile("/path/to/output.mp4", true, options => options .SelectStream(0, 0, Channel.Video) // Select first video stream .SelectStream(1, 0, Channel.Audio) // Select second audio stream .WithVideoCodec(VideoCodec.LibX264) .WithAudioCodec(AudioCodec.Aac)) .ProcessSynchronously(); ``` -------------------------------- ### Replace or Add Audio Track to Video with FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Explains how to replace an existing audio track or add an audio track to a video file. It requires the input video path, the path to the new audio file, and the output path for the modified video. ```csharp FFMpeg.ReplaceAudio(inputPath, inputAudioPath, outputPath); ``` -------------------------------- ### Capture Video Snapshot with FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Provides methods for capturing snapshots from video files. It demonstrates capturing a snapshot in-memory as a Bitmap and persisting it directly to a file. Requires input path, desired size, and a TimeSpan for the capture time. ```csharp // process the snapshot in-memory and use the Bitmap directly var bitmap = FFMpeg.Snapshot(inputPath, new Size(200, 400), TimeSpan.FromMinutes(1)); // or persists the image on the drive FFMpeg.Snapshot(inputPath, outputPath, new Size(200, 400), TimeSpan.FromMinutes(1)); ``` -------------------------------- ### Capture GIF Snapshot from Video with FFMpeg (Async/Sync) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Details capturing animated GIF snapshots from video files. It includes asynchronous and synchronous methods, allowing for custom dimensions (maintaining aspect ratio with -1) and specifying the capture time. Requires input/output paths, size, and TimeSpan. ```csharp FFMpeg.GifSnapshot(inputPath, outputPath, new Size(200, 400), TimeSpan.FromSeconds(10)); // or async await FFMpeg.GifSnapshotAsync(inputPath, outputPath, new Size(200, 400), TimeSpan.FromSeconds(10)); // you can also supply -1 to either one of Width/Height Size properties if you'd like FFMPEG to resize while maintaining the aspect ratio await FFMpeg.GifSnapshotAsync(inputPath, outputPath, new Size(480, -1), TimeSpan.FromSeconds(10)); ``` -------------------------------- ### Join Multiple Video Files with FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Demonstrates joining multiple video files into a single output file. This method takes the output file path and a variable number of input file paths. It's a straightforward way to concatenate video segments. ```csharp FFMpeg.Join(@"..\joined_video.mp4", @"..\part1.mp4", @"..\part2.mp4", @"..\part3.mp4" ); ``` -------------------------------- ### Extract Audio Track from Video with FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Demonstrates extracting the audio track from a video file. This function requires the input video path and the output path where the extracted audio will be saved. ```csharp FFMpeg.ExtractAudio(inputPath, outputPath); ``` -------------------------------- ### Analyze Media Files with FFProbe (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Analyzes media files to extract detailed information such as duration, format, video stream properties (resolution, frame rate, codec), and audio stream properties (codec, channels, sample rate). Supports synchronous, asynchronous, URI, and stream-based analysis. ```csharp using FFMpegCore; // Synchronous analysis of a local file var mediaInfo = FFProbe.Analyse("/path/to/video.mp4"); // Access media properties Console.WriteLine($"Duration: {mediaInfo.Duration}"); Console.WriteLine($"Format: {mediaInfo.Format.FormatName}"); // Video stream information if (mediaInfo.PrimaryVideoStream != null) { var video = mediaInfo.PrimaryVideoStream; Console.WriteLine($"Video: {video.Width}x{video.Height} @ {video.FrameRate}fps"); Console.WriteLine($"Codec: {video.CodecName}"); Console.WriteLine($"Bitrate: {video.BitRate} bps"); } // Audio stream information if (mediaInfo.PrimaryAudioStream != null) { var audio = mediaInfo.PrimaryAudioStream; Console.WriteLine($"Audio: {audio.CodecName}, {audio.Channels} channels, {audio.SampleRateHz}Hz"); } // Asynchronous analysis var asyncMediaInfo = await FFProbe.AnalyseAsync("/path/to/video.mp4"); // Analyze from URI var urlMediaInfo = FFProbe.Analyse(new Uri("https://example.com/video.mp4")); // Analyze from stream using var fileStream = File.OpenRead("/path/to/video.mp4"); var streamMediaInfo = await FFProbe.AnalyseAsync(fileStream); ``` -------------------------------- ### Create Video from Image Sequence - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Generates a video file from a sequence of image files. It requires the output video path, a frame rate, and the paths to the image sequence. This is ideal for creating videos from frame-by-frame animations or captured frames. ```csharp using FFMpegCore; // Create video from image sequence FFMpeg.JoinImageSequence( "/path/to/output.mp4", frameRate: 24, "/path/to/frame001.png", "/path/to/frame002.png", "/path/to/frame003.png"); ``` -------------------------------- ### FFMpeg.Snapshot: Capture Video Thumbnails (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Captures a single frame from a video as an image file, useful for generating thumbnails. This function supports saving to file, asynchronous capture with specific stream selection, and capturing animated GIF previews. It requires FFMpegCore and System.Drawing namespaces. ```csharp using FFMpegCore; using System.Drawing; // Save snapshot to file FFMpeg.Snapshot( "/path/to/video.mp4", "/path/to/thumbnail.png", new Size(320, 180), TimeSpan.FromSeconds(30)); // Async version with specific stream await FFMpeg.SnapshotAsync( "/path/to/video.mp4", "/path/to/thumbnail.jpg", new Size(640, 360), TimeSpan.FromMinutes(1), streamIndex: 0); // Capture GIF snapshot (animated preview) FFMpeg.GifSnapshot( "/path/to/video.mp4", "/path/to/preview.gif", new Size(480, 270), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(5)); // 5-second duration // Async GIF with aspect ratio preservation await FFMpeg.GifSnapshotAsync( "/path/to/video.mp4", "/path/to/preview.gif", new Size(480, -1), // -1 preserves aspect ratio TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(3)); ``` -------------------------------- ### Mute Audio Track of Video with FFMpeg (C#) Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Provides a simple method to mute the audio track of a video file. It takes the input video path and the desired output path for the video without audio. ```csharp FFMpeg.Mute(inputPath, outputPath); ``` -------------------------------- ### FFMpeg.Join: Concatenate Video Files (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Joins multiple video files sequentially into a single output file. This method takes the output file path followed by the paths of the video files to be joined. It requires the FFMpegCore library. ```csharp using FFMpegCore; // Join multiple video parts FFMpeg.Join( "/path/to/joined_video.mp4", "/path/to/part1.mp4", "/path/to/part2.mp4", "/path/to/part3.mp4"); ``` -------------------------------- ### Record HLS Stream to Local File - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Records a live HLS (HTTP Live Streaming) stream to a local video file. It requires the URI of the M3U8 playlist and the desired output file path. This function is useful for capturing live streams for later playback or archival. ```csharp using FFMpegCore; // Record HLS stream FFMpeg.SaveM3U8Stream( new Uri("https://example.com/stream/playlist.m3u8"), "/path/to/recorded.mp4"); ``` -------------------------------- ### Apply Video Filters (Scale, Crop, Transform) - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Applies various video filters to manipulate video streams, including resizing, cropping, mirroring, and rotation. This allows for advanced video processing directly within the application. It uses the `FFMpegArguments` fluent API for building filter chains. ```csharp using FFMpegCore; using FFMpegCore.Enums; using System.Drawing; // Scale video with filters FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4", true, options => options .WithVideoCodec(VideoCodec.LibX264) .WithVideoFilters(filterOptions => filterOptions .Scale(1920, 1080) .Mirror(Mirroring.Horizontal) .Transpose(Transposition.ClockwiseAndFlip))) .ProcessSynchronously(); // Crop video FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4", true, options => options .Crop(new Size(1280, 720), left: 100, top: 50)) .ProcessSynchronously(); // Resize to specific dimensions FFMpegArguments .FromFileInput("/path/to/input.mp4") .OutputToFile("/path/to/output.mp4", true, options => options .Resize(1280, 720)) .ProcessSynchronously(); ``` -------------------------------- ### Generate Raw Video Frames C# Source: https://github.com/rosenbjerg/ffmpegcore/blob/main/README.md Generates a sequence of raw video frames using an iterator. The `GetNextFrame()` method is responsible for producing or retrieving each frame. This is useful for custom video processing pipelines. ```csharp IEnumerable CreateFrames(int count) { for(int i = 0; i < count; i++) { yield return GetNextFrame(); //method that generates of receives the next frame } } ``` -------------------------------- ### Replace Audio Track in Video - C# Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Replaces the audio track of a video file with a new audio file. It takes the input video path, new audio path, output video path, and an optional 'stopAtShortest' parameter. This function is useful for updating audio in existing videos. ```csharp using FFMpegCore; // Replace video's audio with different audio file FFMpeg.ReplaceAudio( "/path/to/video.mp4", "/path/to/new_audio.mp3", "/path/to/output.mp4", stopAtShortest: true); ``` -------------------------------- ### FFMpeg.ExtractAudio: Extract Audio Track (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Extracts the audio track from a video file and saves it as a separate audio file. This method allows users to specify the input video and the output audio file path, including the desired audio format (e.g., MP3). Requires FFMpegCore. ```csharp using FFMpegCore; // Extract audio as MP3 FFMpeg.ExtractAudio("/path/to/video.mp4", "/path/to/audio.mp3"); ``` -------------------------------- ### FFMpeg.Mute: Remove Audio Track (C#) Source: https://context7.com/rosenbjerg/ffmpegcore/llms.txt Removes the audio track from a video file, resulting in a silent video. This function takes the input video path and the desired output path for the muted video. It requires the FFMpegCore library. ```csharp using FFMpegCore; // Create muted version of video FFMpeg.Mute("/path/to/input.mp4", "/path/to/silent_output.mp4"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.