Tuesday, May 09, 2006

HD2DVD process

cat howto/hd2dvd_process.txt

Look up nuv file with mythrecordings.py
[root@myth ~]# /home/donn/scripts/mythrecordings.py

Correct nuv file with projectx (this is my script to make running PX easier):
[root@be scripts]# ./projectx.sh /mythtv myfixednuv /mnt/1041_20060509003700_20060509013600.nuv

NOTE: use -tom2p option of projectx! Don't demux (has bugs with hidef context)

Script is basically:
/root/tmp_jre/jre1.5.0_06/bin/java
-jar /root/tmp/projectx_0_90_4_doom9/ProjectX_Source_0.90.4/ProjectX.jar
-tom2p -out "$OUTDIR" -name "$OUTNAME" "$INFILE"

PX creates: myfixednuv.m2p
m2p/mpg is MPEG PS (rather than TS) and playable with windows media player, etc.

Encode to DVD-compliant video with ffmpeg (copy audio stream at same time). This file can be played with mplayer, windows media player, etc.:
[root@be scripts]# ffmpeg -y -i myfixednuv.m2p -r ntsc -target dvd -b 8000
-s 720x480 -deinterlace -copyts
-aspect 16:9 -acodec copy /mythtv/mydvdcompliant.mpg

If source video is 4:3, use -aspect 4:3

Optionally, check dvd compliant .mpg with mplayer:
mplayer -vo dummy -ao dummy -identify /mythtv/mydvdcompliant.mpg 2>&1 | grep "VIDEO|AUDIO"

Play .mpg file with xine:
# xine -pfhq --no-splash file:/mythtv/mydvdcompliant.mpg

Note, atsc files inevitably have some dropouts (transmission glitches) and this caused mplayer to lose audio and then halt. Playing the same file in xine results in no problems (except the glitches themselves, of course).

Build DVD disc layout with dvdauthor (output dir is 'mydvd'):
dvdauthor -o mydvd -x dvd.xml

Where dvd.xml is:
<dvdauthor>
<vmgm />
<titleset>
<titles>
<audio lang="en" />
<pgc>
<vob file="mydvdcompliant.mpg" chapters="0,10:00,15:00,20:00" />
</pgc>
</titles>
</titleset>
</dvdauthor>

Or via CLI for scripting (two programs as back-to-back chapters):
dvdauthor -o /mythtv/dvd_mars_prague -t -a ac3+en -c 0,10:00,20:00,30:00,40:00,50:00 mars_px_ff-dvd.mpg -c 0,5:00,10:00,15:00,20:00 prague_px_ff-dvd.mpg

Build video_ts.ifo:
dvdauthor -o /mythtv/dvd_mars_prague/ -T

Together:
# dvdauthor -o dvd_concorde_paris -t -a ac3+en
-c 0,10:00,20:00,30:00,40:00,50:00 concorde_px_ff-dvd.mpg
-c 0,5:00,10:00,15:00,20:00 paris_px_ff-dvd.mpg;
dvdauthor -o dvd_concorde_paris -T

Play from hard drive with xine:
# xine -pfhq dvd:///mythtv/dvd_mars_prague/

Footnotes:
* Thanks to Mike Shell for pointing out another nuance of ffmpeg: If you crop or pad, the order is very important. It makes a difference if crop/pad is entered before (or after) setting the video size (-s 720x480).

* During all this hassling with ffmpeg, I tried other programs: mencoder, transcode, and tmpgenc (Windows). I can say with ease, that ffmpeg is light years faster than these other programs, and its speed (and quality) is the main reason I worked hard to get ffmpeg to work with my recordings. The ffmpeg command line is not so bad after you are fluent in it. And now I've reduced the number of options so the command is shorter. Actually, it's kinda fun reading the ffmpeg lines used by other people. Yeah, the geek that I am.

Scripts I wrote to automate the process:

Script for making .m2p file with projectx:


donn@fatso:~/scripts/root_scripts$ cat projectx.sh
#!/bin/bash

