I have a 4D numpy array of movie frames. I'm looking for a function to write them to a movie, at a given framerate. I have FFMPEG installed on my OS, and as I can see from these answers, the most efficient way to do so is via pipes.
However, I have very little experience using pipes, and the explanations in the link above make little sense to me. Furthermore, very few of the answers seem actually implement pipes, and the one that does uses mencoder, not FFMPEG. I am relatively inexperienced with FFMPEG, so am not sure how to modify the command string from the mencoder answer to make it work in FFMPEG.
WHAT I WOULD LIKE:
A function of the following form:
animate_np_array(4d_array, framerate) -> output.mp4 (or other video codec)
Which implements pipes to send frames one after the other to FFMPEG, and which I can copy-paste into my existing code.
Furthermore, it is absolutely necessary that this function never actually plots any of the frames, as calls to the matplotlib.imshow() function (as I have most typically seen used) slow things down considerably.
The ImageIO API offers a dead simple way to do this:
import imageio
imageio.mimwrite('output_filename.mp4', np_array , fps = [an int])
While I'm not sure if this uses pipes or not, it's blazingly fast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With