Log in

View Full Version : Low resolution/bitrate DVD compliant MPEG2 with Mencoder


em500
5th April 2008, 12:19
The goal: (PAL) DVD compliant low resolution (D4 or 352x288) MPEG2
The tool: mencoder

I regularly encode a bunch of medium quality (resolution between VCD and DVD) inputs in various formats that mencoder understands (mostly RV10). I want them to convert them into standard DVDs, where fitting more hours on a disc ranks higher than getting best quality (which is why I'm downsizing to 352x288 rather than upsizing to 720x576). But of course I still want the best quality within these constraints. :) And I'd really like to do it all in mencoder without installing any other tools if at all possible. But mencoder has tons of options that are pretty confusing for amateurs.

What I've used so far is mainly based on mencoder documentation (http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html). I've also seen Sagittaire's batch files (http://forum.doom9.org/showthread.php?t=117655), but I don't really understand some of the advanced options. This is what I use now.


1st pass:

mencoder -oac lavc -ovc lavc (use lavc for everything)
-ofps 25 -of -mpeg -mpegopts format=dvd:tsaf (I want to make PAL DVDs)
-vf scale=352:288,harddup (VCD resolution is ok for me)
-srate 48000 -af lavcresample=48000 (resample audio to DVD rate)
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:me_range=128:keyint=15:vstrict=0 (options for DVD compliance)
:trell:mbd=2: precmp=2:subcmp=2:cmp=2:dia=-10: predia=-10:cbp:mv0:vqmin=1:lmin=1:dc=10 (quality enhancement according to mencoder docs)
:aspect=4/3 (probably redundant but harmless)
:vrc_maxrate=1800:vbitrate=1050 (VCD-like quality, fits about 9 hours on a DVD-5)
:vpass=1:turbo (first pass)
:acodec=ac3:abitrate=128 (low bitrate ac3 for audio, which is mainly dialog)
-o output.mpg input.rmvb (in and output names)

2nd pass command is the same, but with "vpass=1:turbo" replaced by "vpass=2"

This has worked pretty well for me, but I'm looking for improvements if possible. I haven't done anything with the more advanced options from Sagittaire, like B-frames or custom matrices, as I don't understand most of them, and the batch file seems more geared towards higher quality encodes. So I'm posting this to see if anyone can give me tips to improve on what I'm using now.

BTW, I think audio encoding in the first pass is superfluous, but mencoder complains if I left them out IIRC.

unixfs
13th April 2008, 18:20
there are a lot of mistakes in your command line:
- dc=10 is forbidden in dvd. leave the setting at the default dc=8
- vf scale=352:288 will distort your video. Use -vf scale=352:-10,expand=352:288
- all those :*cmp=2 will probably introduce blocks. Better leave
the default ME methods (*cmp=0 that are also faster)
- using a longer gop such as 25 or 30 will only do good :)
- vrc_maxrate=1800 is a bit low, IMO. Better use something
larger for a better looking encode
- if you want 2 bframes add :vmax_b_frames=2, but I always
dislike the final output

45tripp
13th April 2008, 20:25
-of -mpeg

i'm guessing a typo,
as it shouldn;t run like that



:aspect=4/3 (probably redundant but harmless)


it's certainly not redundant!!


- dc=10 is forbidden in dvd. leave the setting at the default dc=8


it's not forbidden.
but i'd stick to 8 too

- vf scale=352:288 will distort your video. Use -vf scale=352:-10,expand=352:288

that way will certainly distort.
at least his option has chances of being right.

otherwise i agree with you,
but i am partial to 1 bframe

scharfis_brain
13th April 2008, 21:00
dvd only allows GOPs of 15 frames length for PAL. AFAIK

unixfs
13th April 2008, 23:38
that way will certainly distort.
at least his option has chances of being right.


no you are wrong. -vf scale=352:288 will scale
unconditionally without keeping into account the
aspect ratio of the original movie (think how nice
will look a 2.35 movie rescaled to ~4/3) while
-vf scale=352:-10,expand=352:288 will preserve
the A/R and add borders to stay within a frame
size accepted by dvds. True is that the 352->384
rescale implied by :aspect=4/3 should be considered, too,
but that will surely introduce a much lesser distortion
than a brute and blind rescale to 352:288.
Try it with mplayer and see yourself

45tripp
14th April 2008, 00:10
True is that the 352->384
rescale implied by :aspect=4/3 should be considered, too,


exactly

edit:
you can force it like so if you like:
-vf scale=384:-10,scale=352:-1,expand=352:288
i think it's better to just calculate right in the first place, manually


dvd only allows GOPs of 15 frames length for PAL. AFAIK

it'll play.
and compression will be better.

strict compliance is boring :)

em500
16th April 2008, 16:31
Thanks for the input guys. I'm still pretty new to this, and was proud enough that things seemed to be mostly working. Haven't seen any obvious distortions yet, because all my input has been 4:3 so far.

Any thoughts on low-bitrate optimized matrices?

em500
16th April 2008, 16:34
i'm guessing a typo,
as it shouldn;t run like that

Yes, that should be "-of mpeg".

em500
16th April 2008, 16:39
- dc=10 is forbidden in dvd. leave the setting at the default dc=8
- all those :*cmp=2 will probably introduce blocks. Better leave
the default ME methods (*cmp=0 that are also faster)

I got those from
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
But maybe they don't work so well for low bitrates/resolution?

- if you want 2 bframes add :vmax_b_frames=2, but I always
dislike the final output
So why should I add them then? Or should the output be better in theory?

45tripp
20th April 2008, 15:33
Any thoughts on low-bitrate optimized matrices?

i don't like using them.
you can get a comparison on some:
http://forum.doom9.org/showthread.php?s=&threadid=76021
really for xvid encoding though.

and you can check the matrices included in HCenc.

or further search it yourself.
i think manono got into some specifics lately around here.

I got those from
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
But maybe they don't work so well for low bitrates/resolution?

you'll tend to get blocks on fast action.
try *cmp 1 or 3.
of course if you're happy, leave it as is.


So why should I add them then? Or should the output be better in theory?

in theory and practice.
many dislike b frames in fast action.
again you'll have to try and see.