Monthly Archives: December 2011

Bulk DVD Creation With Tovid

Today I’m going to show you how I automated the DVD creation part of the VHS home video conversion process. I’m assuming you have already captured the video to your computer somehow, and just want to make DVDs with your captured video.

Note: All of these tools are Linux command line tools. Less convenient than a GUI, but much more appropriate for bulk operations and scripting.

Preparing the Videos

Tovid can take any video format and make a DVD from it by calling ffmpeg and other libraries when it needs to. In practice, I find that tovid and ffmpeg fight like sibling when they get along it’s true love, but when they fight things get broken.

Encoding is the slowest part of making a DVD, so we’ll do it separately. This way we can tweak the DVD quickly without re-encoding each time. FFMpeg can do it with the command:

ffmpeg -i SourceFile.whatever -target ntsc-dvd outputfile.mpg

This will produce mpeg2 files which don’t need to be further encoded in order to be put on a DVD.

Splitting Videos

If the resulting outputfile.mpg is too big for a DVD, you will need to split it. FFMpeg can split your file using a starting second (-ss) and a time (-t).  With this syntax you can break your file into as many pieces as you need to fit them on a DVD.

ffmpeg -i SourceFile.whatever -ss 0 -t 7200 -target ntsc-dvd outputfile-part1.mpg
ffmpeg -i SourceFile.whatever -ss 7201 -target ntsc-dvd outputfile-part2.mpg

Creating the Metadata

Tovid will want a couple of pieces of metadata, depending on what menu options you choose. Main titles, submenu titles and a disc title.

Since I was digitizing family videos, I wanted the disc title to be the years spanned. So I created a CSV file with 4 columns. the year would become the disc title.

filename,year,long description,short description
SourceFile.whatever,1990,The family goes sledding at Ice Hill,Sledding

The Tovid Wrapper Script

I know Tovid is already a wrapper for dvdauthor, ffmpeg and whatever other tools it uses behind the scenes, but what’s another layer, right?

I put all of my videos, the CSV file and this script in a folder:

#!/usr/bin/env php
<?php

/*
 * @brief Make as few DVDs as needed to fit all of the videos listed in a CSV file
 *
 * Copyright Michael Moore <[email protected]>
 * This script assumes that
 *      * All of the videos have already been encoded into mpeg2 format for DVD
 *      * All of the videos paths are relatie to INPUTDIR
 *
 * As many videos are fit into one DVD as possible. Videos are added in the order
 * listed in the CSV file. If a video is too big for a DVD the script will tell
 * you, and then exit. DVDs are named either "year", "year1 - year2" or
 * "year disc n", using the year from the CSV.
 *
 * Requires php-cli installed so that we can fork processes.
 *
 * Our metadata.csv file format:
 * pathtofile,year,looooooooooooong title here,short title
 *
 * We assume the file has a header row.
 */

//
//         Settings
//
define('DVDSIZE',8500000000); // Our estimate of the number of bytes available on a DVD+R DL
define('MENUOVERHEAD',45*1024*1024); // Generous leeway for the menu system
define('INPUTDIR',"/home/myuser/videos/input/"); // starting point for all file paths. Use / for abs. paths
define('TMPDIR','/tmp/tovid/'); // Where do you want the tmp files?
define('OUTDIR',"/home/myuser/videos/DVDs/"); // Destination?
define('MAXCHILDREN',5); // How many tovids to run simultaneously? Probably 1-2 less than the # of cores available?
$fh = fopen(INPUTDIR.'/metadata.csv','r');

//
//         No Lifeguard on duty!
//
@mkdir(TMPDIR);
chdir(TMPDIR); // Tovid likes to dump in the cwd. Chdir so that tovid dumps its temp files somewhere usefulish

define('MAXVOB',1073709056); // The max size of a single VOB
global $pids;
$pids = Array();

