0

Good morning, I have a script that generates 2 images every second in a folder and I want ffmpeg to convert them into a series of mpeg-4 videos of 5 secs duration and that shows 2 images per second (10 frames total). Problem is that after I start the script and after I run ffmpeg, it processes the videos with the images it catches right after I run the command only and then it closes. I tried with the -re command also and nothing happens. How do I keep ffmpeg running and live converting the images while they're being generated? Here's the code I'm using :

ffmpeg -re -framerate 2 -s 1920x1200 -i C:\Desktop\input\%05d.bmp -vcodec libx264 -pix_fmt yuv420p -map 0 -segment_time 5 -g 5 -sc_threshold 0 -force_key_frames "expr:gte(t,n_forced*5)" -f segment C:\Desktop\output\%05d.mp4

All I want is to execute ffmpeg one time and let it work and close only when they're finished generating.

1

Pipe the images. When reading images from files, ffmpeg will identify the last image in the sequence during initialisation and will read till that image.

cat images | ffmpeg -f image2pipe -re -framerate 2 -i - -vcodec libx264 ...

Edit: Not surprisingly cat also sets the input roster at initialisation. However, the method below works for me.

Have the script append the new images to a blob file

i.e. cat new-image >> all-images

while ffmpeg call is

ffmpeg -f image2pipe -re -framerate 2 -i all-images -vcodec libx264 ...

It is very important that your new image generation and appendation speed is equal to or faster than ffmpeg's read speed.

  • I have Windows, cat won't work. I tried with type but it doesn't work either. – Vincent Bavaro Nov 14 '18 at 10:36
  • Get gow and you'll have cat. – Gyan Nov 14 '18 at 10:58
  • got gow, it gives me this error : C:\Desktop\input\%05d.bmp: No such file or directory – Vincent Bavaro Nov 14 '18 at 11:18
  • cat *.bmp works here. – Gyan Nov 14 '18 at 11:22
  • it gives me the same error. Maybe I modified my command in a wrong way? Basically now it goes like : cat *.bmp | ffmpeg -f image2pipe -re -framerate 2 -s 1920x1200 -i C:\Desktop\input\%05d.bmp... – Vincent Bavaro Nov 14 '18 at 11:28
0

To keep ffmpeg getting added new images, it will need to get them from stdin. You will need to write a program or script that will keep feeding it new images as they arrive.

For examples see:

These programs will need some changes to fit them to your needs, but they are a good starting point.

  • I will try them but I would've liked a built-in ffmpeg solution for it cause adding files to the stdin would slow down the process. I thought the -re command should've worked like that? – Vincent Bavaro Nov 14 '18 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.