Skip to content

FFmpeg Processors

Axwabo edited this page Apr 1, 2026 · 4 revisions

FFmpeg-based Audio Processors

Important

Consider streaming a file if the file type is supported.

These audio processors read 32-bit floats from FFmpeg's standard output.

Example

To stream live radio, pass the URL to the UseFFmpeg extension method on an AudioPlayer

using SecretLabNAudio.FFmpeg.Extensions;

// radio1.hu
audioPlayer.UseFFmpeg("https://icast.connectmedia.hu/5201/live.mp3");

The above code is the same as:

using SecretLabNAudio.Core.Extensions;
using SecretLabNAudio.FFmpeg.Processors;

audioPlayer.Use(AsyncBufferedFFmpegAudioProcessor.CreatePlayerCompatible("https://icast.connectmedia.hu/5201/live.mp3"));

AsyncFFmpegProcessorBase

This is the base class for processing FFmpeg output asynchronously. It cannot be inherited from user code.

The reader thread waits for 100 milliseconds before reading again if the buffer's sample count is greater than or equal to SleepThresholdSamples

Reading from this provider will pad the output with silence until the first time the underlying buffer has at least SleepThresholdSamples

The capacity can only be set in the constructor; it has a minimum value of 1920 samples.

The sleep threshold can be modified at any time. it defaults to 75% of the capacity.

Setting the Endless property to true will make the Read method pad the output with silence if the buffer is empty, even if enough data has been buffered earlier. This can be useful if the source sometimes hangs for a bit.

Tip

Use the HandleError or MapError extension method to deal with errors.

Call the StopBuffering method to stop the buffering thread. After invocation, remaining data can still be read, but buffering cannot be restarted. This method is invoked when Dispose is called.

Call the ClearBuffer method to discard data in the buffer. To make the processor pad the output until enough data is read again, set the waitForRefill parameter to true

BufferingState transition
  1. ResolvingStream (if stream-based)
  2. StartingFFmpeg
  3. PreFillingBuffer
  4. Reading - back to step 3 if:
    • ClearBuffer is called
    • Endless is true and not enough data is available
  5. Ended

If the state is Reading or Ended, and no error has occurred, the underlying buffer's remaining data can be extracted with the Read method. Otherwise, the provided buffer is cleared (padded with silence).

AsyncBufferedFFmpegAudioProcessor

A simple subclass of AsyncFFmpegProcessorBase. It accepts a string input source (e.g. file path, URL).

FFmpeg is started with the specified arguments.

StreamBasedFFmpegAudioProcessor

A subclass of AsyncFFmpegProcessorBase that reads from a managed Stream

A delegate is invoked to fetch the stream asynchronously. If the delegate throws an exception, the AsyncException property will be set.

When the stream has been resolved, FFmpeg is started, and the stream is copied to FFmpeg's standard input. If CopyToAsync throws before buffering is canceled, the AsyncException property will be set.

SynchronousFFmpegAudioProcessor

Important

This processor blocks the current thread until FFmpeg process is started, and when reading from the standard output.

A fully synchronous audio processor that starts FFmpeg in the constructor. When calling read, it blocks the calling thread until FFmpeg outputs data.

Getting Started

Playing Audio

Advanced

Audio Processors

FFmpeg

v1 Guides

Caution

v1 will be out of support soon.

Clone this wiki locally