Brett Code


Movie to Images

As a one-liner:

C:\alpha\ffmpeg\bin\ffmpeg.exe -i C:\alpha\input\test.mp4 -r 10 C:\alpha\output\test_%04d.png

The same thing, broken up into multiple lines for ease of visual comprehension (note the trailing `):
C:\alpha\ffmpeg\bin\ffmpeg.exe `
-i C:\alpha\input\test.mp4 `
-r 10 `

Finally, as a multi-line string, subsequently invoked:
$c = @'
C:\alpha\ffmpeg\bin\ffmpeg.exe `
-i C:\alpha\input\test.mp4 `
-r 10 `

Invoke-Expression $c

All of these snippets work on the PowerShell Command Line. I have no idea how they need to be tweaked in order to be included in scripts. Though, I am inclined to believe I would simply use the one-liner and be done with it.

ffmpeg spits out all sorts of data while in operation, so I found things out about my test movie (test.mp4) that I was not aware of before:
Duration: 00:00:05.27
Start: 0.000000
Bitrate: 17246 kb/s
29.83 fps
The output contained 55 images, test.mp4 is 5.27 seconds long, and the -r 10 switch requests 10 images to be saved per second, so I am assuming the leading and trailing frame are saved, as well ( 1 + 53 + 1 = 55).

Also (something which I find quite interesting and indicates how well ffmpeg is programmed), if the output file designation is changed from test_%04d.png to test.gif an animated GIF is outputed. Hot Dog!

The Raw Command

The basic syntax is:
ffmpeg input [switches] output
So, in my examples:
Additional switches (as I understand and which seem like they might be useful in the future) include:
Unfortunately, neither -fs 100 (controls the file size in kilobytes) nor -b:v 512k (controls the bit rate) had any effect. These switches may only work for streaming video... or if the output is another video. I really would have liked -fs to work.

In the end, I did try the -fs switch, while outputing to another movie; and it worked:

C:\alpha\ffmpeg\bin\ffmpeg.exe -i C:\alpha\input\test.mp4 -fs 1000 C:\alpha\output\test_1000.mp4

But I have no confidence -fs 1000 did what I intended. After all, I would have expected the output movie to have a FileSize of 1MB. But instead, it was 1.47MB. And rather than the full 5.26 seconds of video, the output was only 2 seconds long. Obviously, something had been clipped.

As such (and in the future), I'm far more likely to do manual edits (with some sort of GUI Video Editing Program or by deleting any images I don't want after sequencing them) than to do any sort of scene restructuring directly in ffmpeg.

However (I will note), the size switch (-s 192x108) did exactly what I expected and resized the movie perfectly:

C:\alpha\ffmpeg\bin\ffmpeg.exe -i C:\alpha\input\test.mp4 -s 192x108 C:\alpha\output\test_%04d.mp4

I would have liked to end this write-up by doing a simple round trip and convert the images back into a movie. But it's not that simple, as I have to tell ffmpeg certain things about the movie (like frame rate, if nothing else) that have been lost in the conversion to PNGs. So, it's not a simple one-liner (or two one-liners for the round-trip) and will have to wait for another day and it's own write-up.

After all, even something as short and direct as what I have done here takes a fair amount of time... well, for me, anyhow.

command line image manipulations

© copyright 2019 Brett Paufler