BIT-101
Bill Gates touched my MacBook Pro
A while back I created an app to allow myself to play a sequence of images as a video. I called it isv
for “Image Sequence Viewer”.
https://bit-101.com/blog/posts/2024-06-28/image-sequence-viewr-isv/
It was decent but it had issues so I kind of stopped using it. But I still have a need for the use case. I’m often rendering an animation as a long sequence of png frames and then creating a video from them using ffmpeg. I don’t want to have to wait until the whole thing is done before seeing how it’s coming along, so I go into the folder where the frames are being created and view the first one and use the arrow keys to scroll through them in a kind of janky animation.
This morning, on a whim, I decided to see if mpv
, the video player I use while developing animations, could play image sequences natively. Lo and behold! It can! The syntax is somewhat complex. It does this by merging the files into a video on the fly, so there are a few mf
or merge file commands. Found a workable solution on StackOverflow and adapted that into a shell script that you can pass in a directory path to.
#!/bin/sh
mpv mf://$1/*.png -mf-fps 30 --loop 2>/dev/null
Some explanation:
mf://
is the merge file path of the files to merge. There are several formats you can use here, but I’m just using the glob version. $1
is the first argument to the script, which should be the path to the frames. You can also pass a file containing a list of the frames, or a printf
type statement like image-%d.png
. The glob is simple and works.
-mf-fps
is the frame rate and --loop
makes the resulting animation play continuously. Quiet things down by sending any output to /dev/null
.
I put this in a script file called mpf
so I just need to say mpf out/frames
and I have a looping video playing with whatever frames have been rendered so far.
It doesn’t have all the bells and whistles that I tried to put in isv
, like bouncing forwards and backwards, or watching for new frames and playing them. Here I’d need to stop and run the script again to get new frames. But it works great and is very simple. Maybe I’ll see if I can get some kind of polling going, but I assume that’s going to mean stopping the video and restarting it. Not quite as seemless as isv
was on that front. On the other hand, this winds up being an actual video that I can resize, even full screen, which I couldn’t do in isv
and I can still stop, start, go back and forth frame by frame, etc.
For a one line script… not bad.
Comments? Best way to shout at me is on Mastodon