Streaming with named pipe in linux

Streaming with named pipe in linux

ยท

1 min read

While working with ffmpeg recently, I needed a solution to stream multiple videos to an RTMP URL without repeatedly starting the command for each video. That's when I discovered the concept of named pipes in Linux, which provided a seamless way to continuously feed videos to ffmpeg for streaming.

Named pipe are just files in linux, which provides bi-directional communication. One process can write to this pipe and another process can listen to this pipe. It can be easily created using this command

 mkfifo video_pipe

It will create a pipe. You can see it just as a file on your system. Now if I want to send video to this pipe, I can just use cat. This will start writing video data to this pipe.

cat video.mp4 > video_pipe

Now, we need a process that is listening to this pipe. I used ffmpeg to listen to this pipe. FFmpeg will keep reading from this pipe and streaming it to rtmp URL. I can feed multiple videos to this pipe.

ffmpeg -re -i video_pipe -c copy -f flv your_rtmp_server_url