ReplayToDvd

From IckyWiki

Jump to: navigation, search

- Linux specific instructions for combining replay tv recordings into a DVD with menus -


Much thanks to this site for most of this information, along with the AVS forum for rtv5k tools. If you need more specific info, you should consult one of those sites.

These instructions have been customized for gentoo and for NTSC systems. For other linux distros or PAL-specific instructions, see the previous howto link.

I mostly am writing this up because the previous site was more for video files in general and not so much for Replays; I had trouble getting transcode to work right on replay files (video/audio sync), so I decided to use the RTV5K tools for that part. Also added a few details that might not've been mentioned, like adjusting the length of the menu video to match audio, etc. Mostly for my own benefit so I don't forget how I did it.

- EricaErkkila

Contents

Initial Setup

  • Obtain and install DVArchive; download shows to your local machine
    • This is a java program for seeing your Replay TV on the network and downloading shows from it
  • For encoding the replay tv files into DVD format, obtain rtv5k tools from the AVS forum
    • note that more help with the RTV tools can be obtained from the txt file included with the binary distributions.
  • Obtain gopdit, in order to edit out commercials (goes by gop boundaries so you don't have to transcode in order to edit them out). Note that depending on your qt setup you may need to specify the QT dir for configure, in order to get it to compile properly (eg /usr/qt/3). See configure --help for options.


Then, obtain a bunch of stuff available from portage:

  • for all of these, to get the version indicated you may need to stick ACCEPT_KEYWORDS=~x86 in front of emerge package
  • You might want wxvlc for watching streaming video from the Replay on your PC through DVArchive. That's vlc in portage.
  • transcode 0.6.14 or later
    • this program is for transcoding most avi and mpg files to dvd format that dvdauthor will like (although, I never could get audio/video sync using it for replay files which is why I opted to go with the rtv5k solution--also because that solution allows for automatic commercial removal). Still, if you have non-replay-TV files you want to write to DVD, you might want this.
    • requires ffmpeg, at least 0.4.9_pre1
  • mjpegtools, at least 1.6.2
    • includes some programs for making a jpg into an mpg for the menu
    • includes mplex
  • cdrtools
    • even if you don't have a DVD writer on your machine, you might want this for making isos
  • gimp (or some other image manipulation program)
    • for making graphics for menu, etc.
  • dvdauthor 0.6.10 or later
    • for putting it all together and making the VIDEO_TS files that will go onto the DVD
  • xine or other video player
    • for testing DVD files, grabbing screenshots, playing videos, etc.
  • toolame
    • useful for creating a silent audio file, if needed

I had to add the following to /etc/portage/package.keywords:

media-video/vlc ~x86
media-video/ffmpeg ~x86
media-video/transcode ~x86
media-video/dvdauthor ~x86
media-libs/libquicktime ~x86

I also had to add some stuff to my USE variable in /etc/make.conf:

  • for vlc:
nls xv bidi truetype wxwinsows imlib matroska faad png wxwindows
  • for transcode ~x86:
mmx

scripts

  • make yourself some scripts for doing the replay file to dvd conversion, to make it easier every time you do it (below). Every script will require a base path/filename for the show files that came from the replay. That is, the full path to the files with the filename up to (not including) the .extension (ie before the last dot). Note that some of these programs seem to break if you have more dots than just the one before the extension in the filenames; before running the scripts be sure to rename any files with extra dots in them.
    • eg, if files are like /home/test/junk/show1.mpg and /home/test/junk/show1.evt, etc. you would enter at the prompt: /home/test/junk/show1

mkText.pl

This script takes the .evt file from the replay and turns it into a text file showing start and stop times for commercials. Just run this once.

You may also want to try downloading and learning to use cinelerra (cinelerra-cvs for gentoo) and use it to figure out the exact time indices. To use this, you have to run the replay mpg file through mpeg3toc first, to get a toc file to open in cinelerra. You could also try using cinelerra to edit the file and render the output, although you would need to figure out how to get the rendering options correct so you get a file of the correct size/quality.

Even better is to obtain gopdit. Although it forces edits on gop boundaries rather than any frame you want, it's very nice because you can figure out the boundaries, then export as an RTV txt file which rtvedit can use directly!


#!/usr/bin/perl

my $in = $ARGV[0];
my $segments = $ARGV[1];

if ( $in =~ /^\s*$/ )
{
        print "Enter base path/filename of show files: ";
        chomp( $in = <STDIN> );
}

my $evt = $in . ".evt";
my $txt = $in . ".txt";

if ( $in =~ /^\s*$/ or !-f "$evt" )
{
        die "$evt not found\n";
}

my $segflag = "-p";
if ( $segments =~ /^\s*$/ )
{
        print "Program segment (if half hour show, enter 180) [default 300]: ";
        chomp( $segments = <STDIN> );
}
if ( $segments =~ /^[0-9]+$/ )
{
        $segflag .= $segments;
}
else
{
        $segflag .= "300";
}

#=head2
my $evtdump = "/home/test/bin/evtdump $segflag \"$evt\" > \"$txt\"";
print "doing $evtdump\n";
system($evtdump);
#=cut

mkEdits.pl

This script takes the .txt file produced by mkText.pl or using cinelerra or gopdit above and edits the mpeg file into one without commercials. This may be an interative process where you edit the .txt file and re-run this until you're happy with the results, because it's hardly ever perfect at picking which transitions were commercials. When editing the .txt, note that if there is more than one 'D' line in a row, or more than one 'A' line in a row, only the last one in the series counts. Basically A means it's going to pick up the recording at that time, and D means it's going to start ignoring the data at that time. You should always compare the edited file (ending in 1.mpg) with the original to make sure the commercial spots are all gone, and that none of the show got accidentally removed. This is the most time-consuming part of the process.

Depending on how you got your .txt file, you may need to give rtvedit the -t1 flag as well. If using evtdump (mkTxt.pl), you won't need it, nor will you if you export an RTV txt file from gopdit. But, if you get the timestamps from another program like cinelerra you'll want to use -t1 to make it use the nearest editable point.

#!/usr/bin/perl

my $in = $ARGV[0];

if ( $in =~ /^\s*$/ )
{
        print "Enter base path/filename of show files: ";
        chomp( $in = <STDIN> );
}

my $txt = $in . ".txt";

if ( $in =~ /^\s*$/ )
{
        die "Input blank\n";
}

#=head2
my $rtvedit = "/home/test/bin/rtvedit \"$txt\"";
print "doing $rtvedit\n";
system($rtvedit);
#=cut

mkDvd.pl

This script takes the final edited mpeg from mkEdits.pl (ending in 1.mpg) and turns it into an mpeg file that a DVD player can read.

#!/usr/bin/perl

my $in = $ARGV[0];

if ( $in =~ /^\s*$/ )
{
        print "Enter base path/filename of show files: ";
        chomp( $in = <STDIN> );
}

my $mpg1 = $in . "1.mpg";
my $dvd = $in . "_dvd";

if ( $in =~ /^\s*$/ or !-f "$mpg1" )
{
        die "$mpg1 not found\n";
}

#=head2
my $rtvconvert = "/home/test/bin/rtvconvert -d \"$mpg1\" \"$dvd\"";
print "doing $rtvconvert\n";
system($rtvconvert);
#=cut

my $mpgout = $dvd . ".mpg";
my $m2v = $dvd . ".m2v";
my $mp2 = $dvd . ".mp2";

#=head2
my $mplex = "mplex -f 8 -o \"$mpgout\" \"$m2v\" \"$mp2\"";
print "doing $mplex\n";
system( $mplex );

print "Removing $m2v\n";
unlink "$m2v";
print "Removing $mp2\n";
unlink "$mp2";

print "\nNOTE: final mpeg to be used for DVD is $mpgout\n";
#=cut


todvd.pl

  • For converting non-replay mpg or avi or other video files (such as for the THX image, etc.) into a format dvdauthor will like, you may want a script like this:
#!/usr/bin/perl

my $filename = $ARGV[0];

if ( $filename =~ /^\s*$/i )
{
        print "Enter filename to transform: ";
        $filename = <STDIN>;
        chomp $filename;
}
if ( $filename =~ /^\s*$/ or ! -f $filename  )
{
        die "file $filename doesn't exist or not specified\n";
}

my $fileshort = $filename;
if ( $filename =~ /^(.+)\.(.+)$/ )
{
        $fileshort = $1;
}

my $transcode = "transcode -i $filename -y ffmpeg --export_prof dvd-ntsc --export_asr 2 -o $fileshort -D0 -s2 -m $fileshort" . ".ac3 -J
 modfps --export_fps 29.97";

print "Will do $transcode\n";

system($transcode);


my $mplex = "mplex -f8 -o " . $fileshort . "_dvd.mpg " . $fileshort . ".m2v " . $fileshort . ".ac3";

print "Will do $mplex\n";

system($mplex);

print "Removing $fileshort" . ".m2v\n";
unlink $fileshort . ".m2v";
print "Removing $fileshort" . ".ac3\n";
unlink $fileshort . ".ac3";

print "\nFinal image to be used on DVD is $fileshort" . "_dvd.mpg\n";


mkMenu.pl

  • you would probably like a script for putting together a jpeg image with button highlight/select and audio for the menus:
#!/usr/bin/perl


#---------------------get all necessary input

# still jpg image for menu

my $jpeg = $ARGV[0];
if ( $jpeg =~ /^\s*$/ )
{
        print "Enter background jpg image file: ";
        chomp( $jpeg = <STDIN> );
}
if ( $jpeg =~ /^\s*$/ or !-f $jpeg )
{
        die "No background image!\n";
}
my $jpegshort = $jpeg;
if ( $jpeg =~ /^(.+)\.(.+)$/ )
{
        $jpegshort = $1;
}

# audio for menu
my $mp3 = $ARGV[1];
if ( $mp3 =~ /^\s*$/ )
{
        print "Enter mp3 or other audio file: ";
        chomp( $mp3 = <STDIN> );
}
if ( $mp3 =~ /^\s*$/ or !-f $mp3 )
{
        die "No audio!\n";
}

# number of frames in menu video
my $frames = $ARGV[2];
if ( $frames !~ /^[0-9]+$/ )
{
        print "Enter number of frames for background image.\n";
        print "Remember, this is > 29.97 fps times the number of seconds of your audio file: ";
        chomp( $frames = <STDIN> );
}
if ( $frames !~ /^[0-9]+$/ )
{
        die "No frame value!\n";
}

# highlight image
my $highlight = $ARGV[3];
if ( $highlight =~ /^\s*$/ )
{
        print "Enter highlight png file (default $jpegshort" . "_highlight.png): ";
        chomp( $highlight = <STDIN> );
}
if ( $highlight =~ /^\s*$/ )
{
        $highlight = $jpegshort . "_highlight.png";
}
if ( !-f $highlight )
{
        die "No highlight file!\n";
}

# select image
my $select = $ARGV[4];
if ( $select =~ /^\s*$/ )
{
        print "Enter select png file (default $jpegshort" . "_select.png): ";
        chomp( $select = <STDIN> );
}
if ( $select =~ /^\s*$/ )
{
        $select = $jpegshort . "_select.png";
}
if ( !-f $select )
{
        die "No select file!\n";
}

#------------------------ make ac3 audio file from audio input

# figure out pre-extension and extension for audio filename
my $audioshort = $mp3;
my $audioext = "";
if ( $mp3 =~ /^(.+)\.(.+)$/ )
{
        $audioshort = $1;
        $audioext = $2;
}

my $do_unlink_ac3 = 0;
my $ac3 = $mp3;

# convert to ac3 if not already
if ( $audioext !~ /^\s*ac3\s*$/i )
{
        $do_unlink_ac3 = 1;
        $ac3 = $audioshort . ".ac3";

        my $do_unlink_wav = 0;
        my $wav = $mp3;
        # convert to wav if not already
        if ( $audioext !~ /^\s*wav\s*$/i )
        {
                $do_unlink_wav = 1;
                $wav = $audioshort . ".wav";
                my $wavconv = "ffmpeg -i \"$mp3\" -f wav \"$wav\"";
                print "doing $wavconv\n";
                system($wavconv);
        }

        # Use 'normalize' to make audio softer/louder if necessary:
        # my $normalize = "normalize -a -10dB \"$wav\"";
        # print "doing $normalize\n";
        # system( $normalize );

        # Convert to AC3 audio:
        my $toac3 = "ffmpeg -i \"$wav\" -ab 224 -ar 48000 \"$ac3\"";
        print "doing $toac3\n";
        system($toac3);

        if ( $do_unlink_wav )
        {
                print "Removing $wav\n";
                unlink "$wav";
        }
}

# If you do not want any audio present in your menu, it is still necessary to create
# a silent audio file for mplex so the DVD menus will work correctly. Like this:
# For PAL:
#dd if=/dev/zero bs=4 count=1920 | toolame -b 128 -s 48 /dev/stdin menu_audio.ac3

#For NTSC:
#dd if=/dev/zero bs=4 count=1601 | toolame -b 128 -s 48 /dev/stdin menu_audio.ac3


#-----------------now make video of the still menu image

my $m2v = $jpegshort . ".m2v";
my $jpegtovid = "jpeg2yuv -n $frames -I p -f 29.97 -j \"$jpeg\" | mpeg2enc -n n -f8 -a2 -o \"$m2v\"";
print "doing $jpegtovid\n";
system( $jpegtovid );


#----------------- mux with audio
my $mpg = $jpegshort . ".mpg";
my $mplex = "mplex -f8 -o \"$mpg\" \"$m2v\" \"$ac3\"";
print "doing $mplex\n";
system( $mplex );

#-------------------- make a temporary spumux file
unless ( open( SPUMUX, ">spumux.xml" ) )
{
        print "Removing $m2v\n";
        unlink "$m2v";
        print "Removing $mpg\n";
        unlink "$mpg";
        die "Could not open spumux.xml for writing\n";
}

print SPUMUX << "OUT";

<subpictures>
        <stream>
                <spu start=\"00:00:00.0\" end=\"00:00:00.0\"
                        highlight=\"$highlight\"
                        select=\"$select\"
                        autooutline=\"infer\"
                        autoorder=\"rows\"/>
        </stream>
</subpictures>

OUT

#-----------------------spumux it
my $final = $jpegshort . "_final.mpg";
my $spumux = "spumux spumux.xml < \"$mpg\" > \"$final\"";
print "doing $spumux\n";
system( $spumux );

print "Removing spumux.xml\n";
unlink "spumux.xml";
print "Removing $m2v\n";
unlink "$m2v";
print "Removing $mpg\n";
unlink "$mpg";
if ( $do_unlink_ac3 )
{
        print "Removing $ac3\n";
        unlink "$ac3";
}

print "\nThe final menu mpeg file is $final\n";


dvdauthor.xml.example

  • an example dvdauthor file
  • this one has a lead-in thx video (simpsons) that you would get if you hit 'top menu' on your remote. it then jumps to the root menu.
  • the root menu is the first one. It lists all the titles.
  • I have a second menu here for chapters. The two menus link to each other via jump commands.
  • the jump cell 1 causes each menu to loop
<dvdauthor dest="DVD">
        <vmgm>
                <menus>
                        <pgc entry="title">
                                <vob file="/path/to/thx_simpsons_dvd.mpg"  chapters="0,0:10,0:20,0:30"/>
                                <post> jump titleset 1 menu entry root; </post>
                        </pgc>
                </menus>
        </vmgm>
        <titleset>
                <menus>
                        <pgc entry="root">
                                <button> jump title 1 chapter 1; </button>
                                <button> jump title 2 chapter 1; </button>
                                <button> jump title 3 chapter 1; </button>
                                <button>jump menu 2</button>
                                <vob file="/path/to/testMenu_final.mpg"/>
                                <post> jump cell 1; </post>
                        </pgc>
                        <pgc>
                                <button>jump title 1 chapter 1; </button>
                                <button>jump title 1 chapter 2; </button>
                                <button>jump title 2 chapter 1; </button>
                                ...etc
                                <button>jump menu entry root; </button>
                                <vob file="/path/to/chapterMenu_final.mpg"/>
                                <post> jump cell 1; </post>
                        </pgc>
                </menus>
                <titles>
                        <pgc>
                                <vob file="/path/to/first_video_dvd.mpg" chapters="0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00"/>
                                <post> call menu; </post>
                        </pgc>
                        <pgc>
                                <vob file="/path/to/second_video_dvd.mpg" chapters="0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00"/>
                                <post> call menu entry root; </post>
                        </pgc>
                        <pgc>
                                <vob file="/path/to/third_video_dvd.mpg" chapters="0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00"/>
                                <post> call menu; </post>
                        </pgc>
                </titles>
        </titleset>
</dvdauthor>

    • above has the THX simpsons file as a lead-in, then jumps to the menu
    • menu has three buttons, each leading to a different video. Order depends on placement of boxes in the highlight file, generally things to the left and higher going first.
    • each video has chapter stops every 5 minutes
    • at the end of each video, it jumps back to the menu.


Converting Replay TV shows to DVD format

  • get show files from wherever DVArchive dumps them (eg /root/dvarchive/Local_Guide/, if you run DVArchive as root)
  • run mkText.pl OR run gopdit on the .mpg file to get edit points (export final data as RTV .txt) OR use cinelerra to manually determine the edit points and edit a txt file for it.
    • if using mkText.pl enter base dir/base name, eg if your show files were named pickle.mpg, pickle.evt, etc: GoodEats/AmericanPickle/pickle
    • answer the question about program segment length (or use default)
  • examine the resulting .txt file, edit if you want (if it looks wrong)
  • iterate running mkEdits.pl and editing the .txt file by hand until you're satisfied the commercial removal is all correct.
  • make sure your edited video file ends in '1.mpg' so it will be picked up by the next script.
  • run mkDvd.pl
  • double check that base_dvd.mpeg is OK; that is, audio/video are synced. Note final location of mpg file to be used for dvdauthor.

THX logos in the Root Section of DVD

  • DVD players start by reading the root section of the DVD. You can stick a THX image in there to play and also have a root menu to go to other menus (or just skip to the first titleset menu--see dvdauthor section).
  • A neat one to use is the Simpsons THX parody. Try googling for 'Simpsons THX' and obtain an .mpg or avi (highest quality one you can find).
  • Use the todvd.pl script mentioned above to convert to a dvd-appropriate format.

Creating menus

graphics and button selections

In gimp:

  • Make a new image of size 720x480, with a resolution of 81dpi in the x-axis & 72dpi in the y-axis. (NTSC)
  • Right click on the image, select Image -> Alpha -> Add channel. (note: may be different now, check layers menu)
  • Right click on the image, select image -> Layers -> Layers, Channels & Paths (note: may be different now, check layers menu)
    • call the layer 'buttons'
  • open the layer tool so you can select each layer
  • Select the background layer and add all graphics you'd like for the menu
    • In KDE, you can grab screenshots using KSnapshot
      • set up xine's video settings for xshm (or other module that will send output to X11, or else KSnapshot won't capture it)
      • capture the window using KSnapshot
      • you can then save it and pull it into gimp for menu graphics.
  • select the button layer and draw button outlines around the objects you'd like to be selectable in the menu
    • help for this here
    • basically, select a rectangle or circle, fill with a bright (highlight) color, select->shrink by about 5 pixels, then image->clear selection
  • hide the button layer: select the button layer, set the alpha (opacity?) slider all the way down
  • select the background layer and do file-> save as a jpeg file (important that it be .jpg)
  • turn opacity all the way down to hide background layer
  • go back to button layer, slide opacity all the way up (show buttons)
  • file-> save as png file (like image_highlight.png) (important that it be png)
  • with button layer still selected, change the color of the buttons to a select color (what color it is if you click on the button). Image -> Colors -> Color map rotation. Once changed, save the layer as another png, like image_select.png (important that it be png)
  • animated menu explanation

