Entering data in ffmpeg using named pipes

I have a C program that generates a series of images, and I wanted to make them in video, which should be broadcast in real time or stored in a file. When reading the ffmpeg documentation, I repeatedly came across the fact that ffmpeg can receive data from named pipes.

My question is in what format the files transferred to the channel should be, and how to enter files into the channel.

+4
source share
3 answers

From what I know, there are no requirements for the format of the video that will be placed in the named pipe. You can put something that ffmpeg can open. For example, I developed a program using ffmpeg libraries that read h264 videos from a named pipe and extract statistics from it - the named pipe was filled with another program. This is really a very nice and clean solution for continuous video.

Now, regarding your case, I think that you have a small problem, since the named pipe is just one file, and ffmpeg will not be able to find out that there are several images in one file! Therefore, if you declare a named pipe as input, ffmpeg will believe that you have only one image - not good enough ...

One solution that I can think of is to declare that your named pipe contains video, so ffmpeg will constantly read and store it or transfer it. Of course, your C program would have to generate and record this video in a named pipe ... It's not as complicated as it sounds! You can convert your images (you didnโ€™t tell us what their format is) to YUV, and simply write one after another in a named pipe (YUV video is a series of YUV without captions), you can also easily convert from BPM to YUV, just check Wikipedia entry on YUV ). Then ffmpeg will think that the named pipe contains a simple YUV file so that you can finally read it and do whatever you want with it.

+3
source

You can use the command line parameter * -loop_input *:

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 handset. Then FFmpeg will create a new frame every 1/25 of a second from the input file (or channel).

+2
source

Use image2 with wildcard file names, assuming these images exist as files from ffmpeg documents:

 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); 
-1
source

Source: https://habr.com/ru/post/1346964/


All Articles