I'm not sure if this is something expected and obvious, or weird and unusual - but given that I do a lot of batch operations and speed is an important factor to me, I thought I might at least try to find out why it happens, so that I'm better at coming up with faster solutions in the future. Please bear with me.
Here's some context:
I'm working on a tool that allows you to crop a video, but instead of showing the same section of the original video, the crop "moves" - taking a static video and generating something like a close-up shot of a subject.
In order to do so, I have the tool extract each frame of a video with FFMPEG as a BMP, crop a specific section of each frame individually, then stitch it back together into a video.
The thing is, since each crop command has different coordinates, I can't just do a batch mogrify using *.bmp - that would give me a static crop of a single region of the original video. The solution I found is to have my tool generate and run a batch file with one crop command for each frame, like this:
Code: Select all
magick mogrify -path cropped/ -crop 1920x1080+0+0 frame000.bmp magick mogrify -path cropped/ -crop 1920x1080+0+1 frame001.bmp magick mogrify -path cropped/ -crop 1920x1080+0+2 frame002.bmp magick mogrify -path cropped/ -crop 1920x1080+0+3 frame003.bmp magick mogrify -path cropped/ -crop 1920x1080+0+4 frame004.bmp magick mogrify -path cropped/ -crop 1920x1080+0+5 frame005.bmp magick mogrify -path cropped/ -crop 1920x1080+0+6 frame006.bmp magick mogrify -path cropped/ -crop 1920x1080+0+7 frame007.bmp magick mogrify -path cropped/ -crop 1920x1080+0+8 frame008.bmp magick mogrify -path cropped/ -crop 1920x1080+0+9 frame009.bmp magick mogrify -path cropped/ -crop 1920x1080+0+10 frame010.bmp
It takes about 19s to do the mogrify crop of each frame individually, using the method above. For comparison, a single batch mogrify on all 150 frames takes slightly less - about 16 seconds. It's a small difference, and one that makes sense to me.
But if I divide the 150 frames into 5 batch files with the individual crop instructions for 30 frames each, and run them all at the same time, I can process them all in under 8 seconds!
What I would like to know is: Why does this happen? Is there something silly I'm doing or failing to do? Maybe something to do with multithreading? Is it normal to be able to get much better speeds by running a few instances of the command prompt and processing multiple images at the same time? Am I going mad and probably measuring it wrong somehow? Should I just divide stuff up like this every time I do a batch operation to get faster speeds?
As you can see, I am very confused, hehe. Any insight is appreciated. Thanks!