Log in

View Full Version : DVD encoding with Mencoder


bilu
3rd March 2004, 13:08
Hi,

UPDATE: http://forum.doom9.org/showthread.php?s=&postid=457065#post457065

Me and other guys at KVCD.net have been working on using Mencoder for DVD encoding.

Current Status
===============
Official Mencoder port for Windows:
http://www.mplayerhq.hu/MPlayer/releases/win32-beta/mplayer-mingw32-1.0pre3.zip

Direct CVS encode by VMesquita(February 29th):
http://www.jltoca.uaivip.com.br/files/mencoder-29-2-2004.zip

A great tutorial by my neighbour rds_correia ;) :
http://kvcd.net/forum/viewtopic.php?t=9300

It's now possible to use Mencoder to do DVD-compliant encodes (respecting max bitrate, VBV)and supporting interlaced/telecined sources. You need the CVS build to support interlaced sources.

EDIT: Also possible to use Avisynth sources.

A small bug in that CVS build: you have to set vstrict=-1 to support fractional framerates like 29.97 or 23.976 fps, despite the docs say it should be vstrict=0. Doesn't happen with the official build.

Also the man page in the CVS build is not correctly converted: the parameters got replaced by "s" during conversion :D
Use the one specified in the tutorial and also have a look at this post for some settings exclusively in the CVS build:

http://kvcd.net/forum/viewtopic.php?p=65125#65125

And here an example of a DVD compliant encode using a settings file:

http://kvcd.net/forum/viewtopic.php?p=65732#65732

Now I'll be investigating the quality parameters, which are about the same used for MPEG-4 encodes. Hope you enjoy Mencoder for MPEG-2 and contribute with some feedback :)


Cheers,
Bilu

rds_correia
3rd March 2004, 13:21
Hi bilu,
Great idea posting here at doom9 too :)
Maybe one of the guys here have some idead to help us with mencoder.
Cheers

Asmodeus
3rd March 2004, 14:06
HI Bilu and Rui :)
We'll see. For helpful ideas - make posts bellow :D

unixfs
4th March 2004, 10:01
Hi,
In all the encodes I made I noticed:
- the usual blacker than black problem, the most annoying of all
- a lot of mosquito around faces whenever you resize
- blockiness in the passage from near-still to high motion scenes
(other motion scenes generally don't suffer)

I made my test using every bitrate from 900 to 5000.

Did you experience and solve these problems?

Thanks.

bilu
5th March 2004, 17:05
We at KVCD.net focused first into doing DVD-compliant streams and documentation.
Now we're investigating quality, and then we'll go to filesize prediction.

Can you post your command-line?

PS: Never tried resizing before, I've been trying to do DVDs, not SVCDs. But I'm curious about the interlaced scaling if I ever want to do VCDs - not enough to discard a field if you're working with a telecined source. The IVTC filters are still a bit crappy but mostly horribly documented :sly:

What is the blacker than black problem?


Bilu

unixfs
5th March 2004, 20:23
Hi,
actually I use these settings (only one of the many variations I tried)

mencoder "$INPUT" -of mpeg -o "$OUTPUT" -vc mpeg12, -ovc lavc -lavcopts vcodec=mpeg1video:preme=2:mbd=2:vbitrate=$BITRATE:vpass=1:vmax_b_frames=2:
vb_strategy=1:vrc_maxrate=5000:vqcomp=0.1:vpsize=1000:vstrict=1:
vrc_buf_size=917:aspect=4/3:nr=800:vratetol=10000000:cmp=256:precmp=256:
subcmp=256 -nosound -sws 2 $EXTRA

in 2 passes. *cmp=256 enabled chroma_me, mbd=2 encodes with the min macroblock distortion.

I also tried KVCD's matrices, but with worse results.

VCD are mpeg1 only, so no interlacing possible.
For SVCD remember to use -vf scale=480:576:1 and -lavcopts :ildtc:


Blacker than black is the problem caused by the different scale
of luma and chroma values on tv: [16,235] and [16,240] instead
of [0,255]. It shows very well: black is never a flat black, but
a series of flashing greyish or greenish blocks.
It's been widely discussed here:

http://forum.doom9.org/showthread.php?s=&threadid=31301&perpage=20&pagenumber=2

bilu
8th March 2004, 11:20
@unixfs

This is mine for 1-pass DVD encodings, but I'm still on a testing phase.

BATCH
=====
mencoder -include settings.ini -lavcopts keyint=15 movie.vob -o movie.mpg
bbdmux movie.mpg 0xe0 movie.m2v
del /q /f movie.mpg

SETTINGS.INI
=========
of=mpeg=1
ovc=lavc=1
vf=hqdn3d=4:3:6
noskip=1
nosound=1
lavcopts=vcodec=mpeg2video:ildct=1:ilme=1:vstrict=-1:
vrc_buf_size=1835:vqcomp=0:vqblur=0: preme=2:ildctcmp=2: precmp=2:
vqmax=10:mbqmax=10:vbitrate=300:vrc_minrate=300:
vrc_maxrate=9800:scplx_mask=0.3:autoaspect=1

It works very good. I get better quality and lower filesizes without B-frames than with B-frames using it. It seems to aim the lowest filesize possible to achieve a certain quality, because it does look pretty good: it raises bitrate whenever it's needed, but tries to keep it down.

About the blacker than black problem, I knew it but not under than name :)
Haven't checked it yet, but it may fit the same attitude problem that I found about Telecined sources - these guys have a monitor-oriented attitude leaving no choice to the users :angry:

