This is an old revision of the document!


To do a clean MPG copy from a DVD:

dvd_copy -o - | ffmpeg -i - -map 0:v -map 0:a -c:v copy -c:a copy -f vob dvd_copy.mpg 

Or into Matroska:

dvd_copy -o - | ffmpeg -fflags +genpts -i - -codec copy dvd_copy.mkv 

Adding Chapters

Create a file with the metadata. This example here has chapters at each minute mark.


Use the file as input with the encode, and map the metadata:

ffmpeg -i video.mpg -i chapters.txt -map_metadata 1 video.mkv

archives: Wrong audio track by default

Note: This is a bug I would run into after extracting a VOB from a DVD, and running ffmpeg -i movie.vob

ffmpeg lists the audio tracks in reverse order *in some cases*, so be sure to map the right one. See order of 0x8x below for an example.

You can see the streams by ffmpeg output that it is reading and writing to:

    Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x480 [PAR 32:27 DAR 16:9], 9800 kb/s, 59.94 tb(r)
    Stream #0.1[0x85]: Audio: ac3, 48000 Hz, 5.0, s16, 448 kb/s
    Stream #0.2[0x84]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
    Stream #0.3[0x83]: Audio: ac3, 48000 Hz, quad, s16, 448 kb/s
    Stream #0.4[0x82]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
    Stream #0.5[0x81]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    Stream #0.6[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
Output #0, avi, to 'movie.avi':
    Stream #0.0: Video: mpeg4, yuv420p, 720x480 [PAR 32:27 DAR 16:9], q=2-31, 200 kb/s, 59.94 tb(c)
    Stream #0.1: Audio: mp2, 48000 Hz, stereo, s16, 192 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.6 -> #0.1 [sync #0.1]

If you map any of them, you need to map all of them (both audio and video).

ffmpeg -i movie.vob -map 0.0:0.0 -map 0.6:0.1

archives: From Letterbox to Anamorphic Widescreen

ffmpeg -i movie.vob -acodec copy \
	-croptop 60 -cropbottom 60 \
	-s 720x480 -aspect 16:9 -deinterlace \
	-vcodec libx264 -vpre hq -crf 12 -threads 0 \

The original source of DVDs is a 720×480 picture. The height is stretched to 540 pixels (480 x 1.125 = 540) to display it, so that the aspect ratio is 4:3 (720/540 = 1.33333).

What I want to do is both crop the black and bottom bars, but also keep the new size the same as the original one … just so that the new specs mirror exactly what a widescreen DVD would be (instead of having arbitrary heights/widths).

Since the original size is a height of 480 pixels, *that* is the number to use when counting how many pixels to crop. *Do not* count it from the display size (540). That's why I'm cropping by 60 on top and bottom (verified with GIMP).

If you look at a “normal” widescreen movie that doesn't have black bars at the top and bottom, you'll see that source material is the same size: 720×480. The aspect ratio, though, is 16:9, so the display is stretched to 854×480 – in this case, it's the width that is stretched instead of the height (480 x 16/9 = 853.333).

Last but not least, the MPEG2 codec can store the display aspect ratio inside the header data, which is why you tell ffmpeg that the new one is 16:9.

If you looked at a widescreen and a fullscreen video, the original display size is actually the same: 720×480. They are just stretched differently based on the aspect ratio.

archives: Convert image to video

ffmpeg -i snapshot.jpg -sameq -s 720x480 video.mp4

That will create a one frame video. Then I copy it to about 200 frames to make a 6 second video.

Avidemux has problems opening a single frame file, so create a long MP4 before trying to create a VOB to burn to DVD.

archives: PSP Format w/ffmpeg

Finally found a working solution:

ffmpeg -y -i 101._The_Force_Phantom.mkv -s 320x240 -ar 24000 -r 29.97 -f psp -title "The Force Phantom" M4V12345.MP4

You *can* encode to 480×272 (or 270) and it will playback fine, but for some reason the title tag won't be read anymore. Seems to be a PSP bug, since a video I downloaded (SWTFU stuff) also won't display it.

Also, MV1234.MP4 is the old supported format. My PSP (firmware >5) supports “movie.mp4” naming scheme, as well as folder structures just fine!