Give input to ffmpeg using named pipes

Akilan picture Akilan · Apr 6, 2011 · Viewed 10.2k times · Source

I have a C program which generates a series of images and I wanted to make them into a video which should be streamed in real time or stored in a file. While reading up ffmpeg documentation I came across repeatedly that ffmpeg can take input from named pipes.

My question is in what format should the files given into the pipe should be and how to input the files into the pipe.

Answer

Serafeim picture Serafeim · May 7, 2011

From what I know, there aren't any requirements on the format of the video that will be put to the named pipe. You could put anything ffmpeg can open. For instance, I had developend a program using ffmpeg libraries that was reading an h264 video from a named pipe and retrieved statistics from it - the named pipe was filled through another program. This is really a very nice and clean solution for continous video.

Now, concerning your case, I believe that you have a small problem, since the named pipe is just one file and ffmpeg won't be able to know that there are multiple images in the same file! So if you declare the named pipe as input, ffmpeg will believe that you have only one image - not good enough ...

One solution I can think of is to declare that your named pipe contains a video - so ffmpeg will continously read from it and store it or stream it. Of course your C program would need generate and write that video to the named pipe... This isn't as hard as it seems! You could convert your images (you haven't told us what is their format) to YUV and simply write one after the other in the named pipe (a YUV video is a headerless series of YUV images - also you can easily convert from BPM to YUV, just check the wikipedia entry on YUV). Then ffmpeg will think that the named pipe contains a simple YUV file so you can finally read from it and do whatever you want with that.