http://www1.mplayerhq.hu/pipermail/mplayer-users/2003-February/030162.html

EDIT: vstrict=-1 was needed for VMesquita CVS compile because a bug in that version didn't let you use fractional framerates like 29.97 or 23.976 with vstrict=0.


Bilu

unixfs
8th March 2004, 11:50
Interesting, I'll try it, even though vbitrate=300 seems to be
really low.
What speed do you get at full size (without resizing)encoding ?

For my part I discovered that adding
-vf ...,eq=1,yuvcsp
(or even eq=2) reduces the blackiness, without introducing
too much lattice hue.

bilu
8th March 2004, 12:23
Mplayer's own script encodes with mjpegtools instead of mencoder :rolleyes:

http://www1.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/TOOLS/mencvcd

About yuvcsp:
yuvcsp -> Clamps YUV color values to the CCIR 601 range without doing real conversion

Maybe you only need this :)

My script's speed: 7fps on a PIII-500 :D
Low bitrate: it rises whenever it wants in this script.

Bilu

bilu
9th March 2004, 12:57
I was having a problem doing NTSC DVD encodes and keeping telecine.

Solved now:
http://kvcd.net/forum/viewtopic.php?p=66761#66761

Bilu

itcth
9th March 2004, 14:23
Please advice commandline for encoding to VCD Pal.

Regards,

bilu
11th March 2004, 14:32
Originally posted by itcth
Please advice commandline for encoding to VCD Pal.

