I’ve been playing around a lot with video conversion lately and one of the tools I use often is the Swiss armyknife for video manipulation ‘[ffmpeg](<http://ffmpeg.mplayerhq.hu/>)‘. It does format conversion (MPEG1/2/4, Quicktime, AVI …) , rescaling, recompressing, frame rate conversion … almost everything. It exists for all flavours of Linux/Unix, and also for [Windows](<http://www.videohelp.com/tools/ffmpeg>).

To give you an example: this is a script I wrote to extract screenshots of DVD files, straight from the disk.

**1\) the naive version**  
`ffmpeg -i [input file] -r .05 -y [output name]%%03d.png`  
This does indeed extract a PNG image every 20 seconds (framerate = 0.05), but it does not take into account that the DVD image material is stored anamorphically. What you get is this:  
[![V4Vendetta\_1\_720.012](<http://farm3.static.flickr.com/2410/2251354130_3c70d04cdf_m.jpg>)](<http://www.flickr.com/photos/pforret/2251354130/> "V4Vendetta_1_720.012 by PeterForret, on Flickr")  
Natalie Portman looks really thin, but that’s because the image dimensions (720×576 pixels – PAL standard) are for 5:4 aspect ratio, and whereas the actual image should be 16:9. So let’s make the image wider while keeping it the same height.

**2\) Rescale to 16:9**  
`ffmpeg -i [input file] -r .05 -s 1024x576 -y [output name]%%03d.png`  
The result looks better:  
[![V4Vendetta\_1\_1024.012](<http://farm3.static.flickr.com/2125/2251353732_f0d3c9c74f_m.jpg>)](<http://www.flickr.com/photos/pforret/2251353732/> "V4Vendetta_1_1024.012 by PeterForret, on Flickr")

As you see, there are still black borders on the top and bottom. This is because a feature film is made in ‘scope’ format, with an aspect ratio of 2.39 instead of 1.78 (the decimal equivalent of 16/9). So, while the full width of the image is used, only 428 pixels of the height are actually in use. Let’s crop those black borders off.

**3\) Crop black borders away**  
`ffmpeg -i [input file] -r .05 -croptop 74 -cropbottom 74 -s 1024x428 -y [output name]%%03d.png`

[![V for Vendetta: cropped](<http://farm3.static.flickr.com/2159/2250661505_42377134ee.jpg>)](<http://www.flickr.com/photos/pforret/2250661505/> "V for Vendetta: cropped by PeterForret, on Flickr")

**4\) old 4:3 movies**  
The older movies used a 4:3 aspect ratio, so when you extract them as 16:9 they look like a weight fell on them:  
[![MammaRoma\_1024](<http://farm3.static.flickr.com/2142/2250556757_9a5cdf6576_m.jpg>)](<http://www.flickr.com/photos/pforret/2250556757/> "MammaRoma_1024 by PeterForret, on Flickr")  
In those cases, you can use the ‘naive’ version above, which will give you:  
[![MammaRoma\_720](<http://farm3.static.flickr.com/2149/2250556101_cc7d436950_m.jpg>)](<http://www.flickr.com/photos/pforret/2250556101/> "MammaRoma_720 by PeterForret, on Flickr")

Here also, the actual 4:3 image is ‘letterboxed’ to the 5:4 DVD image.

Why did I need to figure this out? Well, guess what movie is running on my LCD photo frame:

[![Lucia y el sexo](<http://farm3.static.flickr.com/2028/2250618987_04117271a2.jpg>)](<http://www.flickr.com/photos/pforret/2250618987/> "Lucia y el sexo by PeterForret, on Flickr")

#### Windows batch script

For those who like a ready-made script (for Windows machines), here it goes:

```
set FFMPEG=<path>/ffmpeg.exe
set SOURCE=e:\video_ts
set TITLE=[movie name]
set DESTIN=%CD%

pushd %SOURCE%
for %%F in (*.VOB) do (
call :vob2img %%F
)
popd
goto :end
:vob2img
set FNAME=%1
set NAME=%FNAME:.VOB=%
set NAME=%NAME:VTS_=%
set NAME=%NAME:01_=%
set NAME=%NAME:_TS=%
set NAME=%NAME:VIDEO=%
set ROOT=%TITLE%_%NAME%
"%FFMPEG%" -i %FNAME% -r .05 -croptop 74 -cropbottom 74 -s 1024x428 -y %DESTIN%%ROOT%.%%03d.png
:end
```

Which will give, for a 90 minute movie, 270 images called like `V4Vendetta_1.NNN.png`.