if [ $# -ne 3 ]; then
   echo 1>&2 "Usage: $0 outdir outname "
   exit 127
fi

OUTDIR="$1"
OUTNAME="$2"
INFILE="$3"

/root/tmp_jre/jre1.5.0_06/bin/java -jar /root/tmp/projectx_0_90_4_doom9/ProjectX_Source_0.90.4/ProjectX.jar -tom2p -out "$OUTDIR" -name "$OUTNAME" "$INFILE"

# Show user the aspect ratio.
mplayer -vo dummy -ao dummy -identify "${OUTDIR}/${OUTNAME}.m2p" 2>&1 | grep VIDEO


===
Script for converting .m2p file to DVD .mpg


donn@fatso:~/scripts/root_scripts$ cat convert_m2p.sh
#!/bin/bash

if [ $# -ne 3 ]; then
   echo 1>&2 "Usage: $0 src_dir outdir basename"
   echo 1>&2 " $0 /mnt/nfs /mythtv leno_clip"
   echo 1>&2 " if srcfile is /mnt/nfs/leno_clip.m2p"
   exit 127
fi

date

SRCDIR="$1"
OUTDIR="$2"
OUTNAME="$3"

# Get AR.

ASPECTTMP=`mplayer -vo dummy -ao dummy -identify "${SRCDIR}/${OUTNAME}.m2p" 2>&1 | egrep VIDEO\_ASPECT`
#echo $ASPECTTMP
# This ($ASPECTTMP2) is 1.3333 or 1.777
ASPECTTMP2=`expr match "$ASPECTTMP" '[=_A-Z]\+\(.\+\)'`
echo "Numerical aspect is $ASPECTTMP2"
# Keep only '[0-9].[0-9]'
ASPECTNUM=`expr match "$ASPECTTMP2" '\([0-9]\.[0-9]\)'`
# ASPECTNUM is "1.3" or "1.7"
#echo $ASPECTNUM

if [ $ASPECTNUM == "1.3" ]; then
   ASPECT="4:3"
else
   ASPECT="16:9"
fi
echo "Aspect ratio is $ASPECT"

echo "Running ffmpeg."
echo "Input is : ${SRCDIR}/${OUTNAME}.m2p"
echo "Outputting: ${OUTDIR}/${OUTNAME}_ff-dvd.mpg"

nice ffmpeg -y -i "${SRCDIR}/${OUTNAME}.m2p" -r ntsc -target dvd -b 2048k \
-s 720x480 -deinterlace -copyts \
-aspect $ASPECT -acodec copy "${OUTDIR}/${OUTNAME}_ff-dvd.mpg"

date


Poor quality video (lots of blockiness):

From the ffmpeg docs:

"The parameter 'q' which is displayed while encoding is the current quantizer. The value 1 indicates that a very good quality could be achieved. The value 31 indicates the worst quality. If q=31 appears too often, it means that the encoder cannot compress enough to meet your bitrate. You must either increase the bitrate, decrease the frame rate or decrease the frame size."

For target type 'dvd', this gave q of 5-10 (for a HD recording):

-target dvd -b 2048k

More tips from the ffmpeg docs:


* To have a constant quality (but a variable bitrate), use the option '-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst quality).
* When converting video files, you can use the '-sameq' option which uses the same quality factor in the encoder as in the decoder. It allows almost lossless encoding.


Using -qscale instead of -b: Found blog that said best (best tradeoff of quality to filesize) qscale numbers are 5, 9, 11. [ http://www.kilobitspersecond.com/2007/05/24/ffmpeg-quality-comparison/ ]

2 Comments:

At 10:02 AM, Blogger Donn Lee said...

I got an email today:

"""Donn:

There is only a few guides out there that deal with this subject
thoroughly, e. g. http://www.linux.com/article.pl?sid=06/04/17/2058219

However, I find your blog most analytical and useful since you share the
what has worked for you and what not.

I managed to follow all your steps outlined (install ProjectX, ffmpeg on
a freshly installed Debian SID system as well as on Ubuntu Dapper Drake.
I was using virgin HDTV material from MythTV (with commercials) as well
as material with Commercials cut out using MythTV.
I am able to generate an m2p file with ProjectX without any problems

However, I always get Segmentation Faults from ffmpeg, no matter what
after some while.. I was never able to convert a one hour show to DVD
mpeg so far...

I was wondering if you experienced similar situations and how you
managed to work around it?

Presently I am running a up-do-date Dapper Drake system.

My ffmpeg version is:

ffmpeg version CVS, build 3276800, Copyright (c) 2000-2004 Fabrice
Bellard
configuration: --extra-cflags=-fomit-frame-pointer
-DRUNTIME_CPUDETECT --build i486-linux-gnu --enable-gpl --enable-pp
--enable-zlib --enable-vorbis --enable-libogg --enable-theora
--enable-a52 --enable-dts --enable-dc1394 --enable-libgsm
--disable-debug --prefix=/usr
built on Nov 24 2005 10:19:02, gcc: 4.0.3 20051121 (prerelease)
(Ubuntu 4.0.2-4ubuntu3)
ffmpeg CVS
libavcodec 3276800
libavformat 3211520

Andreas"""

My response:

Hi Andreas,
Thanks for your email and comments. I am still encoding with ffmpeg
as described in my blog and I have not seen any seg faults so far. I
am running Fedora Core 3 with a 2.6.9 kernel. I am including my
ffmpeg version info below:

[donn@be ~]$ ffmpeg -version
FFmpeg version CVS, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --prefix=/usr --libdir=/usr/lib --mandir=/usr/share/man --
enable-mp3lame --enable-libogg --enable-vorbis --enable-theora --enable-faad
bin --enable-xvid --enable-a52 --enable-a52bin --enable-pp --enable-shared -
-enable-pthreads --enable-dc1394 --enable-gpl --disable-strip --extra-cflags
=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -m32 -march=i386 -f
asynchronous-unwind-tables
libavutil version: 49.0.0
libavcodec version: 51.7.0
libavformat version: 50.3.0
built on Mar 1 2006 06:18:11, gcc: 3.4.4 20050721 (Red Hat 3.4.4-2)
ffmpeg CVS
libavutil 3211264
libavcodec 3344128
libavformat 3277568

I got this version of ffmpeg as an rpm from atrpms. I have used older
versions of ffmpeg on this same PC, and not seen any seg faults with
the older versions. I think my blog may have some output with the
older versions.

I hope some of this info will be helpful.

Donn

 
At 3:02 AM, Blogger Donn Lee said...

Andreas updated me and said:

"""Thanks for getting back with me.

Made some progress... Yesterday I have compiled ffmpeg cvs from Ubuntu
with Athlon XP optimizations (which is my CPU). Now it runs much, much
better....

I guess, I keep you posted...

Andreas"""

 

Post a Comment

<< Home