I have a game which can create some screenshots, and I want to transform them to mp4 video. So I've the next command:
ffmpeg -framerate 15 -i %06d.png -s hd1080 -vcodec libx264 -r 30 timelapse.mp4
But my game lasts 8h, so, after have auto-compress pictures, I've more than 9To of pictures. So I want to start the ffmpeg process before the end of pictures generation, so I want that ffmpeg wait the next picture to digest it.
How can I do it?
If you don't need the video absolutely immediately after the game, try batch processing.
Create videos periodically, maybe every 5 to 30 minutes, using your fresh pictures. Then combine all of the videos when ready. Concatenating a bunch of videos of the same format without recenocding in ffmpeg is very fast.
This answer has a great overview of the methods for combining videos in ffmpeg.
In your case, you can append the output file names into a text file as each video clip is created. For example, vidlist.txt
:
file '/path/to/clip1.mp4'
file '/path/to/clip2.mp4'
file '/path/to/clip3.mp4'
Then use the command:
ffmpeg -f concat -safe 0 -i vidlist.txt -c copy output.mp4
One disadvantage is that you effectively double your disk space usage while creating the final video. You are still able to delete all clips immediately after combining, ultimately using the same amount of space. Alternatively, you could concatenate each video clip onto the main clip as you go, instead of waiting until the end. No additional space would be needed.
You may also be able to pipe images to ffmpeg with a script that feeds occasional input for 8 hours. But depending on how quickly after the game you need the video (likely seconds for a piped script script versus a minute or so for batched), batch processing and combining may be a simpler solution.
If this is running on the same hardware as the game, a constant script approach may still be better as the cpu usage should remain lower than the peaks created by batch processing every few minutes, although this can be mitigated somewhat by restricting threads for ffmpeg.