Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

mplayercrop

by bumby (Beadle)
on Jul 29, 2005 at 15:50 UTC ( #479452=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info
Description: Autocrop for MPlayer
#!/usr/bin/perl -w
######################################################################
+#
# 
# MPlayercrop - MPlayer autocrop script
# By Martin (bumby) Stenberg <bumby@evilninja.org>
#
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(<FILE>){
                $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;
}
Replies are listed 'Best First'.
Re: mplayercrop
by mrborisguy (Hermit) on Jul 29, 2005 at 23:40 UTC

    What is "autocropping"? That's hardly a descriptive description.

        -Bryan

      Sorry for that one. MPlayer has a cropdetect option which gives you information about width and height etc for use with -vf crop. So what you have to do normaly is to run mplayer with cropdetect find a suitable crop-line and rerun mplayer with this line in -vf crop. What the script here does, is just that, but automated. So you only have to run mplyarcrop.pl you_movie.avi I use it on every second movie I play, so I thought it might be usefull for someone else. First piece of code I post here.
Re: mplayercrop
by Anonymous Monk on Sep 13, 2007 at 22:35 UTC
    nice script, but it would be nice if mplayer does not detect the crop of the beginning of the movie. better would be skipping some frames after each crop detect. i've modified the script a little so it doesn't fork (it's important for use in my personal mplayer script)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://479452]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-01-25 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (65 votes). Check out past polls.

    Notices?