#!/usr/bin/perl # Copyright (C) 2012 Siva Dirisala $bcmd = "-target ntsc-dvd -b 5000000 -ar 48000 -ab 128k -ac 2 -acodec ac3 -vcodec mpeg2video -threads 8"; if($#ARGV < 1) { print < EOF exit(0); } if(! -e $ARGV[1]) { mkdir($ARGV[1]); } $t1 = time(); $catcmd = "cat "; @durations; open(FILES,$ARGV[0]); while(chomp($_ = )) { $infile = $_; #$infile =~ s/'/\\'/g; $infilebase = $infile; $infilebase =~ s/.*\///g; $infilebase =~ s/[.]([^.]+)$//; $outfile = "$ARGV[1]/${infilebase}.vob"; $catcmd .= "\"$outfile\" "; $cmd = "ffmpeg -i \"$infile\" $bcmd \"$outfile\""; if(! -e $outfile) { print "$cmd\n"; system($cmd); } $cmd = "ffmpeg -i \"$outfile\" 2>&1 | grep --color=never Duration | sed -e 's/.*Duration: \\([^,]*\\).*/\\1/' | awk -F':' '{ print \$1*3600+\$2*60+\$3 }'"; $duration = `$cmd`; chomp($duration); push @durations,$duration; } $t2 = time(); print(($t2-$t1),"sec\n"); close(FILES); print "$catcmd\n"; print("chapters: "); $ctime = $durations[0]+0.005; print(sec2str(ceil($ctime))); for(my $i=1;$i<$#durations;$i++) { print(","); $ctime += $durations[$i]+0.005; print(sec2str(ceil($ctime))); } print "\n"; $ctime = 0; $ind = 1; map { $ctime += $_+0.005; printf("%2d %8.3f %8d %8s\n",$ind,$ctime,ceil($ctime),sec2str(ceil($ctime))); $ind++; } @durations; # support methods sub d2 { my ($n) = @_; if($n < 10) { return "0$n"; } else { return "$n"; } } sub sec2str { my ($secs) = @_; my $t; if($secs >= 3600) { $t = d2(int($secs/3600)).":"; $secs -= int($secs/3600)*3600; } if($t or $secs >= 60) { $t .= d2(int($secs/60)).":"; $secs -= int($secs/60)*60; } $t .= d2($secs); return $t; } sub ceil { my ($n) = @_; if($n == int($n)) { return $n; } else { return int($n+1); } }