[MPlayer-users] Encoding problems / tips needed

JiHO jo.irisson at noos.fr
Sun Aug 1 01:17:33 CEST 2004


Hi all,

I followed some topics in here about encoding from dvd, particularly 
this discussion around an encoding script:
[MPlayer-users] Script update from Meino.Cramer at gmx.de
and I came with a hopefully not-to-bad encoding method. Nevertheless 
there are still some hicups and I'd like to have your probably very 
useful comments before I try to script all this and translate it to 
french for a french mencoder tutorial. Maybe, if we come with something 
clear and functional it can be a great help to other people. Feel free 
to post any comment.
Here are the steps I follow:

0/. [Not compulsory] Rip the dvd to your hard drive.
Then, encode from this rip with:
	mencoder dvd://1 -dvd-device /where/you/ripped/it/

1/. Encode (or just extract) the audio in a way appropriate for your 
source material and target format.
	output AC3 5.1 directly from an AC3 5.1 DVD:
		mplayer dvd://1 -dumpaudio
	output MP3:
		mplayer dvd://1 -alang en -vc dummy -vo null -ao pcm -aofile foo.wav
		lame --preset standard foo.wav foo.mp3
	output OGG:	
		mplayer dvd://1 -alang en -vc dummy -vo null -ao pcm -aofile foo.wav
		oggenc -q 6 foo.wav -o foo.ogg

2/. Calculate required video bitrate.
	vbitrate = (target_size - audio_size - overhead) * 8 / duration in 
seconds / 1000
The sizes are in bytes, overhead is around 1% to 1.5% for most containers.
AVI container: around 1%
OGM container: around 1.2%
	Example: in order to fit the movie on two 700 Mb CDs
		target_size = 1 400 000 000
		audio_size = ????
			an AC3 stream dumped from a DVD, around 450Mb: 471 132 672
			same stream dumped to WAV and encoded to MP3 with lame --preset 
standard, around 201Mb: 210 741 240
			same stream dumped to WAV and encoded to OGG with oggenc -q 6, around 
180Mb: 188 146 208
		overhead (at most) = 1 400 000 000 x 0,015 = 21 000 000
		duration = 02:43:35
          		= 2 x 3600 + 43 x 60 + 35 = 9815 seconds
	vbitrate = 739,9 = 740 for AC3 audio
		= 952,2 = 952 for MP3 audio
		= 970,6 = 971 for OGG audio
NB: this is probably not too good I should rip this on 3 CDs ;-)

3/. Detect black bands and aspect ratio:
	mplayer dvd://1 -vf cropdetect
If dimensions are not divisible by 16:
	3.1/ change it to the lower 16 multiplier and change the offset to keep 
the center of the video. use only even numbers.
	Example: cropdetect outputs -vf crop=720:362:0:58
	362 isn't divisible by 16. The nearest low multiplier is 352. so we 
change to:
		-vf crop=720:352:0:58
	but then the vertical offset (58) is wrong because we cropped out 10 
additional pixels from the bottom of the picture. we thus want to add 5 
to this offset. but 5 is odd so we add 4. this results in:
		-vf crop=720:352:0:62
	3.2/. scale the video to the nearest 16 multiplier
	Example: cropdetect outputs -vf crop=720:362:0:58
	362 isn't divisible by 16. The nearest low multiplier is 352. so we 
change to:
		-vf crop=720:362:0:58,scale=720:352

4/. Do video pass 1. You can use -oac copy to ensure good sync.
mencoder dvd://1 -alang en -oac copy -vf crop=???,hqdn3d=2:1:2 -ovc lavc \
-lavcopts 
vcodec=mpeg4:vbitrate=???:v4mv:mbd=2:naq:trell:cmp=3:subcmp=3:mbcmp=3:vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01:autoaspect:vpass=1 
\
-noskip -skiplimit 0 -noodml -o /dev/null
The video is not useful and can be thrown out to /dev/null.

5/. Likewise for video pass 2.
mencoder dvd://1 -alang en -oac copy -vf crop=???,hqdn3d=2:1:2 -ovc lavc \
-lavcopts 
vcodec=mpeg4:vbitrate=???:v4mv:mbd=2:naq:trell:cmp=3:subcmp=3:mbcmp=3:vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01:autoaspect:vpass=2 
\
-noskip -skiplimit 0 -noodml -o mymovie.avi

6/. Mux audio from 1 with video from 5.
output AC3 audio in AVI container:
	leave mymovie.avi as it is.
output MP3 audio in MKV container:
	mkvmerge -o mymovie.mkv -A mymovie.avi foo.mp3
output OGG audio in MKV container:
	mkvmerge -o mymovie.mkv -A mymovie.avi foo.ogg	
output OGG audio in OGM container:
    ogmmerge -o mymovie.ogm -A mymovie.avi foo.ogg

6bis/. [Not compulsory] Split resulting file in two or more parts to fit 
on cds:
avisplit -i mymovie.avi -o mymovie_split.avi -s 700
ogmsplit -o mymovie_split.avi -s 700

The problems:
hicup 1/ Movie duration in step 2 has to be read from lsdvd because 
mplayer's OSD seems to give a wrong value when playing DVDs.
hicup 2/ even if the switches "-noskip -skiplimit 0" are used in step 4, 
some frames are skipped, two or three times, at the beginning of the 
movie. This is not problematic for the rest of the encoding but it seems 
strange to me as mencoder shouldn't skip frames.
hicup 3/ even using nearly all the "quality providing options" of lavc 
(if you think of others, please do not hesitate) at quite high bitrates 
(up to 1400), I still get some problems with the dark areas of the 
movie. the dark greys are not very well dealt with and I got big black 
squares in the darkest parts of the movie, instead of the beautiful 
gradient of dark greys I hoped (see attached picture if you don't see 
what I mean - I hope the picture is not too heavy to be sent on this 
list). does any one have a trick to make things better? some filter 
options maybe or something like this?

Remark: Alternative method for MKV with MP3 audio:
1. encode audio directly with lame in mencoder (= PASS 0)
	mencoder dvd://1 -ovc frameno -oac mp3lame -lameopts preset=standard -o 
frameno.avi
2. This calculates the video bitrate automatically. But this is for an 
AVI container I guess. I assume that the MKV container header is around 
the same size as AVI header and use this bitrate.
3. crop as before	
4. rename frameno.avi to audio.avi and encode as before so that it uses 
AC3 audio and NOT audio from PASS 0. PASS 0 was only a way to encode 
audio, using mencoder's support for lame and to calculate the bitrate.
5. as before
6. Mux AUDIO from audio.avi with video from 5.
  output MKV:
	mkvmerge -o mymovie.mkv -A mymovie.avi -V audio.avi
Question: I know that 3 pass encoding is deprecated but don't you think 
this could be used?

Thank you for any comment. Sorry if this email was "a bit" long... ;-)
I'll post the resulting script someday on this list for review if that's 
OK with everybody.
-- 
JiHO
---
   Windows, c'est un peu comme le beaujolais nouveau :
à chaque nouvelle cuvée on sait que ce sera dégueulasse,
     mais on en prend quand même, par masochisme.
---
-------------- next part --------------
A non-text attachment was scrubbed...
Name: capture.png
Type: image/png
Size: 96153 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-users/attachments/20040801/41b5c647/attachment.png>


More information about the MPlayer-users mailing list