Never did VCD (never did anything, I'm still on a testing phase :) ) but according to the man page:

vrc_buf_size=<value>
buffer size in kbit (pass 1/:2). For MPEG1/2 this also sets the vbv buffer size, use 327 for VCD, 917 for SVCD and 1835 for DVD. NOTE: vratetol should not be too large during the second pass or there might be problems if vrc_(min|max)rate is used.

Bilu

bilu
11th March 2004, 18:24
CVS build March 10th:
http://clientes.netvisao.pt/bilu/bruno/mencoder20040310a.zip

My settings, using the KVCD matrix, pretty good quality, very small filesize. Speed: 6/7 fps for PAL, 5/6 fps for NTSC, on a PIII-500.

Bold settings are for use with NTSC (use this build or newer):
BATCH
====
mencoder -include settings.ini -vf-pre softpulldown -lavcopts keyint=15 (18 ) movie.vob -o movie.m2v


SETTINGS.INI
========
of=rawvideo=1
vf=il=d,hqdn3d,il=i,yuvcsp
ovc=lavc=1
nosound=1
noskip=1
lavcopts=vcodec=mpeg2video:ildct=1:ilme=1:vstrict=-1:vrc_buf_size=1835:vqcomp=0:vqblur=0: preme=2:ildctcmp=2: precmp=2:vqmax=10:mbqmax=10:vbitrate=300:vrc_minrate=300:vrc_maxrate=9800:scplx_mask=0.3:autoaspect=1:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79:inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44

Cheers,
Bilu

Amnon82
12th March 2004, 00:05
@ itcth:

Till now I got always errors using the mpeg1codec.
I'll look throu this in my holidays the next 2 weeks.
Maybe I can build in a working settings for VCD into my GUI for Mencoder. If you want, try it. I didn't test VCD in my last release. Just optimized it for SVCD and DVD. My last SVCD got 795 MB incl. audio 112 kb and 91 min fullscreen in very good quality.

As soon as I have a working setting I'll post my cmdline.
Stay tuned...

@bilu:

THX for hosting a newer CVS. Did You compiled it by Your self?

bilu
12th March 2004, 01:36
Originally posted by Amnon82
@bilu:

THX for hosting a newer CVS. Did You compiled it by Your self?
I did, and you can do it too ;)

http://kvcd.net/forum/viewtopic.php?p=67029#67029


Bilu

bilu
12th March 2004, 17:05
Results from my settings (read posts above):
Filesizes
=========
abyss.vob.m2v -> 134.916.216 -> 36.111.221
amelie.vob.m2v -> 103.337.734 -> 24.185.169
anna.vob.m2v -> 164.022.016 -> 61.234.049
chap15.vob.m2v -> 329.337.333 -> 114.314.987
chap2.vob.m2v -> 223.575.480 -> 72.046.802
indiana.m2v -> 218.904.532 -> 53.085.408
matrix.m2v -> 122.009.328 -> 38.174.780
nemesis.m2v -> 219.144.332 -> 62.979.247
anime_telecine.m2v -> 30.879.651 -> 11.448.379
hybrid.vob.m2v -> 31.890.606 -> 6.039.997
interlaced.vob.m2v -> 46.741.160 -> 28.684.066
telecine1.vob.m2v -> 12.265.422 -> 3.647.157
telecine2.vob.m2v -> 16.380.030 -> 11.366.393

Avg Bitrates & Quantizers
=========================
abyss.vob.m2v -> 3503/4.73 -> 940/3.40
amelie.vob.m2v -> 3990/2.69 -> 938/4.02
anna.vob.m2v -> 4911/9.92 -> 1834/4.49
chap15.vob.m2v -> 5705/8.43 -> 1980/4.72
chap2.vob.m2v -> 5413/7.52 -> 1743/4.05
indiana.m2v -> 6847/2.58 -> 1661/3.53
matrix.m2v -> 5080/4.74 -> 1587/3.46
nemesis.m2v -> 4964/3.36 -> 1426/3.51
anime_telecine.m2v -> 3460/6.06 -> 984/4.42
hybrid.vob.m2v -> 6710/2.88 -> 1203/4.08
interlaced.vob.m2v -> 4453/7.48 -> 2729/4.74
telecine1.vob.m2v -> 6850/7.86 -> 1631/4.23
telecine2.vob.m2v -> 3320/10.18 -> 1840/3.81
And all of them look very good ;)


Cheers,
Bilu

itcth
12th March 2004, 17:21
@Amnon82

Thanks for your help.I have been facing a lot of compatitibilty problem when creating VCD by Mencoder.Nero never burn my mpeg file and complain my mpeg file is not standart mpeg1 VCD.

