PDA

View Full Version : ffmpeg muxing problem


burnix
7th February 2008, 20:22
Hello. I have some problems to encode a vob file with ffmpeg (delay between audio/video). i try to method : encode all the stream in 1 pass and encode in two pass all the streams separately and mux them.

with first methos i have delay and with second one i have error.

So il you have some suggestion i thank you a lot.

1-command line

ffmpeg -y -i E:\Dvd\VIDEO_TS\VTS_01_1.VOB -aspect 16:9 -t 30 -vcodec libxvid -croptop 70,0 -cropbottom 70,0 -s 624x256 -r 25 -b 1000k -flags +trell -g 250 -me_method epzs -qmin 2 -qmax 15 -acodec libmp3lame -ac 2 -ar 44100 -ab 80k -benchmark OUT.avi

2-command line

ffmpeg -ss 1000 -t 10 -y -i E:\Dvd\VIDEO_TS\VTS_01_1.VOB -aspect 16:9 -croptop 4,0 -cropbottom 4,0 -s 624x352 -vcodec libxvid -vtag xvid -b 1000k -flags +trell -g 250 -me_method epzs -qmin 2 -qmax 15 -an -r 25,0 -pass 1 -passlogfile xvid.stats ffmpeg-xvid-temp.avi
ffmpeg -ss 1000 -t 10 -y -i E:\Dvd\VIDEO_TS\VTS_01_1.VOB -aspect 16:9 -croptop 4,0 -cropbottom 4,0 -s 624x352 -vcodec libxvid -vtag xvid -b 1000k -flags +trell -g 250 -me_method epzs -qmin 2 -qmax 15 -an -r 25,0 -pass 2 -passlogfile xvid.stats ffmpeg-xvid-temp.avi
ffmpeg -ss 1000 -t 10 -y -i E:\Dvd\VIDEO_TS\VTS_01_1.VOB -vn -acodec libmp3lame -ac 2 -ar 48000 -ab 128k ffmpeg-xvid-temp.mp3
ffmpeg -y -f avi -i ffmpeg-xvid-temp.avi -r 25,0 -vcodec copy -i ffmpeg-xvid-temp.mp3 -acodec copy ffmpeg-xvid.avi

2-error

error, non monotone timestamps 1 >= 0
av_interleaved_write_frame(): Error while opening file

20-40
8th February 2008, 20:29
Mencoder is (a close cousin of ffmpeg) much better for this conversions.

First, your audibitrate is to low for libmp3lame. Try from 128 kbps upwards, and always use CBR (may save you from troubles).
Second, IF you do two pass encode - it's good thing to use audio-track in 1st pass too, even encoded to low quality, as I do for years. For example:


1st pass

mencoder -dvd-device d:\dvd\movie.iso dvd:// -sws 9 -vf scale=576:-2 -ovc lavc -ffourcc divx -lavcopts vcodec=mpeg4:vpass=1:turbo:vmax_b_frames=2:vb_strategy=1:vbitrate=824:keyint=250:autoaspect -oac pcm -channels 1 -srate 4000 -alang en -slang es -o d:\dvd\out.avi

2nd pass

mencoder -dvd-device d:\dvd\movie.iso dvd:// -sws 9 -vf scale=576:-2 -ovc lavc -ffourcc divx -lavcopts vcodec=mpeg4:vpass=2:vhq:vmax_b_frames=2:vb_strategy=1:vbitrate=824:keyint=250:autoaspect -ofps 25.000 -af volume=+8dB:channels=2 -oac mp3lame -lameopts cbr=128 -alang en -slang es -o d:\dvd\out.avi

For single .vob you can try ffmpeg, BUT for 1: your source material must be properly identified because most of the "issues" came from improper fps conversions. You surely know about delays in vobs, and other very important stuff I'm talking about.
This always works for me IF input material is PURE PAL and audio is non-delayed.

ffmpeg -i "E:\Dvd\VIDEO_TS\VTS_01_1.VOB" -vcodec libxvid -trell -max_bframes=2 -s 624x352 -b 800k -r 25 -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -y -pass1 "xvid.stats" -f avi out.avi

ffmpeg -i "E:\Dvd\VIDEO_TS\VTS_01_1.VOB" -vcodec libxvid -trell -max_bframes=2 -s 624x352 -b 800k -r 25 -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -y -pass2 "xvid.stats" -f avi out.avi


