/[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

Annotation of /frames.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (hide annotations)
Sat Jul 21 12:50:32 2007 UTC (16 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 1470 byte(s)
command-line options --jpeg-q and --repeat, better output
1 dpavlin 1 #!/usr/bin/perl -w
2    
3     # frames.pl
4     #
5     # 07/19/07 18:06:13 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6    
7     use strict;
8    
9     use GD;
10     use File::Path;
11 dpavlin 17 use Getopt::Long;
12 dpavlin 1
13     my $tmp = '/tmp/frames';
14     my $out = '/tmp/frames.avi';
15 dpavlin 17 my $jpeg_q = 20;
16     my $repeat = 1;
17 dpavlin 1
18 dpavlin 17 GetOptions(
19     "jpeg-q=i" => \$jpeg_q,
20     "repeat=i" => \$repeat,
21     );
22    
23 dpavlin 10 rmtree $tmp if -e $tmp;
24 dpavlin 1 mkpath $tmp || die "can't create $tmp: $!";
25    
26     my $im = new GD::Image( 160, 120 );
27    
28     my $im_col;
29    
30     sub col {
31     my $hex = shift;
32     $hex = lc($hex);
33     die "not hex: $hex" unless ( $hex =~ m/^([0-9a-f])([0-9a-f])([0-9a-f])$/i );
34     my ( $r,$g,$b ) = ( hex($1 . $1),hex($2 . $2),hex($3 . $3) );
35     if ( ! defined( $im_col->{$hex} ) ) {
36     my $col = $im->colorAllocate( $r, $g, $b );
37     warn "creating color $col $hex\n";
38     $im_col->{$hex} = $col;
39     }
40     return $im_col->{$hex};
41     }
42    
43     my @cols = (
44     '000',
45     'f00',
46     '0f0',
47     '00f',
48     'ff0',
49     '0ff',
50     'fff',
51     );
52    
53     my $frame = 1;
54    
55     foreach my $c ( @cols ) {
56 dpavlin 10 foreach ( 1 .. $repeat ) {
57 dpavlin 1 $im->fill(50,50, col($c) );
58     my $path = sprintf('%s/%03d.jpg', $tmp, $frame++);
59     open(my $fh, '>', $path) || die "can't open $path: $!";
60 dpavlin 2 print $fh $im->jpeg( $jpeg_q ) || die "can't save picture $path: $!";
61 dpavlin 1 close($fh) || die "can't close picture $path: $!";
62 dpavlin 17 warn "frame $frame $jpeg_q% ", -s $path, " bytes\n";
63 dpavlin 1 }
64     }
65    
66 dpavlin 12 my $cmd = "ffmpeg -i $tmp/%03d.jpg -r 16 -y $out";
67     warn "## $cmd\n";
68     system($cmd) == 0 or die "encoding failed: $?";
69 dpavlin 1
70 dpavlin 17 #rmdir $tmp || die "can't remove $tmp: $!";
71 dpavlin 10
72     warn "created $out ", -s $out, " bytes\n";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26