Give input to ffmpeg using named pipes

11,027

Solution 1

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.

Solution 2

You could use the *-loop_input* command-line option:

ffmpeg -loop_input -re -timestamp now -f image2 -r 25 -sameq -i input.jpg -an -vcodec mpeg2video out.mp4

In your case, replace input.jpg with the pipe. Then, FFmpeg will create a new frame every 1/25 seconds from the input file (or pipe).

Share:
11,027
Akilan
Author by

Akilan

Updated on June 04, 2022

Comments

  • Akilan
    Akilan about 2 years

    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.

  • Akilan
    Akilan about 13 years
    Well, I solved the problem in a way that sort of resembles above. I used openCV to output an MJPEG stream into the named pipe and then using ffmpeg to encode from it. I thought MJPEG encoding done internally by openCV shouldn't take much CPU since its just continuous jpeg image stream. :-) BTW, my images are in RGB bitmaps.