MEncoder/DivX to DVD
From Gentoo Linux Wiki
Contents |
[edit] Intro
This is meant as a supplement to HOWTO Create a DVD, which gives a simple example for transcoding from one video format to a dvd compatible format using mplayer's mencoder. This page serves to repeat that example and give other more complete examples.
[edit] QuickStart
- NTSC
- Widescreen
mencoder -of mpeg -mpegopts format=dvd -srate 48000 -ofps 30000/1001\ -ovc lavc -oac lavc -lavcopts \ vcodec=mpeg2video:\ vrc_buf_size=1835:\ keyint=18:\ vrc_maxrate=9800:\ vbitrate=4900:\ aspect=16/9:\ acodec=ac3:abitrate=192 \ ~/Videos/path/to/file-divx.avi -o ~/Videos/path/to/file-divx.mpeg2
- Fullscreen
mencoder -of mpeg -mpegopts format=dvd -srate 48000 -ofps 30000/1001\ -ovc lavc -oac lavc -lavcopts \ vcodec=mpeg2video:\ vrc_buf_size=1835:\ keyint=18:\ vrc_maxrate=9800:\ vbitrate=4900:\ aspect=4/3:\ acodec=ac3:abitrate=192 \ ~/Videos/path/to/file-divx.avi -o ~/Videos/path/to/file-divx.mpeg2
- PAL
- Widescreen
mencoder -of mpeg -mpegopts format=dvd -srate 48000 -ofps 25 \ -ovc lavc -oac lavc -lavcopts vcodec=mpeg2video:\ vrc_buf_size=1835:\ keyint=15:\ vrc_maxrate=9800:\ vbitrate=4900:\ aspect=16/9:\ acodec=ac3:abitrate=192 \ ~/Videos/path/to/file-divx.avi -o ~/Videos/path/to/file-divx.mpeg2
- Fullscreen
mencoder -of mpeg -mpegopts format=dvd -srate 48000 -ofps 25 \ -ovc lavc -oac lavc -lavcopts vcodec=mpeg2video:\ vrc_buf_size=1835:\ keyint=15:\ vrc_maxrate=9800:\ vbitrate=4900:\ aspect=4/3:\ acodec=ac3:abitrate=192 \ ~/Videos/path/to/file-divx.avi -o ~/Videos/path/to/file-divx.mpeg2
[edit] Using MEncoder
Note #1: you need to compile mplayer with the encode USE flag enabled.
Note #2: for more details, see here.
mencoder -of mpeg -mpegopts format=dvd -srate 48000 -ofps <fps> -ovc lavc -oac lavc -lavcopts \ vcodec=mpeg2video:vrc_buf_size=1835:keyint=<gop>:vrc_maxrate=9800:vbitrate=<vbitrate>:aspect=<ar>:\ acodec=ac3:abitrate=192 \ -vf crop=<crop>,scale=<scale>,expand=<expand> \ <inputfile> -o <outputfile>
MEncoder general options:
- -of mpeg: encodes to the MPEG container format instead of AVI
- -mpegopts format=dvd: uses DVD-compatible MPEG format
- -srate 48000: selects the correct output sample rate to be used (48000Hz)
- -ofps <fps>: specifies a frames per second (fps) value for the output file (25 for PAL DVD, 30000/1001 for NTSC DVD)
- -ovc lavc: uses libavcodec for encoding the video
- -oac lavc: uses libavcodec for encoding the audio
libavcodec options:
- -lavcopts: libavcodec options must be specified after this
- vcodec=mpeg2video: employes MPEG-2 video codec
- vrc_buf_size=1835: specifies the correct buffer size (1835kbit)
- vrc_maxrate=9800: specifies the correct maximum bitrate (9800kbit/s)
- keyint=<gop>: sets the maximum interval between keyframes in frames (15 for PAL DVD, 18 for NTSC DVD)
- vbitrate=<vbitrate>: specifies the video bitrate in kbit/s (any value up to 9800)
- aspect=<ar>: specifies movie aspect (either 4/3 or 16/9)
- acodec=ac3: employes AC3 audio codec
- abitrate=192: specifies the audio bitrate (192kbit/s)
video filters options:
- -vf: video filters options must be specified after this
- crop=<crop>: crops the given part of the image and discards the rest (see later for details)
- scale=<scale>: scales the image to the correct value (see later for details)
- expand=<expand>: expands (not scales) movie resolution to the given value (720:576 for PAL DVD, 640:480 for NTSC DVD)
- harddup: "In order to maintain audio/video synchronization throughout the encode, MEncoder has to drop or duplicate frames. This works rather well when muxing into an AVI file, but is almost guaranteed to fail to maintain A/V sync with other muxers such as MPEG. This is why it is necessary to append the harddup video filter at the end of the filter chain to avoid this kind of problem."
input and output files:
- <inputfile>: specifies the input file
- -o <outputfile>: outputs to the given filename
[edit] Determine the crop value
In order to determine the <crop> value, you can use the following command:
| Code: $ mplayer -vf cropdetect <inputfile> |
... crop area: X: 4..715 Y: 56..419 (-vf crop=704:352:8:62)% 0.8% 0 0 49% ... |
In this case, the <crop> value is: 704:352:8:62.
The following command is for verifying its correctness:
$ mplayer -vf rectangle=<crop> <inputfile>
[edit] Determine the scale value
To determine the <scale> value, you need to know:
- the <crop> value (see the previous paragraph)
- either PAL or NTSC resolution (respectively 720x576 and 720x480)
- your desider aspect ratio (either 4/3 or 16/9; must match the value you previously assigned to the aspect=<ar> option)
The general formulae for the <scale> value is:
xscale = xres yscale = (yres*ar*ycrop)/xcrop
Example (PAL DVD, 4/3):
- if <crop> value is 704:352:8:62, then xcrop=704 and ycrop=352
- PAL DVD resolution is 720x576, so xres=720 and yres=576
So your <scale> value is: 720:(576*(4/3)*352)/704 = 720:384
[edit] VOBU/NAV
While the method above would give you a stream that would play on your DVD player, you may not be able to seek/search, because the output will not have NAV packets. You can add them by splitting the video from the audio and running them through mplex, from mjpegtools.
(Are these NAV packets real? Perhaps the problem is a lack of chapter points in the dvdauthor xml file?) I find that demux with 'ProjectX -demux' and mux with 'mplex -f 8' does however help with A/V sync.
