#!/usr/bin/perl #H# renames mpeg videos based on the specs of the file #H# example for an SVCD: #H# svcd_file.MPEG2_480x480-12@29.970_44100x2x16x224.m2v #H# example for a VCD: #H# vcd_file.MPEG1_352x240-2@29.970_44100x2x16x224.mpg # print out help info if requested if ($ARGV[0] eq "-h" || $ARGV[0] eq "--help" || $ARGV[0] eq "help" || $ARGV[0] eq "") { open (SELF, $0); while () { if ($_ =~ /^#H# /) { $_ =~ s/^#H# //; print $_; } } exit; } $FileName=$ARGV[0]; chomp $FileName; $Output=""; open (DATA, qq[mplayer -osdlevel 0 -framedrop -vo none -ao none "$FileName" 2>\&1 |]); while () { $Line=$_; chomp $Line; if ($_ =~ /^AUDIO:/) { #AUDIO: 44100 Hz, 2 ch, 16 bit (0x10), ratio: 28000->176400 (224.0 kbit) #AUDIO: 44100 Hz, 2 ch, s16le, 224.0 kbit/15.87% (ratio: 28000->176400) $Line =~ s/^AUDIO: *//; $Line =~ s/ / /g; $Line =~ s/ / /g; $Line =~ s/ / /g; $Line =~ s/ / /g; $Line =~ s/ Hz, /_/; $Line =~ s/ ch, /_/; #44100_2_s16le, 224.0 kbit/15.87% (ratio: 28000->176400) $Line =~ s/_s(.+)le, /_\1_/; $Line =~ s/ kbit.*//; $Line =~ s/_$//; $Line =~ s/\(//g; $Line =~ s/\)//g; $Output="$Output $Line"; } elsif ($_ =~ /^VIDEO:/) { #VIDEO: MPEG2 480x480 (aspect 2) 29.97 fps 2532.0 kbps (316.5 kbyte/s) $Line =~ s/ / /g; $Line =~ s/ / /g; $Line =~ s/ / /g; $Line =~ s/ / /g; $Line =~ s/ / /g; $Line =~ s/^VIDEO: //; $Line =~ s/ fps.*$//; $Line =~ s/ .aspect /_/; $Line =~ s/\) /_/; $Output="$Output $Line"; } } $Output =~ s/^ //g; $Output =~ s/ /_/g; # MPEG2_480x480_2_29.970_44100_2_16_224.0 $Output =~ s/x/_/; ($Format,$X,$Y,$Aspect,$FrameRate,$SampleRate,$Tracks,$AudioBits,$BitRate)=split(/_/,$Output); $BitRate =~ s/\..//; if ($Format eq "MPEG2") { $Extention="m2v"; } elsif ($Format eq "MPEG1") { $Extention="mpg"; } else { die "I don't know how to deal with $Format files."; } $NFN=$FileName; $NFN =~ s/\.mpg$//; $NFN =~ s/\.m2v$//; $NFN="$NFN.$Format" . "_$X" . "x$Y-$Aspect\@$FrameRate" . "_$SampleRate" . "x$Tracks" . "x$AudioBits" . "x$BitRate" . ".$Extention"; system (qq[mv -v "$FileName" "$NFN"]); close (DATA);