Yes – FFmpeg can write its output straight to an arbitrary file descriptor rather than to a filename on disk. You have two basic ways to do this:
- “pipe:” – write to stdin/stdout (fd 0/1)
- “fd:” – write to any numbered FD (fd 0..4095)
1. Using pipe: (stdout)
The most common trick is to send your encoded bitstream to stdout and then redirect it:
# encode input.mp4 → H.264 bitstream on stdout → save to out.h264
ffmpeg -i input.mp4 \
-c:v libx264 -preset medium -tune film \
-f h264 pipe:1 \
> out.h264
Under the hood “pipe:1” means “mux into format (-f h264) and write to FD 1 (stdout).”
You can also read from stdin with pipe:0:
cat input.yuv | \
ffmpeg -f rawvideo -pix_fmt yuv420p -s 640x480 -i pipe:0 \
-c:v libx264 -f mp4 pipe:1 > out.mp4
2. Using fd: (any descriptor)
If you want to bind to, say, FD 3, you can use the “fd” protocol:
# open FD 3 for writing to out.mp4
exec 3>out.mp4
# tell FFmpeg to mux to fd:3
ffmpeg -i input.mp4 \
-c:v libx264 -f mp4 fd:3 3>&1
Explanation:
exec 3>out.mp4
opens file out.mp4 as FD 3
-f mp4 fd:3
instructs FFmpeg to write the MP4-muxed output to FD 3
3>&1
makes FFmpeg inherit our FD 3 in its child process
You can of course pick any FD number (as long as it’s ≥ 0 and < 4096).
3. In the C API (libavformat)
If you’re embedding FFmpeg, you can wrap an existing FD in an AVIOContext:
int fd = /* your open()ed descriptor */;
uint8_t *buffer = av_malloc(32768);
AVIOContext* avio = avio_alloc_context(buffer, 32768,
/* write_flag= */ 1,
(void*)(intptr_t)fd,
NULL,
write_packet_cb,
NULL);
out_fmt_ctx->pb = avio;
You then implement write_packet_cb(void *opaque, uint8_t *buf, int buf_size) to just write(fd, buf, buf_size) or whatever custom transport you need.
Why you’d do this
• Piping into another process, network socket, or chrooted/jail environment
• Avoiding intermediate files on disk (stream directly to memory, TCP socket, STDOUT)
• Integrating with a parent process that already opened FDs (e.g. systemd socket activation)
• Special virtual “files” (FIFOs, /dev/fb0, etc.)
All in all, “pipe:” and “fd:” give you full power to shove FFmpeg’s output wherever you like without ever touching a real filename.