updated git and svn scripts
[xrzperl.git] / mplayer-make-screenshot
blobcdeb8dfe2a7182d93c7864a6ed78071f11a263dd
1 #!/usr/bin/perl -w
2 ###APPNAME: mplayer-make-screenshot
3 ###APPAUTHOR: duel
4 ###APPDATE: 2008-05-11 02:53:08
5 ###APPVER: 0.1
6 ###APPDESC: mplayer-make-screenshot
7 ###APPUSAGE: filename [number of screenshots]
8 ###APPEXAMPLE: mplayer-make-screenshot [--hand] movie.avi 100
9 ###APPOPTION:
10 use strict;
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
14 #OR nothing will work
15 use lib $ENV{XR_PERL_MODULE_DIR};
17 use MyPlace::Script::Usage qw/help_required help_even_empty/;
18 exit 0 if(help_even_empty($0,@ARGV));
20 my $hand=shift;
21 if($hand eq "--hand") {
22 $hand=1;
24 else {
25 unshift @ARGV,$hand;
26 $hand=0;
29 my $fn=shift;
30 die "File not exist: $fn" unless(-r $fn);
33 sub dup_line {
34 my $line=shift;
35 print STDERR "$line\n";
36 return "$line\n";
39 #my @player_opt=("-slave","-vf","screenshot","-framedrop","-vo","jpeg:quality=100:smooth=100");
40 my @player_opt= $hand ? ("-vf","screenshot","-framedrop") : ("-slave","-vf","screenshot","-framedrop") ;
41 my $pipe_broken=0;
43 sub on_exit() {
44 $pipe_broken=1;
45 exit 0 unless(system("which png2jpg 1>/dev/null")==0);
46 my @pngs=glob("*.png");
47 if(@pngs) {
48 system("png2jpg",@pngs);
49 system("rm","-v",@pngs);
51 exit 0;
54 $SIG{PIPE}="on_exit";
56 if($hand) {
57 system("mplayer",@player_opt,$fn);
59 else {
60 my $num=shift;
61 $num = 50 unless($num>0);
62 my $step=0;
63 $step = 100.00 / $num;
64 my $total=0;
65 my $shot_cmd = "screenshot";
66 my $seek_cmd = "seek ";
67 open FO,"|-","mplayer",@player_opt,$fn;
68 select ((select(FO), $| = 1)[0]);
69 select ((select(STDERR), $| = 1)[0]);
70 sleep 5;
71 print FO dup_line("pause");
72 print FO dup_line($seek_cmd . "4 0");
73 print FO dup_line($shot_cmd);
74 until($total>=99.88) {
75 $total += $step;
76 $total=99.88 if($total>99.88);
77 sleep 2;
78 print FO dup_line($seek_cmd . "$total% 1") or last;
79 sleep 2;
80 print FO dup_line($shot_cmd);
82 print FO dup_line("quit");
83 close FO;
86 on_exit unless($pipe_broken);