#!/usr/bin/perl -w ####################################################################### # # MPlayercrop - MPlayer autocrop script # By Martin (bumby) Stenberg # use strict; use File::Basename; my $SAME_FRAMES=30; # You may have to tweak this usage($0) unless @ARGV; my $argv=""; foreach my $arg (@ARGV){ $arg=~s/ /\\ /g; $argv.=" $arg"; } my $s=""; my $old=""; my $i=0; my $pid = fork(); die "Couldn't fork: $!\n" unless defined $pid; if($pid == 0){ open(FILE,"mplayer -vf cropdetect $argv|") or die "Could not start mplayer"; print "\nGathering crop detections. Please wait...\n"; while(){ $s=$_; if(/\(-vf crop=(\d+:\d+:\d+:\d+)\)/){ $s=$1; if("$s" eq "$old"){ $i++; }else{ $i=0; } } if($i == $SAME_FRAMES){ system("reset"); exec("mplayer -vf crop=$s $argv"); exit 0; } $old=$s; } exit 0; } sub usage{ my $file = basename(shift); print "Usage: $file [mplayer options] file\n"; exit 1; }