Best regards,

unixfs
12th March 2004, 17:32
libavcodec (therefore mencoder) doesn't create CBR mpeg files, and
mencder's mpeg muxer seems to have some compatibility problems
(especially with TMPG), so you will have to create VBR VCDs
and author them with VCDEasy

Amnon82
13th March 2004, 01:35
@itcth: me 2. Try out my new compiled mencoder version. Soon I'll check the VCD compatibilty...:sly:

@bilu: try it without minbitrate. So You have non underflows...

itcth
13th March 2004, 03:58
@Amnon92,
Below are my commandline to encode to VCD

REM #################################################################
mencoder.exe -of mpeg -ovc lavc -lavcopts

vcodec=mpeg1video:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79:inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44:vratetol=1000:vbitrate=1150:vrc_maxrate=1150:vrc_minrate=1150:vrc_buf_size=328:vqmin=2:vqmax=24:vb_qfactor=1.2:vi_qfactor=0.8:vqblur=0.3:keyint=15:aspect=4/3:vmax_b_frames=3 -vf scale=352:288 -ofps 25 -oac lavc -lavcopts acodec=mp2:abitrate=224 -srate 44100 "C:\1.avi" -o D:\Test\TestVCD.mpg

PAUSE
REM ##################################################################

First, i try with old mencoder (5.64 MB or 5,918,208 bytes ) .I can craete file D:\TestVCD.mpg but Nero deny to burn this file(Non compatible issue).

Later,i try the latest MencoderDRPEncBuild120304.exe.Encodeing stop at the beginning and report error(For WinXP).

Kindly look into my commandline if there is any thing gone wrong.

Best regards,

bilu
13th March 2004, 08:48
Originally posted by Amnon82
@bilu: try it without minbitrate. So You have non underflows...
The only underflow I see is at the exact beginning where it had no time to fill it yet, don't think that counts :)

And are you sure that it will be compatible with every standalone player? I've seen guys at KVCD.net complaining about audio stuttering when the video bitrate gets to 0... :rolleyes:

Bilu

Amnon82
13th March 2004, 18:16
k, your point!

RobertR
13th March 2004, 20:54
Idea of using Mencoder to encode DVDs is quite tempting to me as it would allow me to do that on linux and i could get rid of CCE.
I only have one problem in understanding all this. You all seem to use mencoder to encode to KDVD (from what i understand this is kinda standard DVD mpeg stream but encoded using different matrices or some such). I don't want to squeeze material so i can put zillions of movies on one dvdr media. I just want to get DVD backups that are as close to original as possible. Uptil now i've been successfully using Big3 method. Could You please suggest command line for DVD9 -> DVD5 method? Or is this all only matter of different max bitrate?
Finally do any of you have some comparison of quality between Mencoder and CCE?

bilu
13th March 2004, 21:47
Originally posted by RobertR
Could You please suggest command line for DVD9 -> DVD5 method? Or is this all only matter of different max bitrate?
I've recently impressed a friend of mine (experienced CCE encoder) when I showed him the quality I was getting with my settings and then the bitrates and quantizers :)

As you can see, I can reduce bitrate a lot and STILL use less quantizing than the original. Quality is very good and I can't see blocks or blurs. Of course it can be perfected for your purpose, just do this:

-remove completely the denoiser (hqdn3d);

-reduce or remove spatial complexity mask (scplx_mask);