Also, if your input is damaged (contain bad frames for instance) both mencoder and ffmpeg CANNOT perform two-pass encoding (because stats from first pass differ from second pass) and you're stuck (as I have zillion times) with either constant bitrate 1 pass encoding, or 1 pass constant quality - the one I prefer, and at factor 3.4 or/to 4 always give good results.

burnix
9th February 2008, 10:03
Thanks. I'm going to try this, but i think i have pure dvd pal. I have check delay with mediainfo, dvd2avi, mplayer info and i dont have delay. If i make a test with mencoder it work, but not with ffmpeg. I prefer ffmprg because of sound was encoded with more volume (sorry for my english) and it was more faster in xvid (?????).

So i'm going to try your solution, demux with mencoder encode seperate stream with ffmpeg and remux with mencoder, to see if it work.

Thanks for your help.

edit----------------------------

this work like a charm with mencoder

mencoder -ss 1000 -endpos 10 dvd://1 -dvd-device e:\dvd -sws 9 -vf crop=720:560:0:8,scale=624:352 -ovc lavc -ffourcc divx -lavcopts vcodec=mpeg4:vpass=1:turbo:vmax_b_frames=2:vb_strategy=1:vbitrate=1000:keyint=250 -oac pcm -channels 1 -srate 4000 -o doom9.avi
mencoder -ss 1000 -endpos 10 dvd://1 -dvd-device e:\dvd -sws 9 -vf crop=720:560:0:8,scale=624:352 -ovc lavc -ffourcc divx -lavcopts vcodec=mpeg4:vpass=2:vhq:vmax_b_frames=2:vb_strategy=1:vbitrate=1000:keyint=250 -ofps 25.000 -af volume=+8dB:channels=2 -oac mp3lame -lameopts cbr=128 -o doom9.avi

This this work with ffmpeg (?????? out of sync audio and video)

ffmpeg -ss 1000 -t 10 -y -i "E:\Dvd\VIDEO_TS\VTS_01_1.VOB" -vcodec libxvid -trell -max_bframes=2 -me_method epzs -croptop 4,0 -cropbottom 4,0 -s 624x352 -b 1000k -r 25 -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -y -pass 1 -passlogfile xvid.stats -f avi out.avi
ffmpeg -ss 1000 -t 10 -y -i "E:\Dvd\VIDEO_TS\VTS_01_1.VOB" -vcodec libxvid -trell -max_bframes=2 -me_method epzs -croptop 4,0 -cropbottom 4,0 -s 624x352 -b 1000k -r 25 -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -y -pass 2 -passlogfile xvid.stats -f avi out.avi

20-40
9th February 2008, 13:59
First, consider that I use binaries compiled for me and by myself, sources are SVN (newest) versions of ffmpeg, mencoder, xvid, lame et c. I've said this because everything (as it does for years) may work for me, but not for someone else, taking into account number of different binaries out there. Both ffmpeg and mencoder are well-known for constant changes - especially in changing the command-line parameters and syntax.
Heavy bugs are spotted immidiatelly and fixed in matter of days. However, all this confuses users, because some parameters appears no to work anymore, but only because their syntax (or whatever) has been changed.

I use ffmpeg only for muxing and demuxing. He is superior in that to any other application I've tried. Nevertheless, video encoding is pretty much the same as in mencoder (libavcodec) but lacks some "advanced" input and filtering options which mencoder has.
For audio encoding ffmpeg is 9 to 10 times slower then mencoder, even if they use the same library (libmp3lame for example). I get 1.2 RT in ffmpeg, and 10-11 in mencoder for pure mp3 encoding. Ffmpeg is (for no apparent reason to me) too slow in that.
For muxing/demuxing I use this drag&drop "D&D_demux.bat" saved on my desktop and I just "un-rem" needed lines. Be aware that any blank spaces in file-names are unacceptable (my_movie.avi works - but my movie.avi not):

