/[amv]/frames.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /frames.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Fri Jul 20 16:54:52 2007 UTC revision 35 by dpavlin, Mon Oct 1 20:48:54 2007 UTC
# Line 8  use strict; Line 8  use strict;
8    
9  use GD;  use GD;
10  use File::Path;  use File::Path;
11    use Getopt::Long;
12    
13  my $tmp = '/tmp/frames';  my $tmp = '/tmp/frames';
14  my $out = '/tmp/frames.avi';  my $out = '/tmp/frames.avi';
15  my $jpeg_q = 100;  my $jpeg_q = 100;
16  my $repeat = 16;  my $repeat = 1;
17  $repeat = 1; # off  my $vary_jpeg_q = 0;
18    $repeat = 16;
19    my $audio = '-i adpcm.wav -acodec adpcm_ms -ar 22050';
20    
21    GetOptions(
22            "jpeg-q=i" => \$jpeg_q,
23            "repeat=i" => \$repeat,
24    );
25    
26  rmtree $tmp if -e $tmp;  rmtree $tmp if -e $tmp;
27  mkpath $tmp || die "can't create $tmp: $!";  mkpath $tmp || die "can't create $tmp: $!";
# Line 36  sub col { Line 44  sub col {
44  }  }
45    
46  my @cols = (  my @cols = (
47            'fff',
48          '000',          '000',
49          'f00',          'f00',
50            '000',
51          '0f0',          '0f0',
52            '000',
53          '00f',          '00f',
54            '000',
55          'ff0',          'ff0',
56            '000',
57          '0ff',          '0ff',
58            '000',
59          'fff',          'fff',
60  );  );
61    
62  my $frame = 1;  my $frame = 1;
63    
64    sub save_jpeg {
65            my ( $path, $q ) = @_;
66            open(my $fh, '>', $path ) || die "can't open $path: $!";
67            print $fh $im->jpeg( $q ) || die "can't save picture $path: $!";
68            close($fh) || die "can't close picture $path: $!";
69    }
70    
71  foreach my $c ( @cols ) {  foreach my $c ( @cols ) {
72          foreach ( 1 .. $repeat ) {          foreach ( 1 .. $repeat ) {
73                  $im->fill(50,50, col($c) );                  $im->fill(50,50, col($c) );
74                  warn "frame $frame\n";                  my $path = sprintf('%s/%03d.jpg', $tmp, $frame);
75                  my $path = sprintf('%s/%03d.jpg', $tmp, $frame++);                  save_jpeg( $path, $jpeg_q );
76                  open(my $fh, '>', $path) || die "can't open $path: $!";  
77                  print $fh $im->jpeg( $jpeg_q ) || die "can't save picture $path: $!";                  if ( $vary_jpeg_q ) {
78                  close($fh) || die "can't close picture $path: $!";                          foreach my $q ( 1 .. 100 ) {
79                                    my $path = sprintf('%s/%03d-q%03d.jpg', $tmp, $frame, $q );
80                                    save_jpeg( $path, $q );
81                            }
82                    }
83    
84                    warn "frame $frame $jpeg_q% ", -s $path, " bytes\n";
85                    $frame++;
86          }          }
87  }  }
88    
89  my $cmd = "ffmpeg -i $tmp/%03d.jpg -r 16 -y $out";  my $cmd = "ffmpeg -i $tmp/%03d.jpg -r 16 -vcodec mjpeg $audio -y $out";
90  warn "## $cmd\n";  warn "## $cmd\n";
91  system($cmd) == 0 or die "encoding failed: $?";  system($cmd) == 0 or die "encoding failed: $?";
92    
93  rmdir $tmp || die "can't remove $tmp: $!";  #rmdir $tmp || die "can't remove $tmp: $!";
94    
95  warn "created $out ", -s $out, " bytes\n";  warn "created $out ", -s $out, " bytes\n";

Legend:
Removed from v.12  
changed lines
  Added in v.35

  ViewVC Help
Powered by ViewVC 1.1.26