PDA

View Full Version : Overnight extraction and MP4 encoding on a PC.



gstewart
10-19-2005, 03:30 PM
Folks,

I've written a nasty perl script to automatically extract a specified show, then encode it to MPEG4 (PSP and now iPod) format. It works very reliably.

I wrote this so that I could create a scheduled job on my windows PC and I'd have a show the next morning ready to walk out the door with. It uses various tools (ffmpeg, mplayer, tytools, etc). I was tired of manually extracting and encoding shows, and the time that would take.

I'm not really sure how technical the general audience is (seems to be a wide range). Is anyone interested in this type of functionality / howto?

I'd be happy to invest more time and effort in cleaning up the code, and generating a windows binary (exe) if there was some interest.

My apologies if this is old news, but when I was trying to set this up, I had to research several sources to first discover how to extract a show, then how to encode it, and finally a way to automate the entire process overnight.

-g

saltydog4791
10-19-2005, 09:24 PM
Sure, I would love to have a look at your code. I am also working on some perl script right now to enable some of the same stuff on my Mac. I am using perl also and some of the same binaries as you. I am almost there but kind of stuck, so I would love to take a look at what you have so far.

saltydog4791

jbolter
10-20-2005, 04:36 AM
i am very interested! just got a psp and was wondering how i was going to get my stuff on there easily/automatically, a plugin for etivo would be pretty sweet too... :)

gstewart
10-20-2005, 11:59 PM
Ok, thanks for the feedback.

Prerequisites:
tytools (default install is ok)
ffmpeg (easily installed via PSP Video9 installer)
mplayer (service / daemon running on the TiVo and, client installed on the PC)



#!C:\perl\bin\perl.exe

#
# This script written by G Stewart (gstewart@gmail.com), to parse for most recent Tivo program identifier,
# then convert downloaded TY stream to MPG4 PSP format. Primarily for use as a scheduled job.
#

use strict;
use Time::Local;
use Getopt::Long;

my (@pid, @readme);
my (%show, %readme);
my ($grpid, $entries, $sid, $i, $j, $showname, $pid, $readme, $fh1, $fh2, $output);$i=0;

my $tivoip="10.0.10.27";

my $tytoolsloc="C:\\Progra~1\\tyStudio\\typrocess.exe";
my $ffmpegloc="C:\\Progra~1\\pspvideo9\\apps\\ffmpeg.exe";
my $mplayerloc="C:\\Progra~1\\mplayer-tivo\\mplayer.exe";
my $recloc="S:\\My Documents\\My TiVo Recordings\\";

my $mp4name = time;
$mp4name = substr($mp4name, 5);

GetOptions ("show=s" => \$showname);
die "Please enter a show title --show \"Title\" $!\n" unless defined $showname;

$showname = substr($showname, pos($showname), 20);

my $get_list="$mplayerloc tivo://$tivoip/list |";
open($fh1, $get_list) or die "Can't run program: $!\n";

while (<$fh1>) {
$output=$_;
if (/$showname/gi){
my $grpid = substr($_,1,10);
for( $grpid ){s/^\s+//;s/\s+$//;}
$show{$i}=$grpid;
$i++;
}
}
close $fh1;

$entries=$i;
$sid=$show{0};

for ($i=0; $i<=$entries; $i++){
if ($show{$i}>$sid){
$sid=$show{$i};
}
}

if ($sid==''){return;}

my $get_ty="$mplayerloc -dumpfile \"$recloc"."$showname.ty\" -dumpstream tivo://$tivoip/".$sid." |";

open($fh2, $get_ty) or die "Can't run program: $!\n";
while (<$fh2>) {
$output=$_;
}
close $fh2;

system($tytoolsloc, "-i \"$recloc"."$showname.ty\" -o \"$recloc"."$showname.mpg\" -mplex { -f 8 } -demux");
unlink ("$recloc"."$showname.ty");

system($ffmpegloc,"-y -i \"$recloc"."$showname.mpg\" -title \"$showname\" -bitexact -vcodec h264 -coder 1 -g 250 -croptop 2 -cropbottom 0 -cropleft 0 -cropright 0 -s 320x240 -r 29.97 -b 768 -bufsize 768 -aspect 16:9 -acodec aac -ac 2 -ar 48000 -ab 64 -vol 180 -f psp \"$recloc"."MAQ".$mp4name.".MP4\"");
unlink ("$recloc"."$showname.mpg");


..and here's the batch file that kicks of the file dump, conversion, then copy over to the PSP memory stick.


@ECHO OFF
del "S:\My Documents\My TiVo Recordings\MAQ*.MP4" >> "S:\My Documents\My TiVo Recordings\trouble.log"

"C:\Progra~1\TivoPSP\tivo_extract_bedroom.pl" --show "The Tonight Show Wit"
"C:\Progra~1\TivoPSP\tivo_extract_lounge.pl" --show "Futurama"

IF EXIST "E:\MP_ROOT\100ANV01\MAQ*.MP4" (
GOTO filecheck
) ELSE (
echo "File NOT copied to USB connected PSP" >> "S:\My Documents\My TiVo Recordings\trouble.log"
)

C:\Progra~1\TivoPSP\DISK_IN.EXE G
IF %ERRORLEVEL%==0 GOTO filecheck

echo "File NOT copied to Flash card reader" >> "S:\My Documents\My TiVo Recordings\trouble.log"
GOTO end

:filecheck
IF EXIST "G:\MP_ROOT\100ANV01\MAQ*.MP4" (
GOTO flash
) ELSE (
echo "File NOT copied to Flash card reader" >> "S:\My Documents\My TiVo Recordings\trouble.log"

)

GOTO end

:flash
cd G:\MP_ROOT\100ANV01
g:
echo Flash copy in progress
del G:\MP_ROOT\100ANV01\MAQ*.MP4 >> "S:\My Documents\My TiVo Recordings\trouble.log"
copy "S:\My Documents\My TiVo Recordings\MAQ*.MP4" "G:\MP_ROOT\100ANV01\" >> "S:\My Documents\My TiVo Recordings\trouble.log"
echo "File copied to Flash card reader" >> "S:\My Documents\My TiVo Recordings\trouble.log"
GOTO end

:usb
cd E:\MP_ROOT\100ANV01
e:
echo USB copy in progress.
del E:\MP_ROOT\100ANV01\*.MP4 >> "S:\My Documents\My TiVo Recordings\trouble.log"
copy "S:\My Documents\My TiVo Recordings\MAQ*.MP4" "E:\MP_ROOT\100ANV01\" >> "S:\My Documents\My TiVo Recordings\trouble.log"
echo "File copied to PSP via USB" >> "S:\My Documents\My TiVo Recordings\trouble.log"
:end

You'll need to modify the batch file and the Perl scripts above to point to the appropriate location on your system.

Finally, DISK_IN.EXE is a little utility that validates a Flash Memory card is available to write. This is useful if you forget to put in the PSP memory stick the batch file won't crash.

thor240z
04-07-2006, 01:29 PM
gstewart,

I know this is a little old, but have you made any progress in a Windows binary? Just wanted to know, before I decide to dive into perl.

I'm just basically looking to have the daily local news & sportscenter(from the previous night) ready to go in the morning, and just drag it to my ipod for watching during the morning commute.

Thx.

mebgoin
04-07-2006, 08:27 PM
FWIW there's a plugin for etivo that will encode in in MP4 format and even upload to your ipod. Might want to check it out.