@rem
@echo off
@set fname=%1%
echo %fname%
@rem
@rem
@rem # just demux (-acodec copy), -vn with no video, -y overwrite out. file #
ffmpeg.exe -i %fname% -acodec copy -vn -y %fname%.mp3
@rem ffmpeg.exe -i %fname% -acodec copy -vn -y %fname%.ac3
@rem ###################################################################################
@rem # Ffmpeg CAN recompress audio track too (but...it is painfully slow in mp3 !!!) #
@rem ###################################################################################
@rem ffmpeg -i %fname% -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -vn -y D:\audio.mp3
@rem ##############################################################################################
@rem # Ffmpeg CAN mux existing already encoded video and recompress/ed aud. track if you d&d .avi/.avs on #
@rem ##############################################################################################
@rem ffmpeg -i %fname%_.avi -i %fname% -vcodec copy -acodec libmp3lame -ac 2 -ar 48000 -ab 128k -map 0:0 -map 1:0 -f avi %fname%_muxed.avi



As you, I prefer XviD too, and my mencoder lines:
1st pass

mencoder -dvd-device d:\dvd\movie.iso dvd:// -sws 9 -vf scale=576:-2 -ovc xvid -xvidencopts pass=1:max_bframes=2:hq_ac:trellis:vhq=4:bvhq=1:threads=2:autoaspect:profile= asp5 -oac pcm -channels 1 -srate 4000 -alang en -slang es -o out.avi

and for 2nd pass:

mencoder -dvd-device d:\dvd\movie.iso dvd:// -sws 9 -vf scale=576:-2 -ovc xvid -xvidencopts pass=2:bitrate=800:max_bframes=2:hq_ac:trellis:vhq=4:bvhq=1:threads=2:autoaspect:profile=asp5 -af volume=+8dB:channels=2 -oac mp3lame -lameopts cbr=128 -alang en -slang es -o out.avi

or 1 pass constant quality "batch" (mass) re-encoding all .avi files in one folder:

@rem # filename: CQre-encode.bat
set PATH=C:\xvid_encraw;%PATH%
for %%f in (*.avi) do (mencoder-09022008 %%f -sub %%f.srt -vf hqdn3d,pp=0x77 -ovc xvid -xvidencopts fixed_quant=4:lumi_mask:max_bframes=2:hq_ac:trellis:vhq=4:bvhq=1:threads=2:autoaspect -oac copy -o %%f.avi)

work as they are for 99% of inputs.
Further, here are links to on-line man (manual) pages:
http://man.cx/ffmpeg(1)

http://man.cx/mencoder(1)

burnix
10th February 2008, 10:02
Hello. After a few test it seems that ffmpeg was not good for muxing. But i have resolved my problem.

I can sync my audio and video if i add -async parameter in the ffmpeg command line like this :

ffmpeg -y -ss 360 -t 30 -i "E:\Dvd\VIDEO_TS\VTS_01_1.VOB" -aspect 16:9 -croptop 4,0 -cropbottom 4,0 -sws_flags +lanczos -s 624x352 -vcodec libxvid -b 1000k -flags +trell -g 250 -me_method full -qmin 2 -qmax 15 -acodec libmp3lame -async 25 -ac 2 -ar 48000 -ab 128k -pass 1 -passlogfile xvid.stats -f avi out.avi
ffmpeg -y -ss 360 -t 30 -i "E:\Dvd\VIDEO_TS\VTS_01_1.VOB" -aspect 16:9 -croptop 4,0 -cropbottom 4,0 -sws_flags +lanczos -s 624x352 -vcodec libxvid -b 1000k -flags +trell -g 250 -me_method full -qmin 2 -qmax 15 -acodec libmp3lame -async 25 -ac 2 -ar 48000 -ab 128k -pass 2 -passlogfile xvid.stats -f avi out.avi

Mencoder dont have this problem because it detect the delay between audio and video.

I dont know how the delay come because in the source stream there is no delay (verified with dvd2avi and mediainfo)

And for the speed i dont see any difference in mp3 encoding speed between mencoder and ffmpeg.

Thats all falks for 3 weeks. Bye and thanks for that (20-40).

P.S : i use the latest win32 buils for mencoder and ffmpeg.

20-40
10th February 2008, 19:18
>>Mencoder dont have this problem because it detect the delay between audio and video.<<

Like I've said in my first post - for such tasks mencoder is better choice.

>>And for the speed i dont see any difference in mp3 encoding speed between mencoder and ffmpeg.<<

I forget to mention "with some inputs". I usually fed both applications with avisyth script. That's case.

>>Thanks.<<
You're welcome. It wasn't just for two of us, I think.

45tripp
10th February 2008, 22:49
After a few test it seems that ffmpeg was not good for muxing.

ffmpeg muxing is quite broken from 10891