audio

  • obtain an mp3 or other audio file to be used for the menu
    • note the length of the audio in seconds. You'll need this to tell the mkMenu.pl script how many frames to make the menu (so the video is long enough to play the entire song).
  • if you just want silence, make a file with no sound in it (you need something for the final menu mpg, even if it's just silence:
 dd if=/dev/zero bs=4 count=1601 | toolame -b 128 -s 48 /dev/stdin menu_audio.ac3
    • that should work for NTSC; PAL will vary

putting them together

  • run mkMenu.pl (above)

Combining Files into DVD files (VIDEO_TS) and an iso File, Writing to a DVD

  • cp dvdauthor.xml.example to a dvdauthor.xml in the directory where you'd like to write the DVD files
  • edit dvdauthor.xml to link together menus/files
    • you can put chapter stops wherever you want them; you may want to watch the videos to figure this out, or just stick them every few minutes; see the .xml file for details. You may especially want to do this for the THX image so it's easily skipped over.
    • if not doing a top level menu/THX video out front, replace vmgm section with:
 <vmgm />
  • dvdauthor -x dvdauthor.xml
  • test by doing xine dvd:/path/to/show/test/DVD/VIDEO_TS (created by dvdauthor)
  • when you're happy with the results, make an ISO file to be burned to a DVD:
    mkisofs -dvd-video -o dvd.iso DVD
    • came from cdrtools
  • test iso
    • make a directory /mnt/iso, then
      mount -o loop -t iso9660  filename.iso /mnt/iso
    • possibly udf instead if iso9660? although, iso9660 worked for me
    • xine dvd:/mnt/iso
  • now write the .iso file to a DVD
    • in linux, growisofs -dvd-compat -Z /dev/dvd=/path/to/iso
    • for windows, make sure you have the Windows Resource Toolkit (google for it or check microsoft.com for details), as it includes dvdburn.exe
      • run dvdburn dvd_drive iso_file
        • add an /erase for DVD-RW; DVD+RW is formatted prior to writing and DVD-R and DVD+R are write once so can't be erased


Going back from iso file to mpg files

Say you want to undo an iso and get the mpg files back, in a format that dvdauthor can use again. Here's what you do:

  • Mount the iso file:
    • mount -o loop -t iso9660 iso_file.iso /mnt/iso
  • Pull video file from iso:
    • mplayer -dvd-device /mnt/iso -dumpvideo -dumpfile file.m2v
  • Pull audio vile from iso:
    • mplayer -dvd-device /mnt/iso -dumpaudio -dumpfile file.ac3
  • multiplext them together
    • the separation and mplex seem to be necessary or dvdauthor won't recognize the file
    • mplex -f 8 -o file.mpg file.m2v file.ac3
Personal tools