How to Use Named Pipes as FFmpeg Input

This article explains how to configure FFmpeg to read multimedia data from a named pipe (also known as a FIFO) instead of a standard static file. You will learn how to create a named pipe, feed data into it from an external process, and run the correct FFmpeg command to process the stream in real-time.

Understanding Named Pipes in FFmpeg

A named pipe is a specialized file system object that allows different processes to communicate with each other by passing data. Instead of writing temporary files to a disk, one application can write data directly into the pipe while FFmpeg reads from it simultaneously, saving disk space and reducing I/O latency.

Because a named pipe does not support seeking (moving backward or forward in the file), FFmpeg must process the incoming data as a continuous, sequential stream.

Step-by-Step Implementation on Linux and macOS

To read from a named pipe, you must first create the pipe, start writing data to it, and then direct FFmpeg to read from it.

Step 1: Create the Named Pipe

Use the mkfifo command in your terminal to create a named pipe.

mkfifo my_stream.pipe

Step 2: Send Data to the Pipe

Before FFmpeg can read from the pipe, a writer process must open the pipe and begin sending data. Named pipes block execution until both a reader and a writer are connected.

For example, you can stream an existing video file into the pipe using cat:

cat input_video.mp4 > my_stream.pipe &

(The & symbol runs the writing process in the background, keeping your terminal free.)

Step 3: Read from the Pipe with FFmpeg

Now, run FFmpeg and point the input parameter (-i) to the named pipe file path.

ffmpeg -i my_stream.pipe -c:v copy -c:a copy output.mp4

FFmpeg will open the pipe, detect the container format and codecs of the incoming stream, process the data, and write it to output.mp4.

Handling Raw or Formatless Streams

If the data being sent through the pipe is raw stream data (such as raw video frames, PCM audio, or MJPEG sequences) that lacks container headers, FFmpeg will not be able to auto-detect the input format.

In these cases, you must explicitly specify the input format, resolution, and framerate before the -i argument in your FFmpeg command:

ffmpeg -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -framerate 30 -i my_stream.pipe output.mp4

For a sequence of raw JPEG images, use the image2pipe format:

ffmpeg -f image2pipe -i my_stream.pipe -c:v libx264 output.mp4

Windows Named Pipes

On Windows, named pipes use a different syntax (\\.\pipe\pipename). While native Windows command prompt does not have a built-in mkfifo equivalent, you can read from a Windows named pipe using FFmpeg by specifying the pipe path:

ffmpeg -i \\.\pipe\mypipename -c:v copy output.mp4