#! /usr/bin/perl # # AUTHOR: Peter Verhas (http://peter.verhas.com) # DATE: 2004.10.08 # CONTENT: # I needed to edit mpeg-1 files captured in VCD format from my pinnacle PCTV to # cut off ads. I used VirtualDub for ages to edit AVI, but it can not output # MPEG-1. I also wanted 'direct stream copy' speed. I did not need any filter or # any other advanced edition option. # # The first solution was to use VirtualDub to seek the start and end times of # the segments to copy from the original mpeg-1 file to the output and then use # the mpgtx (also GPL) tool from command line to perform the rest. # # After that I realized that all information can be gathered from the jobs file. # All I need to do the editing, save as a job and then have it executed by mpgtx # after some conversion. # # I attach a short Perl script that reads the VirtualDub jobs file, creates the # mpgtx command line and executes it. # # It actually seeks undocumented Sylia command 'AddRange', thus I have to # mention that I used VirtualDub 1.5.10 Seems that these commands change # undocumented by time :-) # # This code is protected by GPL. # # KNOWN BUGS: # the program does not handle accented character file names # use strict; # convert a frame to hour:min:sec.millisec format # it is assumed that the frame rate is 25fps sub frame2timestring { my $frame = shift; # convert frame to millisec my $ms = ($frame*1000/25); my $sec = int($ms / 1000); $ms = $ms - $sec * 1000; my $min = int($sec/60); $sec = $sec - $min *60; my $hour = int($min/60); $min = $min - $hour*60; return "$hour:$min:$sec.$ms"; } open(F," ){ if( /VirtualDub\.Open\((\"[^"]+\")/i ){ $input = $1; $countOpens++; next; } if( /VirtualDub\.SaveAVI\((\"[^"]+\")/i ){ $output = $1; $output =~ s/\.avi\"$/\.mpg\"/i; next; } if( /VirtualDub\.subset\.AddRange\((\d+),(\d+)/ ){ my $start = $1; my $len = $2; $start = 1 if $start == 0; $ranges .= '[' . frame2timestring($start) . '-' . frame2timestring($start+$len) . '] '; } } close F; if( $countOpens > 1 ){ print "There are more than 1 jobs in the job file.\n"; print "Press any key to exit ...\n"; <>; exit 1; } print "mpgtx -j -o $output $input $ranges\n"; `mpgtx -j -o $output $input $ranges`;