--- mplayer-0.99+1.0pre7try2+cvs20060117.orig/TOOLS/mencvcd +++ mplayer-0.99+1.0pre7try2+cvs20060117/TOOLS/mencvcd @@ -0,0 +1,440 @@ +#!/bin/sh +# +# Version: 0.2.2 +# +# Licence: GPL +# +# 2002/09/21 Jürgen Hammelmann +# +# Script: MPlayer Sources (DVD) to (S)VCD ripping and burning +# +# requires: mplayer +# mjpegtools +# vcdimager +# cdrdao +# lame (optionally) +# toolame (optionally) +# sox (optionally) + +for exe in mplayer mpeg2enc mp2enc mplex yuvscaler ; do + if [ -z "`which $exe`" ]; then + echo "ERROR: $exe must be in your path $PATH!" + exit 1 + fi +done +for exe in vcdimager lame cdrdao yuvdenoise sox toolame normalize; do + if [ -z "`which $exe`" ]; then + echo "WARNING: $exe is not found in your path $PATH!" + fi +done + +################################################################################ +# +# 2002/04/11 v0.1.0: first version +# 2002/04/12 v0.1.1: +# 2002/04/14 v0.1.2: +# - handles now multiple vcd's +# - support's mp3 audio as option +# - use of mp2enc/lame instead of toolame because of support +# of resampling and mp3 +# 2002/04/16 v0.1.3: +# - new option "-burnonly" +# - new option "-vbr" +# - removes mpg file after mastering cd image +# (mplayer can read bin images!) +# - bugfixes +# 2002/04/22 v0.1.4 +# - bugfixes / changes +# - more options +# 2002/05/06 v0.1.5 +# - new option "-norm" +# 2002/05/08 v0.1.6 +# - bugfixes +# - new option "-vfr" +# - "-norm" renamed to "-vnorm" +# 2002/05/15 v0.1.7 +# - bugfixes +# - more help +# 2002/05/26 v0.1.8 +# - new option "-sync" +# 2002/06/19 v0.1.9 +# - new option "-mpgonly" +# 2002/09/21 v0.1.10 +# - bug fixes +# - tests now, if the commands are in path and give warnings +# and errors. +# 2002/11/01 v0.2 +# - bug fixes +# - new options: "-sox", "-volume", "-toolame" +# - renamed "-mpg" to "-mpegsrc" +# - default cd size changed to 800mb +# 2002/11/18 v0.2.1 +# - aspect ratio for vcd's, too +# - pulldown mode... +# 2002/12/01 v0.2.2 +# - -normalize +# +################################################################################ +# +# global config section, change them to your needs! + +TMPDIR="." # path to directory for creating temporary files, recommended 2-3GB space + +CDDRV="generic-mmc" # cdrdao: cdwriter driver +CDDEV="--device 0,1,0" # or comment out and create link /dev/cdrecorder + # to your cdwriter dev +CDMAXSIZE=800 + +################################################################################ +AUDIO="audiodump.wav" +VIDEO="stream.yuv" +VCDMODE=2 +SVCDMODE=5 +################################################################################ + +function usage() { + echo "Usage: $HOWCALLED [$HOWCALLED options] [mplayer options]" + echo + echo " is used as basename of the resulting mpg/bin files." + echo + echo "For mplayer options see mplayer help and manual." + echo + echo "$HOWCALLED options:" + echo + echo "-?|-h help." + echo "-a sets the aspect ratio (for SVCD):" + echo " 1 - 1:1 display" + echo " 2 - 4:3 display" + echo " 3 - 16:9 display" + echo " 4 - 2.21:1 display" + echo "-abr output audio bitrate in kbs [224]." + echo "-asr output audio sample rate in Hz [44100]." + echo "-blank cleans cd-rw before burning." + echo "-burnonly burn only the premastered *.cue/*.bin images." + echo "-cdsize maximal size of cd images [800 = 80min raw cd]." + echo "-denoise denoises mpeg stream." + echo "-mp3 outputs audio in mp3 instead of mp2 format." + echo "-mpegsrc don't encode from source, multiplex/burn the " + echo " encoded mpg stream." + echo "-mpgonly do only encoding to mpeg 1/2 format." + echo "-noburn disables burning." + echo "-normalize use 'normalize'." + echo "-overburn enables overburning a cd." + echo "-pulldown enable pulldown mode in output." + echo "-ratio output ratio size of frames, see yuvscaler (1)." + echo "-size x sets output size of frames." + echo "-sox use sox for audio resampling." + echo "-svcdout encode to SVCD format [VCD default]." + echo "-sync set the presentation timestamp offset of video" + echo " stream w.r.t. audio stream (video-audio) in mSec." + echo "-toolame use toolame instead of mp2enc." + echo "-v change amplitude (floating point); less than 1.0" + echo " decreases, greater than 1.0 increases. Use that only" + echo " together with sox!" + echo "-vbr output video bitrate in kbs [VCD:1152, SVCD:2500]." + echo "-vfr sets the frame-rate of the output-stream. Currently" + echo " only the standard MPEG rates are supported:" + echo " 0 - illegal" + echo " 1 - 24000.0/1001.0 (NTSC 3:2 pulldown converted FILM)" + echo " 2 - 24.0 (NATIVE FILM)" + echo " 3 - 25.0 (PAL/SECAM VIDEO / converted FILM)" + echo " 4 - 30000.0/1001.0 (NTSC VIDEO)" + echo " 5 - 30.0" + echo " 6 - 50.0 (PAL FIELD RATE)" + echo " 7 - 60000.0/1001.0 (NTSC FIELD RATE)" + echo " 8 - 60.0" + echo "-vnorm sets the input video norm p, n or s:" + echo " forces the input stream to be treated as PAL|NTSC|SECAM" + echo " regardless of what the stream header might suggest." + echo "-w outputs in wide screen format 16:9." + echo + echo "examples:" + echo + echo "'$HOWCALLED teneriffa teneriffa.avi'" + echo "this creates a VCD from an avi file." + echo + echo "'$HOWCALLED crazy dvd://3 -w':" + echo "encodes and burns dvd title 3 to VCD in 16:9." + echo + echo "'$HOWCALLED carter dvd://1 -sid 0 -aid 128 -ss 3:00 -frames 1500 \\" + echo " -noburn -vnorm n -vfr 1':" + echo "this encodes 1500 frames of dvd title 1 with subtitle 0 and audio stream" + echo "128 starting from 3:00 with frame rate 29.97 fps and input video norm NTSC" + echo "and output frame rate 23.98 fps because of the 3:2 pulldown method in NTSC." + echo + echo "'$HOWCALLED bj -size 640x272 -vf expand=640:480:0:104:0 \\" + echo " -cdsize 645 -noburn bj.avi'" + echo "this example above shows you, how to deal with movies which are not" + echo "created with aspect ratios of 4:3 or 16:9." +} + +HOWCALLED=`basename $0` +if [ $# -le 1 ]; then + usage + exit 1 +fi +case $1 in + -*) + usage + exit 1 + ;; + *) + NAME=$1 + shift 1 + ;; +esac + +cd $TMPDIR +rm -f $VIDEO +rm -f $AUDIO +# create a named pipe for video stream +mkfifo -m 660 $VIDEO + +# some inits +sub="" +size="" +aratio="" +ratio="" +params="" +wide="" +blank=0 +burn=1 +burnonly=0 +mp3=0 +mpgonly=0 +mkstream=1 +abr=224 +abrset=0 +asr=44100 +vbr=1152 +vbrset=0 +denoise="cat -" +vnorm="VCD" +mplexnorm="-f $VCDMODE -m 1 -V -b 46" +imaget="-t vcd2" +yuvin="" +framerate="" +sync="" +sox=0 +toolame=0 +volume="1.0" +overburn="" +pd="" +norm=0 + +while [ "$1"x != "x" ]; do + case $1 in + -a) + aratio="-a $2" + shift 1 + ;; + -w) + wide="-M WIDE2STD" + ;; + -h|-?) + usage + exit 0 + ;; + -abr) + abr=$2 + abrset=1 + shift 1 + ;; + -asr) + asr=$2 + shift 1 + ;; + -cdsize) + CDMAXSIZE=$2 + shift 1 + ;; + -blank) + blank=1 + ;; + -noburn) + burn=0 + ;; + -burnonly) + burnonly=1 + burn=1 + ;; + -overburn) + overburn="--overburn" + ;; + -pulldown) + pd="-p" + ;; + -vfr) + framerate="-F $2" + shift 1 + ;; + -mp3) + mp3=1 + ;; + -mpegsrc) + mkstream=0 + ;; + -mpgonly) + mpgonly=1 + ;; + -normalize) + norm=1 + ;; + -vnorm) + yuvin="-n $2" + shift 1 + ;; + -volume) + volume="$2" + shift 1 + ;; + -denoise) + denoise="yuvdenoise" + ;; + -ratio) + ratio=$2 + shift 1 + ;; + -sid) # mplayer option: have to set vop expand, too!!! + sub="-vf pp,expand=-1:-1:-1:-1:1 -sid $2" + shift 1 + ;; + -size) + size=$2 + shift 1 + ;; + -svcdout) + vnorm="SVCD" + ;; + -sync) + sync="-O $2" + shift 1 + ;; + -sox) + sox=1 + ;; + -toolame) + toolame=1 + ;; + -vbr) + vbr=$2 + vbrset=1 + shift 1 + ;; + *) + params="$params $1" + ;; + esac + shift 1 +done + +# some configs +mpegnorm="-f $VCDMODE -b $vbr -B 260 -V 46" +if [ "$vnorm" == "SVCD" ]; then + [ $vbrset -eq 0 ] && vbr=2500 + mplexnorm="-f $SVCDMODE -m 2 -V -b 230" + mpegnorm="-f $SVCDMODE -b $vbr -B 260 -V 230" + imaget="-t svcd" +fi + +# ratio overwrites wide sizing, size overwrites default frame size +[ -n "$ratio" ] && wide="-M $ratio" +[ -n "$size" ] && size="-O SIZE_$size" + +# with mp3 audio set the default audio bitrate to 128 kbs +[ $mp3 -eq 1 -a $abrset -eq 0 ] && abr=128 + +# audio sample rate in kHz +((a=$asr / 1000)) +((b=$asr % 1000)) +[ $b -le 9 ] && b="00$b00" +[ $b -le 99 ] && b="0$b00" +kasr="$a.$b" + +# start de-/encoding +if [ $burnonly -eq 0 ]; then + # encode streams + if [ $mkstream -eq 1 ]; then + # start mplayer + command="mplayer -noframedrop -vo yuv4mpeg -ao pcm -waveheader -v -osdlevel 0 $sub $params" + echo "$command" + $command & + + # mjpegtools + ($denoise < $VIDEO | \ + yuvscaler -v 0 $wide -O $vnorm $size $yuvin | \ + mpeg2enc -v 0 -s $mpegnorm $aratio -S $CDMAXSIZE -g 6 -G 15 -r 16 \ + $pd $framerate $yuvin -4 2 -2 1 -o $NAME.mpv) & + + # wait for finishing the subprocesses + wait + + # normalize sound + [ $norm -eq 1 ] && (echo "normalizing sound..."; normalize $AUDIO) + + # do resampling with sox + if [ $sox -ne 0 ]; then + echo "wait, do resampling with sox..." + sox $AUDIO -v $volume -r $asr $NAME.wav resample -qs + mv -f $NAME.wav $AUDIO + fi + + if [ $toolame -ne 0 -a $mp3 -eq 0 ]; then + # do mp2 encoding with toolame + echo "wait, encoding to mp2 audio with toolame..." + toolame -b $abr $AUDIO + mv -f `basename $AUDIO .wav`.mp2 $NAME.mpa + elif [ $toolame -eq 0 -a $mp3 -eq 0 ]; then + # mp2enc/lame can't read audiodump.wav directly from named pipe, + # we have to read the whole file. + echo "wait, encoding to mp2 audio with mp2enc..." + mp2enc -b $abr -r $asr -o $NAME.mpa < $AUDIO + elif [ $mp3 -ne 0 ]; then + echo "wait, encoding to mp3 audio with lame..." + lame -b $abr --resample $kasr - $NAME.mpa < $AUDIO + fi + fi + + # remove wav file, won't need anymore! + rm -f $AUDIO + + # multiplex streams + [ -f $NAME.mpv -a -f $NAME.mpa ] || exit 1 + rm -f ${NAME}*.mpg + mplex $mplexnorm $sync $NAME.mpv $NAME.mpa -o ${NAME}%d.mpg + + # remove pipe, won't need anymore! + rm -f $VIDEO + + # should i create only the mpeg file? + [ $mpgonly -eq 1 ] && exit 0 + + # create cd images + for mpg in ${NAME}*.mpg; do + [ -f $mpg ] || exit 1 + cue="`basename $mpg .mpg`.cue" + bin="`basename $mpg .mpg`.bin" + rm -f $cue $bin + vcdimager $imaget -c $cue -b $bin $mpg + [ -f $bin -a -f $cue ] && rm -f $mpg + done + +# end of streaming/mastering +fi + +# burn the (s)vcd's +[ $burn -eq 0 ] && exit 0 + +for cue in ${NAME}*.cue; do + bin="`basename $cue .cue`.bin" + [ -f $bin -a -f $cue ] || exit 1 + + echo "please insert a cd in your cdwriter, after a keypress we start:" + read -n 1 i + + if [ $blank -eq 1 ]; then + cdrdao blank --reload $CDDEV --driver $CDDRV --blank-mode minimal + fi + cdrdao write $overburn --reload $CDDEV --driver $CDDRV $cue +done +exit 0 --- mplayer-0.99+1.0pre7try2+cvs20060117.orig/TOOLS/w32codec_dl.pl +++ mplayer-0.99+1.0pre7try2+cvs20060117/TOOLS/w32codec_dl.pl @@ -0,0 +1,169 @@ +#!/usr/bin/perl + +## usage: w32codec_dl.pl (codec.conf location) + +# this script will use MS's codec dl interface as used by MS Media Player +# to attempt to locate the codecs listed in codecs.conf. It will download +# them to a directory "codecs/" below the current dir. +# you will need the libwww-perl stuff and the utility "cabextract" +# which may be found at http://www.kyz.uklinux.net/cabextract.php3 + +# By Tom Lees, 2002. I hereby place this script into the public domain. + +#use LWP::Debug qw(+); +use LWP::UserAgent; + +$ua = LWP::UserAgent->new; +$ua->agent ("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"); + +# Parse the etc/codecs.conf file +my $cconf = $ARGV[0]; +open CCONF, "<$cconf"; + +my $codec = "(none)"; +my $mscodec = 0; + +my $cc, @ccl; + +mkdir "codecs"; +chdir "codecs"; + +CC: while () +{ + next CC if (m/^[ \t]*\;/); + s/\;.*//g; + s/#.*//g; + + if (m/^videocodec (.*)/) + { + $codec = $1; + } + elsif (m/^[ \t]+driver (.*)/) + { + if ($1 eq "dshow" || $1 eq "vfw") + { + $mscodec = 1; + } + else + { + $mscodec = 0; + } + } + elsif (m/^[ \t]+fourcc (.*)/ && $mscodec == 1) + { + $cclist = $1; + chomp $cclist; + #@ccl = (); + do + { + if ($cclist =~ m/\"(....)\"[, ]*(.*)/) + { + $cc = $1; + $cclist = $2; + } + elsif ($cclist =~ m/[, ]*(....)[, ]*(.*)/) + { + $cc = $1; + $cclist = $2; + } + else + { + $cc = $cclist; + $cclist = ""; + } + if (!($cc =~ m/^[ \t]+/)) + { + push @ccl, ($cc); + } + } while (length ($cclist) > 0); + } +} +close CCONF; + +# Find the codecs +open CODEC_CABS, ">codecs.locations.info"; +%fcc_try = (); +while ($#ccl > 0) +{ + $cc = pop (@ccl); + if (!$fcc_try{"$cc"}) + { + $fcc_try{"$cc"} = 1; + if (!find_codec ($cc)) + { + print "$cc found\n"; + } + else + { + print "MS didn't find $cc\n"; + } + } +} +close CODEC_CABS; + +%got_codecs = (); +sub find_codec +{ + my ($fourcc) = @_; + + my $guid = sprintf ("%08X", unpack ("V", $fourcc))."-0000-0010-8000-00AA00389B71"; + + my $req = HTTP::Request->new (POST => "http://activex.microsoft.com/objects/ocget.dll"); + $req->header ('Accept', '*/*'); + $req->content_type ('application/x-www-form-urlencoded'); + $req->content ("CLSID=%7B${guid}%7D\n"); + #$req->content ('CLSID={'.${guid}.'}'); + + my $res = $ua->request ($req); + + if ($res->is_success) { + print "Lookup returned success... weird!\n"; + return 1; + } else { + # Codec location + if ($res->code == 302) + { + my $loc = $res->headers->header ("Location"); + if (!$got_codecs{"$loc"}) + { + print CODEC_CABS "$loc\n"; + $got_codecs{"$loc"} = 1; + get_codec ($loc); + } +# else +# { +# print "Already have $loc\n"; +# } + return 0; + } + else + { +# print "Lookup failed (Microsoft probably doesn't know this codec)\n"; + return 1; + } + } +} + +sub get_codec +{ + my ($url) = @_; + + my $req = HTTP::Request->new (GET => $url); + $req->header ("Accept", "*/*"); + my $res = $ua->request ($req); + + if ($res->is_success) + { + open TMP, ">tmp.cab" or die "Unable to open tmp.cab"; + print TMP $res->content; + close TMP; + + system "cabextract tmp.cab"; + unlink "tmp.cab"; + } + else + { + print "No such file!\n"; + } +} + --- mplayer-0.99+1.0pre7try2+cvs20060117.orig/TOOLS/midentify +++ mplayer-0.99+1.0pre7try2+cvs20060117/TOOLS/midentify @@ -0,0 +1,5 @@ +#!/bin/sh +mplayer -vo null -ao null -frames 0 -identify "$@" 2>/dev/null | + grep "^ID" | + sed -e 's/[`\\!$"]/\\&/g' | + sed -e '/^ID_FILENAME/ { s/^ID_FILENAME=\(.*\)/ID_FILENAME="\1"/g; }' --- mplayer-0.99+1.0pre7try2+cvs20060117.orig/TOOLS/dvd2divxscript.pl +++ mplayer-0.99+1.0pre7try2+cvs20060117/TOOLS/dvd2divxscript.pl @@ -0,0 +1,264 @@ +#!/usr/bin/perl + +# +# (c) 2002-2004 by Florian Schilhabel +# +# +# version 0.1 initial release 22/08/2002 +# +# +# If you have any comments, suggestions, etc., feel free to send me a mail ;-)) +# flames and other things like that should go to /dev/null +# thankx to all the mplayer developers for this really *great* piece of software +# +# +# This script is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# +# +use Getopt::Long; + +# specify your default Settings here... + +$abr_default = 128; # The default AudioBitRate +$lang_default = "de"; # ... the language +$cdsize_default = 700; # ... the CD-Rom Size +$writedev_default = "0,1,0"; # ... the CD Writer Device +$speed_default = 4; # ... the writer speed +$dvd_device = "/dev/dvd"; # and the DVD Rom Device + +# end of default Settings + + + +sub delete_tempfiles { + if (open(FILE, "< audio.stderr")) { + close (FILE); + system ("rm audio.stderr") + } + if (open(FILE, "< frameno.avi")) { + close (FILE); + system ("rm frameno.avi"); + } + if (open(FILE, "< lavc_stats.txt")) { + close (FILE); + system ("rm lavc_stats.txt"); + } +} + +GetOptions( "help" => \$help, + "abr=i" => \$abr, + "lang=s" =>\$lang, + "cdsize=i" => \$cdsize, + "dvd=i" => \$dvd_track, + "keeptemp" => \$keeptemp, + "shutdown" => \$shutdown, + "out=s" => \$output, + "writecd" => \$writecd, + "writedev=s" => \$writedev, + "speed=i" => \$speed, + "dvd-device=s" => \$dvd_device ); + +if ($help) { + print "Welcome to the DVD to DIVX Helper Script\n"; + print "\n"; + print "this script encodes a DVD track in 3-pass mode to libavcodec's mpeg4\n"; + print "Optionally it writes the resulting MovieFile to a CD-Rom\n"; + print "as well as the corresponding audio track to mp3\n"; + print "Optionally it writes the resulting MovieFile to a CD-Rom\n"; + print "and shuts down the Computer.\n"; + print "If you like, you can watch the mencoder output on /dev/tty8\n"; + print "Usage:\n"; + print "--help show this text\n"; + print "--abr (AudioBitRate) Please enter the desired bitrate\n"; + print " this can be either [96|128|192] kbit/sec.\n"; + print " Default: 128 kbit/sec.\n"; + print "--lang specify the Language of the audio track\n"; + print " this can be for example or \n"; + print " Default: \n"; + print "--dvd specify the DVD Track, you want to encode\n"; + print "--cdsize specify the Size of your CD-ROM\n"; + print " Default: 700MB\n"; + print "--shutdown Shutdown the System, when the encoding process has finished\n"; + print " this will only be possible if you are root\n"; + print "--out Specify the Name of your encoded Movie\n"; + print " The File Extension will be appended automatically\n"; + print "--writecd takes the newly created Movie and writes it to a CD-Rom\n"; + print "--writedev is the usual cdrecord device identifier\n"; + print " for example 0,1,0\n"; + print "--speed the writing speed\n"; + print " Default: 4\n"; + print "--dvd-device device to pull the video off\n"; + print " Default: /dev/dvd\n"; + exit; +} + +delete_tempfiles(); + +# testing user values && set defaults... + +if ($abr == 96){} +elsif ($abr == 128) {} +elsif ($abr == 192) {} +elsif ($abr == 0 ) { + print "No AudioBitRate specified - Setting to Default Value\n"; + $abr = $abr_default; +} +else { +print "AudioBitRate not valid. please choose [96|128|192]\n"; +exit; +} + +if ($lang eq "") { + print "No Language specified - Setting to Default Value\n"; + $lang = $lang_default; +} +else {} + +if ($dvd_track == 0 ) { + print "No DVD Track selected - You must specify one with: --dvd trackno.\n"; + exit; +} + +if ($cdsize == 650) {} +elsif ($cdsize == 700) {} +elsif ($cdsize == 800) {} +elsif ($cdsize == 0 ) { + print "No CD Size Specified - Setting to Default Value\n"; + $cdsize = $cdsize_default; +} + +else { +print "CD Size not valid. please choose [650|700|800]\n"; +exit; +} + +if ($output eq "") { + print "No MovieName given - You must specify one with: --out [movie_name]\n"; + exit; +} +else { + ($name, $extension) = split(/./, $out); + if ($extension eq "avi") { + $vob_tempfile = "$name.vob"; + $avi_filename = "$output"; + } + else { + $vob_tempfile = "$output.vob"; + print "VOB CacheFile set to $vob_tempfile\n"; + $avi_filename = "$output.avi"; + print "Movie Filename set to $avi_filename\n"; + } +} + +if ($shutdown) { + # test who i am + $user = `id -u`; + if ($user == 0) { + print "System will be shut down after Movie encoding\n"; + } + else { + print "Cannot shutdown the system after Movie encoding - you are not 'root'\n"; + exit; + } +} + +if ($writecd) { + if ($writedev == "") { + print "Setting CD Writer Device to Default Value\n"; + $writedev = $writedev_default; + } + if ($speed == 0) { + print "Setting CD Writer Speed to Default value\n"; + $speed = $speed_default; + } + +} + + + +### + +print "Your Settings for this run are:\n"; +print "AudioBitRate: $abr\n"; +print "Language: $lang\n"; +print "DVD-Track: $dvd_track\n"; +print "CD-Rom Size: $cdsize\n"; +print "Movie FIlename: $avi_filename\n"; +if ($writecd) { + print "CD Writer Dev.: $writedev\n"; + print "Writer Speed: $speed\n"; +} + +# here comes the fun part... + +print "precacheing...\n"; +$status = system ("mencoder dvd://$dvd_track -ovc copy -oac copy -dvd-device $dvd_device -alang $lang -o $vob_tempfile 1>/dev/tty8 2>/dev/tty8"); +die "Prechacheing failed. mencoder exited with Status Code $?" unless $status == 0; + +print "Encoding Audio...\n"; +$status = system ("mencoder $vob_tempfile -ovc frameno -oac mp3lame -lameopts br=$abr:cbr:vol=3 -o frameno.avi 1>./audio.stderr 2>/dev/tty8"); +die "Encoding Audio failed. mencoder exited with Status Code $?" unless $status == 0; + +# now we have to find out the recommended bitrate for the Video encoding process... +# my current method to find this out is, hmm, well, *strange* +# but anyway, it works ;-)) + +open(FILE, "< audio.stderr") or die "Unable to open audio.stderr."; +@lines = ; +foreach $line (@lines) { + ($index, $zz) = split(" ", $line); + if ($index eq "Recommended") { + ($a, $b, $c, $d, $size, $f, $bitrate) = split(" ", $line); + if ($cdsize == $size) { + $video_bitrate = $bitrate; + print "Setting Videobitrate to $video_bitrate\n"; + } + } +} +close (FILE); + +print "Encoding Video Stream, 1st pass...\n"; +$status = system ("mencoder $vob_tempfile -ovc lavc -lavcopts vpass=1:vcodec=mpeg4:vbitrate=$video_bitrate:vhq -oac copy -o $avi_filename 1>/dev/tty8 2>/dev/tty8"); +die "Encoding Video Stream failed. mencoder exited with Status Code $?" unless $status == 0; + +print "Encoding Video Stream, 2nd pass...\n"; +$status = system ("mencoder $vob_tempfile -ovc lavc -lavcopts vpass=2:vcodec=mpeg4:vbitrate=$video_bitrate:vhq -oac copy -o $avi_filename 1>/dev/tty8 2>/dev/tty8"); +die "Encoding Video Stream failed. mencoder exited with Status Code $?" unless $status == 0; + +print "finished encoding\n"; + + +if ($writecd) { + print "Now writing CD-Rom\n"; + $status = system("mkisofs -r -J $avi_filename | cdrecord speed=$speed dev=$writedev -data - 2>/dev/tty8 1>/dev/tty8"); + die "Writing CD failed. cdrecord exited with Status Code $?" unless $status == 0; +} +delete_tempfiles(); + +print "Finished - have a nice day ;-)\n"; +if ($shutdown) { + system("halt"); + exit; +} +exit; + + + + + + + + --- mplayer-0.99+1.0pre7try2+cvs20060117.orig/TOOLS/subedit.pl +++ mplayer-0.99+1.0pre7try2+cvs20060117/TOOLS/subedit.pl @@ -0,0 +1,445 @@ +#!/usr/bin/perl -w + +# A script for pipelined editing of subtitle files. +# Copyright (C) 2004 Michael Klepikov +# +# Version 1.0 initial release 28-Mar-04 +# +# Comments, suggestions -- send me an mail, but the recommended way is +# to enhance/fix on your own and submit to the distribution;) +# If you like, I can review the fixes. +# +# This script is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# Retain original credits when modifying. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +use Math::BigInt; + +# Constants +my $FMT_UNKNOWN = 0; +my $FMT_SRT = 1; + +# Argument values +my $DEBUG = 0; +my $inFormat; +my $outFormat; +my $shiftMilli; +my $scaleMilli; +my $splitFromMilli; +my $splitToMilli; + +## Process command line +while (defined ($argVal = shift)) { + if ($argVal eq "-d" || $argVal eq "--debug") { + $DEBUG = 1; + } elsif ($argVal eq "-if" || $argVal eq "--input-format") { + $inFormat = shift; + usage ("Must specify input format") if ! $inFormat; + if ($inFormat =~ /^srt/i) { + $inFormat = $FMT_SRT; + } else { + usage ("Invalid input format"); + } + } elsif ($argVal eq "-of" || $argVal eq "--output-format") { + $outFormat = shift; + usage ("Must specify input format") if ! $outFormat; + if ($outFormat =~ /^srt/i) { + $outFormat = $FMT_SRT; + } else { + usage ("Invalid output format"); + } + } elsif ($argVal eq "-s" || $argVal eq "--shift") { + my $argTime = shift; + if (! defined $argTime || + ! defined ($shiftMilli = getTimeMillis ($argTime))) { + usage ("Invalid shift time value"); + } + } elsif ($argVal eq "-c" || $argVal eq "--scale") { + my $argTime = shift; + if (! defined $argTime || + ! defined ($scaleMilli = getTimeMillis ($argTime))) { + usage ("Invalid scale time value"); + } + } elsif ($argVal eq "-f" || $argVal eq "--split-from") { + my $argTime = shift; + if (! defined $argTime || + ! defined ($splitFromMilli = getTimeMillis ($argTime))) { + usage ("Invalid split start time value"); + } + } elsif ($argVal eq "-t" || $argVal eq "--split-to") { + my $argTime = shift; + if (! defined $argTime || + ! defined ($splitToMilli = getTimeMillis ($argTime))) { + usage ("Invalid split end time value"); + } + } elsif ($argVal eq "-h" || $argVal eq "--help") { + usage (); + } else { + usage ("Unrecognized argument $argVal"); + } +} + +# Input format defaults to SRT +$inFormat = $FMT_SRT if (! defined $inFormat); +# Output format defaults to the same as input +$outFormat = $inFormat if (! defined $outFormat); + +## Read + +my $subs; +if ($inFormat == $FMT_SRT) { + $subs = readSRT (*STDIN); + printf STDERR ("Read %d SRT subs\n", scalar @{$subs}) if $DEBUG; + # Sort by start time + @{$subs} = sort {$a -> {srtStartTime} <=> $b -> {srtEndTime}} @{$subs}; +} + +## Transform + +if (defined $shiftMilli && 0 != $shiftMilli) { + printf STDERR ("Shift: %d milliseconds\n", $shiftMilli) if $DEBUG; + shiftSRT ($subs, $shiftMilli); +} + +if (defined $splitFromMilli || defined $splitToMilli) { + if ($DEBUG) { + my $printFrom = (defined $splitFromMilli) ? $splitFromMilli : "-"; + my $printTo = (defined $splitToMilli) ? $splitToMilli : "-"; + printf STDERR ("Split: from $printFrom to $printTo\n"); + } + splitSRT ($subs, $splitFromMilli, $splitToMilli); +} + +if (defined $scaleMilli && 0 != $scaleMilli) { + my $lastSubIdx = scalar @{$subs} - 1; + if ($lastSubIdx >= 0) { + my $lastTimeOrig = $subs -> [$lastSubIdx] -> {srtEndTime}; + if ($lastTimeOrig == 0) { + die "Cannot scale when last subtitle ends at 00:00:00,000"; + } + my $lastTimeScaled = $lastTimeOrig + $scaleMilli; + printf STDERR ("Scale: %d/%d\n", $lastTimeScaled, $lastTimeOrig) if $DEBUG; + scaleSRT ($subs, $lastTimeScaled, $lastTimeOrig); + } +} + +## Write +if ($outFormat == $FMT_SRT) { + writeSRT (*STDOUT, $subs); +} + +# Close STDOUT, as recommended by Perl manual +# (allows diagnostics on disc overflow, etc.) +close (STDOUT) || die "Cannot close output stream: $!"; + +exit 0; + +## Subroutines + +# Convert string time format to milliseconds +# SRT style: "01:20:03.251", and "," is allowed instead of "." +# Return undef in case of format error +sub getTimeMillis +{ + $_ = shift; + my $millis = 0; + + if (/\s*(.*)[\.,]([0-9]+)?\s*$/) { # Fraction; strip surrounding spaces + #print STDERR "frac: \$1=$1 \$2=$2\n" if $DEBUG; + $_ = $1; + $millis += ("0." . $2) * 1000 if $2; + } + if (/(.*?)([0-9]+)$/) { # Seconds + #print STDERR "secs: \$1=$1 \$2=$2\n" if $DEBUG; + $_ = $1; + $millis += $2 * 1000 if $2; + } + if (/(.*?)([0-9]+):$/) { # Minutes + #print STDERR "mins: \$1=$1 \$2=$2\n" if $DEBUG; + $_ = $1; + $millis += $2 * 60000 if $2; + } + if (/(.*?)([0-9]+):$/) { # Hours + #print STDERR "mins: \$1=$1 \$2=$2\n" if $DEBUG; + $_ = $1; + $millis += $2 * 3600000 if $2; + } + if (/(.*?)\-$/) { # Minus sign + $_ = $1; + $millis *= -1; + } + $millis = undef if (! /^$/); # Make sure we ate everything up + if ($DEBUG) { + if (defined $millis) { + #print STDERR "time value match: $millis ms\n"; + } else { + #print STDERR "time mismatch\n"; + } + } + return $millis; +} + +# Convert milliseconds to SRT formatted string +sub getTimeSRT +{ + my $t = shift; + my $tMinus = ""; + if ($t < 0) { + $t = -$t; + $tMinus = "-"; + } + my $tMilli = $t % 1000; + $t /= 1000; + my $tSec = $t % 60; + $t /= 60; + my $tMin = $t % 60; + $t /= 60; + my $tHr = $t; + return sprintf ("%s%02d:%02d:%02d,%03d", + $tMinus, $tHr, $tMin, $tSec, $tMilli); +} + +# Read SRT subtitles +sub readSRT +{ + local *IN = shift; + my $subs = []; + + $_ = ; + print STDERR "Undefined first line\n" if ! defined $_ && $DEBUG; + my $lineNo = 1; + READ_SUBS: + while (defined $_) { + # Each loop iteration reads one subtitle from + my $sub = {}; + + # print STDERR "Reading line $lineNo\n" if $DEBUG; + + # Skip empty lines + while (/^\s*$/) { + last READ_SUBS if ! ($_ = ); + ++$lineNo; + } + + # Subtitle number + if (/^\s*([0-9]+)\s*$/) { + $sub -> {srtNumber} = $1; + # print "SRT num: $1\n" if $DEBUG; + } else { + die "Invalid SRT format at line $lineNo"; + } + + # Timing + if ($_ = ) { + ++$lineNo; + } else { + die "Unexpected end of SRT stream at line $lineNo"; + } + # print STDERR "LINE: $_\n" if $DEBUG; + if (/^\s*(\S+)\s*--\>\s*(\S+)\s*$/) { + my $startMillis = getTimeMillis ($1); + my $endMillis = getTimeMillis ($2); + die "Invalid SRT timing format at line $lineNo: $_" + if ! defined $startMillis || ! defined $endMillis; + $sub -> {srtStartTime} = $startMillis; + $sub -> {srtEndTime} = $endMillis; + } else { + die "Invalid SRT timing format at line $lineNo: $_"; + } + + # Text lines + my $subLines = []; + while (1) { + last if ! ($_ = ); # EOF ends subtitle + ++$lineNo; + last if /^\s*$/; # Empty line ends subtitle + ($_ = $_) =~ s/\s+$//; # Strip trailing spaces + push @{$subLines}, $_; + } + die "No text in SRT subtitle at line $lineNo" if 0 == scalar @{$subLines}; + $sub -> {lines} = $subLines; + + # Append subtitle to the list + push @{$subs}, $sub; + } + print STDERR "SRT read ok, $lineNo lines\n" if $DEBUG; + + return $subs; +} + +# Write SRT subtitles +sub writeSRT +{ + use integer; # For integer division + local *OUT = shift; + my $subs = shift; + + my $subNum = 0; + foreach (@{$subs}) { + ++$subNum; + + my $sub = $_; + my $sTimeSRT = getTimeSRT ($sub -> {srtStartTime}); + my $eTimeSRT = getTimeSRT ($sub -> {srtEndTime}); + printf OUT ("%d\n%s --> %s\n", $subNum, $sTimeSRT, $eTimeSRT); + foreach (@{$sub -> {lines}}) { + printf OUT ("%s\n", $_); + } + printf OUT "\n"; + } + printf STDERR ("Wrote %d SRT subs\n", $subNum) if $DEBUG; +} + +# Shift SRT subtitles by a given number of seconds. +# The number may be negative and fractional. +sub shiftSRT +{ + use integer; # $shiftMilli could be passed as float + my $subs = shift; + my $shiftMilli = shift; + + foreach (@{$subs}) { + $_ -> {srtStartTime} += $shiftMilli; + $_ -> {srtEndTime} += $shiftMilli; + } +} + +# Multiply each subtitle timing by a divident and divide by divisor. +# The idea is that the divident is usually the new total number of +# milliseconds in the subtitle file, and the divisor is the old +# total number of milliseconds in the subtitle file. +# We could simply use a double precision real coefficient instead of +# integer divident and divisor, and that could be good enough, but +# using integer arithmetics *guarantees* precision up to the last +# digit, so why settle for good enough when we can have a guarantee. +# +# Uses Math::BigInt arithmetics, because it works with numbers +# up to (total number of milliseconds for a subtitle timing)^2, +# which could be on the order of approximately 1e+13, which is +# larger than maximum 32-bit integer. +# There is a performance loss when using BigInt vs. regular floating +# point arithmetics, but the actual performance is quite acceptable +# on files with a few thousand subtitles. +sub scaleSRT +{ + use integer; # Divident and divisor could be passed as floats, truncate + my $subs = shift; + my $scaleDividend = shift; + my $scaleDivisor = shift; + + foreach (@{$subs}) { + my $ss = Math::BigInt -> new ($_ -> {srtStartTime}); + $ss = $ss -> bmul ($scaleDividend); + $_ -> {srtStartTime} = $ss -> bdiv ($scaleDivisor) -> bsstr (); + my $se = Math::BigInt -> new ($_ -> {srtEndTime}); + $se = $se -> bmul ($scaleDividend); + $_ -> {srtEndTime} = $se -> bdiv ($scaleDivisor) -> bsstr (); + } +} + +# Extract a fragment within a given time interval +# Either "from" or "to" may be undefined +sub splitSRT +{ + use integer; # fromMilli and toMilli could be passed as floats, truncate + my $subs = shift; + my $fromMilli = shift; + my $toMilli = shift; + + my $iSub = 0; + while ($iSub < scalar @{$subs}) { + $_ = $subs -> [$iSub]; + my $keep = 0; + if (! defined $fromMilli || $_ -> {srtEndTime} >= $fromMilli) { + # The subtitle ends later than the start boundary + + # Fix overlapping start timing, + # but only of the start boundary is not infinite (undef) + if (defined $fromMilli && $_ -> {srtStartTime} < $fromMilli) { + $_ -> {srtStartTime} = $fromMilli; + } + if (! defined $toMilli || $_ -> {srtStartTime} <= $toMilli) { + # The subtitle begins earlier than the end boundary + + # Fix overlapping end timing, + # but only of the end boundary is not infinite (undef) + if (defined $toMilli && $_ -> {srtEndTime} > $toMilli) { + $_ -> {srtEndTime} = $toMilli; + } + + # All conditions met, all fixes done + $keep = 1; + } + } + if ($keep) { + ++$iSub; + } else { + splice @{$subs}, $iSub, 1; + } + } +} + +# Print brief usage help +# Accepts an optional error message, e.g. for errors parsing command line +sub usage +{ + my $msg = shift; + my $exitCode = 0; + + if (defined $msg) { + $exitCode = 2; + print STDERR "$msg\n"; + } + + print STDERR < input format; supported: SRT + default is SRT + -of,--output-format output format; supported: SRT + default is same as input format + -s,--shift