Pipe Raw Video Streams Reliably Using FFmpeg Nut

This article explains how to use the FFmpeg Nut container to pipe raw, uncompressed video streams between processes reliably. You will learn why the Nut format is superior to standard raw video streams for piping, how it preserves essential metadata, and how to implement it using simple command-line examples.

When piping video between different processes, developers often default to raw video streams using formats like rawvideo or yuv4mpegpipe. However, these formats present challenges. Plain rawvideo lacks any container metadata, requiring you to manually specify the resolution, pixel format, and framerate on the receiving end. While yuv4mpegpipe includes a header, it lacks robust error recovery and does not easily support multiple streams (like synchronized audio and video).

The Nut container (-f nut) is an open, lightweight, and low-overhead container format developed by the FFmpeg community. It is specifically designed to stream multiplexed audio and video over pipes. Because Nut embeds stream headers—including dimensions, pixel format, framerate, and timebase—directly into the stream, the receiving process can automatically configure itself without any hardcoded command-line parameters.

The Basic Nut Pipe Command

To pipe a raw video stream from one FFmpeg process to another using the Nut container, use the following syntax:

ffmpeg -i input.mp4 -f nut -c:v rawvideo -pix_fmt yuv420p - | ffmpeg -f nut -i - -c:v libx264 output.mp4

In this command: * -f nut: Forces FFmpeg to mux the output of the first process (and demux the input of the second process) using the Nut container format. * -c:v rawvideo: Tells FFmpeg to output uncompressed raw video frames inside the Nut container. * -pix_fmt yuv420p: Defines the pixel format of the raw video to ensure compatibility. * - (or pipe:1 / pipe:0): Represents standard output for the writer and standard input for the reader.

Why Nut is Highly Reliable

Nut is uniquely suited for piping because of its recovery capabilities. The format contains syncpoint markers at regular intervals. If your pipe experiences latency, buffer underruns, or temporary data corruption, the receiving FFmpeg process can quickly resynchronize with the stream at the next syncpoint.

Additionally, Nut fully supports stream copying. If you want to pipe compressed video (like H.264 or HEVC) instead of raw video, you can do so without losing packet boundaries or timestamps:

ffmpeg -i input.mp4 -f nut -c:v copy -an - | ffmpeg -f nut -i - -c:v libx265 output.mp4

Using the Nut container eliminates the fragility of raw video pipes, ensuring your video processing pipelines remain stable, metadata-rich, and easy to maintain.