#!/usr/bin/perl #H# Plays a file with mplayer using the params I want based on the hostname and filename #H# For interlaced video add: -vf yadif #H# Note that this script can be called with 3 different names and will act differently: #H# xplay - plays the file(s) on the primary display and audio #H# tplay - plays the file(s) on the second display and audio if available (usually a TV and receiver) #H# vplay - like tplay except nVidia vdpau hardware decoding is used if available # 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; } # always force a local display regardless of what is in the ENV. $ENV{"DISPLAY"}=":0.0"; $Player="mplayer"; $CPUFreq="n"; $Freqd="n"; # unblank the screen #system ("xscreensaver-command -deactivate"); # Stuff all of the command line arguments into a string var to be used later. # This includes the filename to be played and any mplayer params entered on the CLI. # Quotes are put into the string var since most of my file names have spaces. $Args=""; foreach $Arg (@ARGV) { $Args=qq[$Args "$Arg"]; } # determine the hostname and setup the mplayer params based on the hardware in that host $HostName=`hostname`; chomp $HostName; if ($HostName eq "comatose") { $MplayerParams="-monitoraspect 16:9 -osdlevel 1 -sws 9 -framedrop -vo vdpau,xv -vc ffmpeg12vdpau,ffwmv3vdpau,ffvc1vdpau,ffh264vdpau, -ao alsa -novm -fs -sid 999"; # comatose also has a second head which is my TV. If this script is called as tplay # that means I want to play on my TV instead of my monitor. if ($0 =~ /tplay/) { $ENV{"DISPLAY"}=":0.1"; $MplayerParams="-monitoraspect 4:3 -osdlevel 1 -sws 9 -framedrop -vo xv -ao alsa -novm -fs -sid 999"; } if ($0 =~ /vplay/) { $ENV{"DISPLAY"}=":0.1"; $MplayerParams="-monitoraspect 4:3 -osdlevel 1 -sws 9 -framedrop -vo vdpau,xv -vc ffmpeg12vdpau,ffwmv3vdpau,ffvc1vdpau,ffh264vdpau, -ao alsa -novm -fs -sid 999"; } } if ($HostName eq "dementia") { $MplayerParams="-monitoraspect 16:10 -osdlevel 3 -sws 9 -framedrop -vo xv -ao alsa -novm -fs -sid 999 -af volnorm=2 "; # dementia is also connected to a TV and receiver. Allow for tplay or vplay to output to them. if ($0 =~ /tplay/) { $ENV{"DISPLAY"}=":0.1"; $MplayerParams="-subwidth 100 -monitoraspect 16:9 -osdlevel 1 -sws 9 -framedrop -vo xv -ao alsa:device=hw=1.1 -novm -fs -sid 999 -ac hwdts,hwac3, "; } $CPUFreq="y"; if ($0 =~ /vplay/) { $ENV{"DISPLAY"}=":0.1"; $MplayerParams="-subwidth 100 -monitoraspect 16:9 -osdlevel 1 -sws 9 -framedrop -vo vdpau,xv -vc ffmpeg12vdpau,ffwmv3vdpau,ffvc1vdpau,ffh264vdpau, -ao alsa:device=hw=1.1 -novm -fs -sid 999 -ac hwdts,hwac3, "; $CPUFreq="v"; } } if ($HostName eq "lunacy") { # Lunacy is Windows 2000 with Cygwin! # This never really worked and isn't setup anymore. $MplayerParams="-osdlevel 1 -sws 9 -framedrop -vo directx -ao oss -novm -fs -sid 999"; } if ($HostName eq "laika") { # This box is too slow for alsa so it is stuck on OSS :( $MplayerParams="-osdlevel 1 -sws 9 -framedrop -vo xv -ao oss -fs -sid 999 -novm"; } if ($HostName eq "laika2") { $MplayerParams="-osdlevel 1 -sws 9 -framedrop -vo xv -ao alsa:device=hw=0.0 -novm -fs -sid 999 -lavdopts fast:skiploopfilter=all"; $CPUFreq="y"; } # look for extra mplayer params encoded into the filename # format is .x-param. # any spaces in the param get changed to _ # any dots in the params get changed to ^ # any colons in the params get changed to # because MS operating and filesystems can't handle having a : in the filename. # example: # video.x-aspect_16:9.avi # That would play the .avi file with -aspect 16:9 ## Also look for .16x9. or .4x3. #now handled within mkvfix @FileNameChunks=split (/\./,$Args); foreach $Chunk (@FileNameChunks) { if ($Chunk =~ /^x-/) { $Chunk =~ s/^x-/-/; $Chunk =~ s/_/ /; $Chunk =~ s/\^/./; $Chunk =~ s/#/:/g; print "Adding param: $Chunk\n"; $MplayerParams="$MplayerParams $Chunk"; } if ($HostName eq "dementia" || $HostName eq "comatose") { if ($MplayerParams =~ /vdpau/) { if ($MplayerParams =~ /-vf crop/ || $MplayerParams =~ /-vf yadif/) { # vdpau decoders can't handle deinterlace or crop print "Warning: video filters detected. Not using VDPAU.\n"; $MplayerParams=~s/-vc ffmpeg12vdpau,ffwmv3vdpau,ffvc1vdpau,ffh264vdpau,//g; } } # Allow file names to specify that ac3 or dts audio tracks are not the first track. This is no longer used. if ($0 =~ /tplay/ || $0 =~ /vplay/) { if ($Chunk =~ /\+ac3\+dts/) { $MplayerParams="$MplayerParams -aid 2"; } elsif ($Chunk =~ /\+ac3/) { $MplayerParams="$MplayerParams -aid 1"; } elsif ($Chunk =~ /\+dts/) { $MplayerParams="$MplayerParams -aid 1"; } } } # Allow file names to specify that HD video is available in an additional track if ($Chunk =~ /\+720p/ || $Chunk =~ /\+720i/ || $Chunk =~ /\+1080p/ || $Chunk =~ /\+1080i/) { if ($0 =~ /vplay/) { $MplayerParams="$MplayerParams -vid 1"; } elsif ($0 =~ /tplay/) { $MplayerParams="$MplayerParams -vid 1 -lavdopts fast:skiploopfilter=all"; } else { $MplayerParams="$MplayerParams -vid 0"; } } # This allows digital 6 channel output of files with 6 channel aac audio (mostly anime). if ($Chunk eq "aac") { print "Video with AAC audio stream detected. Using realtime AC3 conversion.\n"; $MplayerParams="$MplayerParams -af lavcac3enc=1:640:3"; } } # Handle the CPU frequency scaling for capable systems if playing HD content # no longer used. if ($CPUFreq eq "y") { if ($Args =~ /720/ || $Args =~ /1080/) { #system ("sudo /usr/bin/cpufreq-set --governor performance"); $Freqd="y"; } } if ($CPUFreq eq "v") { #system ("sudo /usr/bin/cpufreq-set --min 2000MHz"); $Freqd="v"; } # FINALLY actually play the file using the params decided on. print "Running $Player $MplayerParams $Args\n"; system ("$Player $MplayerParams $Args 2>&1"); # undo the CPU freqency scaling change if it was done. if ($Freqd eq "y") { #system ("sudo /usr/bin/cpufreq-set --governor ondemand"); } if ($Freqd eq "v") { #system ("sudo /usr/bin/cpufreq-set --min 800MHz"); }