How to Write Raw Video to Unix FIFO Using FFmpeg
This article provides a straightforward guide on how to stream raw video frames from FFmpeg into a Unix named pipe (FIFO). You will learn how to create the named pipe, configure FFmpeg to output uncompressed pixel data, and understand how to handle the blocking nature of Unix FIFOs during transmission.
Step 1: Create the Named Pipe (FIFO)
Before running FFmpeg, you must create a named pipe in your Unix
terminal using the mkfifo command. This creates a special
file that facilitates inter-process communication.
mkfifo my_video_pipe.fifoStep 2: Write Raw Video to the Pipe with FFmpeg
To send raw video frames to the FIFO, you must instruct FFmpeg to use
the raw video muxer (-f rawvideo) and specify your desired
pixel format (such as rgb24 or yuv420p).
Run the following command to start writing to the pipe:
ffmpeg -i input.mp4 -f rawvideo -pix_fmt rgb24 my_video_pipe.fifoKey Parameters Explained: *
-i input.mp4: The input video file. *
-f rawvideo: Forces FFmpeg to output raw,
demuxed, and uncompressed video frames. *
-pix_fmt rgb24: Defines the pixel layout.
In this case, 24-bit raw RGB (8 bits per channel). You can change this
to yuv420p or other formats depending on your consumer
program’s requirements. *
my_video_pipe.fifo: The path to your
created Unix named pipe.
Step 3: Read from the Pipe
Unix FIFOs are blocking by default. When you run the FFmpeg command in Step 2, it will pause (hang) until another process opens the pipe to read the data.
To consume the raw video frames, open a second terminal window and read from the pipe using a programming language (like Python or C++), a media player, or another command-line utility.
For example, you can pipe the raw data back into another FFmpeg process to verify it works:
ffmpeg -f rawvideo -pixel_format rgb24 -video_size 1920x1080 -framerate 30 -i my_video_pipe.fifo output.mp4Note: When reading raw video from a pipe, you must explicitly
define the input video size (e.g., -video_size 1920x1080)
and framerate (e.g., -framerate 30) because raw video files
do not contain header metadata.