If you feel like this example could be improved, you may edit this example here.
When writing a simulation or similar application, you may sometimes want to record a video of something, with your program generating individual frames and ffmpeg assembling them into a whole. It’s possible to do so in two steps - write the frames as PNG files and then pass them as input to ffmpeg - but this is very slow (as it requires to PNG encode, write, read, and PNG decode each frame) and requires a lot of space to store all the frames. It’s much more efficient to use -i pipe: to provide the raw frames as they are generated.
To use, run an ffmpeg instance using the command, and write the raw frames (RGBA, 4 bytes per pixel, 1280 width by 720 height) into its stdin. Once you’re done, close the pipe to the stdin and the ffmpeg process will exit shortly.
The result is written into output_path.mp4, and no output is shown unless there’s an error.