Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give input to ffmpeg using named pipes

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.

like image 621
Akilan Avatar asked Apr 06 '11 19:04

Akilan


2 Answers

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.

like image 105
Serafeim Avatar answered Oct 19 '22 18:10

Serafeim


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).

like image 31
kshahar Avatar answered Oct 19 '22 20:10

kshahar