Akilan
Akilan

Reputation: 279

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.

Upvotes: 6

Views: 13133

Answers (3)

Justin Buser
Justin Buser

Reputation: 2871

Use image2 with wildcard filenames, assuming these images exist as files, from the ffmpeg docs:

for creating a video from the images in the file sequence ‘img-001.jpeg’, ‘img-002.jpeg’, ..., assuming an input frame rate of 10 frames per second:

ffmpeg -i 'img-%03d.jpeg' -r 10 out.mkv

i.e.

AVFormatContext *pFormatCtx = avformat_alloc_context();
avformat_open_input(&pFormatCtx,"img-%03d.jpeg",NULL,NULL);

Upvotes: -2

kshahar
kshahar

Reputation: 10513

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

Upvotes: 4

Serafeim
Serafeim

Reputation: 15104

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.

Upvotes: 7

Related Questions