-remove the intra_matrix and intra_matrix (you'll regret, better looking with 20% less bitrate is not something to abandon ;) )

-you can keep vbitrate=300 as long as you keep vqblur=0:vqmax=10:mbqmax=10 (it won't be afraid to raise bitrate when needed but will aim down when it can)

-Safest option for DVD9->DVD5 is of course two pass. For 1-pass it's hard to keep quality and avg bitrate at the same time. My method seems good because it does denoise, spatial-mask, custom-matrix and tries to lower bitrate when it can. It's not exactly aiming at a bitrate, but quality is good and filesizes too :)

-I avoided B-frames because I had problems with them on a high-action, blended field, interlaced anime. Never had that problem encoding with B-frames in Xvid on that stream, only with Mencoder.


Bilu

bilu
13th March 2004, 22:00
Main problem with Mencoder DVD authoring is chapters, for those who do it. Because you can't force keyframes.

Reported here:
http://article.gmane.org/gmane.comp.video.mplayer.devel/15978
and here:
http://article.gmane.org/gmane.comp.video.mplayer.user/27276
and mentioned here:
http://forum.doom9.org/showthread.php?s=&threadid=72544


Bilu

Amnon82
13th March 2004, 22:27
@bilu: lol bilu! :keyint=15 for PAL and :keyint=18 for NTSC.

DRPEnc is long out and also in the first version of it I added this function also called as GOB Length...

@RobertR: Hi my friend. I coded a gui for mencoder especialy for doing DVD9toDVD5 Copies. This gui is still under development but You can download always the newest version on my page. Enter the settings in General and skip Advanced. Use Prediction to get the right bitrate and quantizer and encode then the full movie. Best results will be 2Pass.

Finally do any of you have some comparison of quality between Mencoder and CCE?

I can use higher bitrates in MEncoder than in CCE. For the same filesize I use avg. 8500 max. 9800 in MEncoder and avg. 2500 max. 6500 in CCE. The Quality is in MEncoder better than in CCE. I encoded 5 Trailer and MEncoder gaves me better results. It depens on the settings.

bilu
13th March 2004, 22:59
Originally posted by Amnon82
@bilu: lol bilu! :keyint=15 for PAL and :keyint=18 for NTSC.

DRPEnc is long out and also in the first version of it I added this function also called as GOB Length...
Read again: http://forum.doom9.org/showthread.php?s=&threadid=72544
Originally posted by RobertR
I suppose that bilu was rather refering to posibility to pass info to mencoder to create key frame at particular point of video (like it can be done for CCE).
keyint is not the solution for this problem.
And if you check my settings on this very same thread you'd know I already knew that. :sly:


Bilu

RobertR
14th March 2004, 00:07
Originally posted by Amnon82
@RobertR: Hi my friend. I coded a gui for mencoder especialy for doing DVD9toDVD5 Copies. This gui is still under development but You can download always the newest version on my page. Enter the settings in General and skip Advanced. Use Prediction to get the right bitrate and quantizer and encode then the full movie. Best results will be 2Pass.
Yes I know about it (i've subscribed that thread and even installed 2.0.1). Just haven't time to test it.

I can use higher bitrates in MEncoder than in CCE. For the same filesize I use avg. 8500 max. 9800 in MEncoder and avg. 2500 max. 6500 in CCE. The Quality is in MEncoder better than in CCE. I encoded 5 Trailer and MEncoder gaves me better results. It depens on the settings.
Thanks to all who gave me some info on it :) This looks more and more tempting. I guess it's time for making some tests on my own :)

Amnon82
14th March 2004, 12:56
@bilu:

Read again: http://forum.doom9.org/showthread.php?s=&threadid=72544
Sorry! I didn't read this thread ... till now.

You ment the function to add Key - I - Frames on the exact position You want to set a chapter. Till now I don't know a way for this.

@RobertR:

Download my newest GUI (http://rj-elektronik.de/avideo/files/0202GUIONLY.exe). In this GUIOnly Release I added my last DVD-Settings. You must only copy the file 'lastencode.drpset' into C:\ and reload it in DRPEnc.

unplugged
15th March 2004, 21:08
Originally posted by bilu
Main problem with Mencoder DVD authoring is chapters, for those who do it. Because you can't force keyframes.
Maybe a solution could be an utility to slightly re-align chapter points to nearest KF, giving as output a new .txt file with chapters aligned.
Or a modified IFOedit version with this feature available in its DVD authoring part.

bilu
15th March 2004, 22:21
That was my first thought :)

But as I was thinking of using Mencoder as a CCE replacement to make the experience with a friend of mine which is an experienced CCE encoder without affecting the rest of the authoring process (I'm still learning to encode MPEG-2, never did authoring myself).

I don't know if realigning chapters is that easy :confused:

Bilu

Amnon82
16th March 2004, 10:10
I think something like this is build in in ReJig. Ask nic the coder of this app.

unplugged
16th March 2004, 14:21
Originally posted by Amnon82
I think something like this is build in in ReJig. Ask nic the coder of this app.
No, these kind of transcoders shouldn't change GOP struture...

Amnon82
16th March 2004, 15:38
@Unplugged: Yes Your right, but I'm talking about the DVDAuthor function inside of ReJig. I use ReJig most for authoring my DVDs which I encoded first with my DRPEnc.

RobertR
17th March 2004, 14:10
@Amnon82:
Thanks for the hint. I intend to do my nearst backup using mencoder and probably will use (at least partialy) DRPEnc for this also. Well unless i'll try jdobs newest kid which also looks tempting :D.
Alternatively You and jdobs could somehow gear up together and make mencoder an option for DVD ReBuild.

As for the chapter points. Maybe authoring software (Scenarist or DVDMaestro) will shift chapter points so that are at closest I frame
? I wouldn't expect authoring programs like IfoEdit or ReJig to do this but those more powerfull might be able to do tricks like that.

Amnon82
17th March 2004, 15:35
Nic released today his new QuEnc (http://forum.doom9.org/showthread.php?s=&threadid=72827)
It based on the same codecsource like MEncoder. Nic is on the beginning. I'm far away. So You have still more options in MEncoder. But Nic will work hard, and maybe his encoder will be better. Try it out.

Amnon82
19th March 2004, 18:32
New MEncoder Build out. Grab it here (http://forum.doom9.org/showthread.php?s=&threadid=72559)

cweb
8th July 2004, 06:46
I built my own mencoder from the pre4 release. I managed to get it to work, but I get this warning on a 29.97 ntsc purely interlaced source (a dvd extra):

[mpeg2video @ 009B2B8C]MPEG1/2 doesnt support 2997/100 fps, there may be AV sync issues

Should I be doing something else?
Edit: I get the same warnings with the other builds.. I did encode the same avs file using Tmpgenc plus at 29.97 mpeg2 (with good results and audio sync on my tv too), so I don't know why mencoder is complaining.

unixfs
8th July 2004, 07:27
someone suggested to use -ofps 30000/10001

cweb
8th July 2004, 14:16
Originally posted by unixfs
someone suggested to use -ofps 30000/10001
Thanks. I tried it and now it is saying

[mpeg2video @ 00750310]MPEG1/2 doesnt support 10001/3334 fps, there may be AV sync issues

Edit: Interesting.. I decided to google for -ofps 30000/10001 and found this link (http://zebra.fh-weingarten.de/~maxi/html/mplayer-dev-eng/2004-02/msg00172.html).

There was a mention of "I'll change to 24000/1001 to mencoder when mplayer reports 23.976, and similar for 29.97 i.e. 30000/1001=29.97003."
So I tried -ofps 30000/1001 and it worked! I mean no warning was given which is positive.

I hope the sync will be ok. This is a learning process but it's interesting. The same encode which usually would take me 1h 30 mins using Tmpgenc Plus 2.5x, seems like it will finish in 1hr. Is mencoder that fast? amazing. I'm using my compile (with gcc 3.3 i.e. not even the latest gcc, but optimised for my athlon which probably helps).

unixfs
8th July 2004, 14:33
please, post a message descriving the bug to mplayer-users@mplayerhq.hu

cweb
8th July 2004, 15:49
I am sending the message right now.. Thanks.