$currentdvdsize = MENUOVERHEAD;
$currentdvdfiles = Array();
fgetcsv($fh); // remove header from csv file
while($file = fgetcsv($fh)){

    // Fast check!
    if((filesize(INPUTDIR .'/'. $file[0]) + $currentdvdsize) > DVDSIZE){
    makeDVD($currentdvdfiles); // Make a DVD!

    $currentdvdfiles = Array(); // Reset!
    $currentdvdsize = MENUOVERHEAD;
    }

    $currentdvdfiles[] = $file;

    // Calculate how much space this video will take on the disc
    // dvdauthor seems to:
    // 1) Never mix videos in the same VOB
    // 2) Make all VOBs except the last one come out to MAXVOB size (the last one can be whatever size smaller than MAXVOB)
    $currentdvdsize += (MAXVOB * ceil(filesize(INPUTDIR .'/'. $file[0])/MAXVOB));

    if($currentdvdsize > DVDSIZE){
    die("It looks like {$file[0]} is too big to fit on a DVD!\n");
    }
}

// Make any remnants
if(count($currentdvdfiles) > 0){
    makeDVD($currentdvdfiles);
}

function makeDVD($files){
    global $pids;

    // Make title
    $last = count($files) - 1;
    if($files[0][1] != $files[$last][1]){
    $title = "{$files[0][1]} - {$files[$last][1]}";
    }else{
    $title = "{$files[0][1]}";
    }

    $count = 2;
    $origtitle = $title;
    while(file_exists(OUTDIR . "/$title")){
    $title = "$origtitle disc $count";
    $count++;
    }

    // List of files
    $input = Array();
    $shorttitles = Array();
    $fulltitles = Array();
    foreach($files as $file){
    $input[] = INPUTDIR . "/{$file[0]}";
    $fulltitles[] = $file[2];
    $shorttitles[] = $file[3];
    }

    $cmd = "tovid disc
    -files  " . implode(" ",array_map('escapeshellarg',$input)) . "
    -titles " . implode(' ',array_map('escapeshellarg',$shorttitles)) . "
    -menu-title " . escapeshellarg($title) . "
    -menu-fontsize 18
    -title-color '#ff7700'
    -title-stroke black
    -titles-fontsize 18
    -titles-color '#ff7700'
    -showcase-titles-align east
    -rotate 5
    -wave default
    -submenus
    -submenu-titles " . implode(' ',array_map('escapeshellarg',$fulltitles)) . "
    -submenu-title-color '#ff7700'
    -submenu-stroke black
    -loop 0
    -submenu-length 20
    -noask
    -out " . escapeshellarg(OUTDIR . "/$title");

    // Now wait for our turn...
    while(count($pids) >= MAXCHILDREN){
    $status = NULL;
    $exited_pid = pcntl_wait($status);            
    if(pcntl_wexitstatus($status) != 0){
        print "FAILURE IN " . TMPDIR . "/tovid.$exited_pid!!!\n{$pids[$exited_pid]}\n";
    }
    unset($pids[$exited_pid]);
    }

    $cmd = str_replace("\n",' ',$cmd);

    print "LAUNCHING!!!\n$cmd\n";

    $pid = pcntl_fork();
    if($pid == -1){
    die("COULDNT FORK!");
    }else if($pid){
    $pids[$pid] = $cmd;
    sleep(3); // give tovid a chance to claim its temp directories
    }else{
    $cmd .= " > " . TMPDIR . "/tovid." . getmypid() . " 2>&1";
    exec($cmd);
    exit();
    }
}

Using the Script

Save the PHP script above to a file named tovidBatch.php and make it executable.

Edit the defined constants to fit your directories and output media (DVDSIZE). If desired, edit the tovid disc command to build your DVDs the way you want them.

Finally, run (on a command line)

php tovidBatch.php

Your videos are on their way!

Sample DVD Menu
Sample DVD Menu
Posted in Computers, Something Interesting | Tagged , , , , , , , , , , | Leave a comment

Don’t buy HP laptops

I bought an HP Pavilion dv7 (dv7t-4100) a little less than a year ago (March, 2011)

It has been a big disapointment and I do not plan on buying an HP laptop again and can’t recommend that anyone else buy one either.

