When using FFmpeg for video and audio processing, file formats supporting stdin input are primarily those that do not depend on file size or container-specific metadata. Typically, these formats are streaming-based, such as Transport Stream (TS) or raw formats like PCM audio or raw video data. This is because these formats enable continuous reading and processing of data without requiring seeks to specific file positions.
Common file formats supporting stdin input include:
-
MPEG Transport Stream (TS) - This format is widely used for digital video broadcasting and live streaming, and it is well-suited for piping.
-
Raw audio formats (e.g., PCM) - This format lacks file headers and metadata, with continuous data streams, making it ideal for reading from standard input.
-
Raw video formats - Similar to raw audio, raw video (typically in YUV or RGB formats) can be streamed through stdin as they consist of continuous video frame data.
Example
If you have a live video data stream that you want to encode or convert using FFmpeg, you can use the following command to pipe the data into FFmpeg:
bashcat input.yuv | ffmpeg -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -i - -c:v libx264 output.mp4
In this example, the cat input.yuv command reads data from a raw YUV video file and pipes it into FFmpeg. FFmpeg reads the input stream from stdin using the -i - option. The -f rawvideo option specifies that the input format is raw video data.
Important considerations
When using stdin, ensure you fully understand the data format and correctly set FFmpeg's input parameters (such as format -f, video size -video_size, pixel format -pixel_format, etc.), as FFmpeg cannot automatically detect these parameters from stdin. Additionally, the input data must be streamable; otherwise, it may result in processing failures or data corruption.