ATSC to HDTV without any GUI's (ffmpeg)
So converting to DVD works fine with avidemux2, except for the fact that when I use "DVD (lavcodec)" the video file is too small and the video quality sucks rocks. My goal is to go 100% non-gui: Abandon avidemux2 because it is heavily GUI dependent. It does have a command line mode, but I can't figure it out, and even if I did, cli mode still requires X11 and gtk for some reason.
Since I'm really running avidemux to use ffmpeg, why not just use ffmpeg instead of avidemux? Sounds like a decent plan. So here goes...
After much reading of ffmpeg, I settled on the following ffmpeg procedure:
Do two pass encoding where the first pass is:
nice ffmpeg -y -hq -i mars_demux.m2v -pass 1 -passlogfile mars_rate7500_passfile -target dvd -s 720x480 -deinterlace -r 30000/1001 -b 3200 -minrate 1500 -maxrate 7500 -aspect 4:3 -bufsize 4096 mars_out.mpg
After this completes, repeat the same command but with "-pass 2".
Explanation of ffmpeg options I used:
-y: Overwrite existing files (don't prompt user).
-hq: Enable high-quality mode (uh, sure, sounds good).
-i mars_demux.m2v: This is the video file produced when running the .nuv file thru ProjectX.
-pass 1: This is the first pass of two passes.
-passlogfile mars_rate7500_passfile: Specifies the file to write/read first pass data.
-target dvd: We want DVD formatted video to be outputted.
-s 720x480: Output will be standard DVD resolution (NTSC).
-deinterlace: We want progressive scan, not interlaced.
-r 30000/1001: Set frame rate to 29.97 ('-r 29.97' or '-r ntsc' should also work).
-b 3200: Set video bitrate to 3200kbps. Lower this if getting buffer underflow msgs.
-minrate 1500: Set min data rate to 1500kbps (VBR video).
-maxrate 7500: Set max data rate to 7500kbps. Max allowed by DVD spec is 9800, but probably wise to go no higher than 9000. There's a ffmpeg bug that might still exist that causes problems with high rates, http://www.transcoding.org/cgi-bin/transcode?DVtoDVD
-aspect 4:3 : This is the aspect ratio of the source video. This show was not widescreen. If it was then I would do -aspect 16:9.
-bufsize 4096 : This sets the DVD rate control buffer size (may not be needed but some examples I saw set this, and it seems reasonable to me). Seems to be a standard value of 224kb, but I got 'buffer underflow' error messages, so increased it to 1840. This was ok on a non-hidef show, but not enough for HD. So 4096. But this did not stop the buffer underflow errors either, so upgraded ffmpeg to a newer version.
mars_out.mpg: The name of the outputted DVD video.
Here's the output
ffmpeg version 0.4.9-pre1, build 4730, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --host=i686-redhat-linux-gnu --build=i686-redhat-linux-gnu --target=i386-redhat-linux --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --extra-cflags=-O2 -march=i386 -mcpu=i686 --enable-mp3lame --enable-vorbis --enable-faad --enable-faac --enable-xvid --enable-pp --enable-shared-pp --enable-shared --enable-gpl --disable-strip
built on Jan 15 2005 14:50:54, gcc: 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
Input #0, mpegvideo, from 'mars_demux.m2v':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: mpeg2video, 704x480, 29.97 fps
Assuming NTSC for target.
File 'mars_rate7500_ffmpeg.mpg' already exists. Overwrite ? [y/N] y
Output #0, dvd, to 'mars_rate7500_ffmpeg.mpg':
Stream #0.0: Video: mpeg2video (hq), 720x480, 29.97 fps, q=2-31, pass 1, 6000 kb/s
Stream mapping:
Stream #0.0 -> #0.0
[mpeg2video @ 0x5edce30]Warning min_rate > 0 but min_rate != max_rate isnt recommanded!
Press [q] to stop encoding
frame=40458 q=0.0 size= 739888kB time=1349.9 bitrate=4490.0kbits/s
Ignore the message "Warning min_rate > 0 but min_rate != max_rate isnt recommanded". http://www.cdr-zone.com/forum/about2271.html
Some insight to why the recorded source is 704x480 instead of 720x480 I found in this page:
"The 720-pixel-wide DV frame is actually slightly wider than the 720-pixel-wide DVD-Video frame--technically, the two formats have a slightly different pixel aspect ratio, and therefore display aspect ratio--so that if you encode DV directly to DVD without changing the size, the image will be slightly "squished" horizontally. The difference is small enough that it's usually not visible, but if you want to get the correct aspect ratio, you can clip 16 pixels from the left and/or right borders to get a 704-pixel-wide frame, which is also legal for DVDs. In particular, TV broadcasts often have thin black bars at the left and right due to the frame size difference, and clipping these off will also improve encoding quality. (For these reasons, it is also preferable to clip the video frame before resizing when using half-width or half-width/half-height video.)"
So next time I could try adding padding to the left/right with the following ffmpeg options:
-padleft 8 -padright 8
and that would make the source 720 pixels wide. This would probably remove any aspect ratio distortion introduced by going from 704 to 720. Probably worth a test run and a good test would be to set the padding color to something noticable like red:
-padcolor FF0000
I tried running with "-qscale 1" and got horrible buffer underflow error messages. So I went with the -maxrate, -minrate params instead. Later, I found a posting that said you have to set '-qmin 1' when doing '-qscale 1', but I never bothered trying it.
5/9/2006:
The sdtv programs were fine with this procedure, but when trying HD Late Night show, I would get many underflow errors though I searched and tried various adjustments of -b -minrate -maxrate -qmin -qmax -bufsize and probably a couple others. I posted to ffmpeg-user list for help, then had this idea to look at the mytharchive code for how it runs ffmpeg. This led to a new direction:
I found a possible solution, a new switch "-copyts" from mythburn/mytharchive and a simpler/reduced command line. So:
[root@be ~]# ffmpeg -y -i /mnt/finland.0000.mpg -r ntsc -target dvd -b 3000
-s 720x480 -copyts -aspect 16:9 /mythtv/finland_mytharchive2.mpg
Where finland.0000.mpg was created from hdtvtompeg2 (but could have used .m2v for inputfile just the same). The encoding finished without the underflow errors.
Sadly, the resulting mpeg file from ffmpeg cannot be muxed with mplex. So, I simply ran projectx on the resulting mpeg to produce a new .m2v (pass2.m2v), then mplex'd it:
mplex -f 8 -V -o mars_final.mpg mars_demux.ac3 pass2.m2v
Then, used dvdauthor on this .mpg file.
If this info helped you or saved you valuable time, please consider linking to this site as a favor.
0 Comments:
Post a Comment
<< Home