I chose the dv7 because I needed something with some processing power. My dv7 has anIntel i7 clocked at 1.87Ghz, with 6 gigs of RAM.

Update (January, 23, 2011)

The screw that was loose on the case eventually came out. Within a day the hinge near where the screw fell out of broke, and I could hear a piece of metal shaking around inside the case. The warranty expires at the end of March.

The HP support person I spoke with was professional in the way that a police officer who pulls you over for speeding is professional. He kept trying to get me to say that I had dropped, bumped or otherwise abused the laptop and warned me multiple times that if I sent it in and they found signs of abuse that I would have to pay for repairs.

Still, 50 minutes later and a box was on its way to my house. The box took 2 days to get here, 2 days to get to HP, and they must’ve fixed it that day because I got it back 3 days after that.

I had only complained about the hinge. The loose power plug and missing keyboard/worn off keyboard I had chalked up to wear-and-tear and didn’t expect them to fix under warranty, but they did.

So, do I love HP laptops now? No, but I’m happy with how their warranty service turned out, and hopeful that I won’t have these problems once the warranty expires!

 

The HP Pavilion dv7 Overheats

Unfortunately, the dv7 is inadequately cooled. When I start the computer temperature of the computer quicky reaches 75-78 degress (Celcius) and the fans are running loudly. As soon as I start a couple of desktop applications (Firefox, Pidgin, Thunderbird and a terminal) the temperature reaches about 85.

When I got this machine, I was excited because from time to time I rip VHS tapes (old homevideos) and convert them to DVDs for family members. The encoding process is long and slow, and I expected to benefit from all 4 cores.

Sadly, I can’t even run a video encoder at full speed on a single core without the computer overheating, and shutting down.  The computer shuts down if it reaches 100 degrees. I have to run ffmpeg (or mencoder) at 55% CPU usage (of one core) in oder for the fans to keep up with the CPU.

I’m effectivly stuck with a single core 1.03 GHz (55% of a single 1.87GHz core) computer since I can’t use more than that at once. Extremely disapointing.

TIP: If you're in a similar situation, and you're on Linux, you
can use the program cpulimit throttle a specific process or
program. When I try to encode video on Windows (in iTunes) the
computer overheats no matter what I do.

NOTE #1:  This happens in both Windows AND Linux, so it’s not some weird Linux bug. I nearly always use my laptop on a hard surface — and I have to have it on something hard with great airflow if I want to even think about encoding a video.

NOTE #2: My fans and vents are clean. I can see through them to the fans, and have used compressed air on them anyways just in case.

The HP Pavilion dv7 Has a Low Quality Keyboard

I admit that I use  my computer more than most people do. Between work and hobbies, it’s not unusual for me to be on my computer 10-12 hours a day, and often more.

This laptop however, is the first one that I have ever worn the letters off the keys. It is also the first one that I have ever had a key spring break during normal use.

Luckly the dv7 comes with a numeric keypad which I don’t use, so I took the keyspring from one of those keys and repaired my broken key.

Again, very disapointing

The HP Pavilion dv7 Case is Poorly Built

Within a few months of getting my dv7 I noticed that the screen wouldn’t stay in position. It would always settle back an extra inch from where I had pushed it. It turned out that the top plastic piece of the case was coming loose from the bottom piece, which in turn left the lid hinge a little loose.

I tightened the screw on the case, and have had to tighten it again every couple of months.

I’m Done Whining Now

I don’t want/need a replacement from HP badly enough to talk to someone in a call center. I’m just going to keep using this computer until it dies. I’m betting it doesn’t make it a year. My guess is that the threads for the case screw eventually wear out and the screen won’t stay up.

I have a rock-solid reliable P4 desktop computer (an HP, no less!) I can use if this thing goes, and next time I’ll buy something more reliable, like a Thinkpad or a Mac Book.

So, if you’re in the market for a laptop, use extreme caution when buying an HP Pavilion. You might not get as good of a machine as you expect.

Posted in Computers, Something Interesting | Tagged , , , , , , | 2 Comments