/[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 2 - (hide annotations)
Thu Jul 19 20:17:06 2007 UTC (16 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1246 byte(s)
configurable jpeq quality
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    
12     my $tmp = '/tmp/frames';
13     my $out = '/tmp/frames.avi';
14 dpavlin 2 my $jpeg_q = 10;
15 dpavlin 1
16     mkpath $tmp || die "can't create $tmp: $!";
17    
18     my $im = new GD::Image( 160, 120 );
19    
20     my $im_col;
21    
22     sub col {
23     my $hex = shift;
24     $hex = lc($hex);
25     die "not hex: $hex" unless ( $hex =~ m/^([0-9a-f])([0-9a-f])([0-9a-f])$/i );
26     my ( $r,$g,$b ) = ( hex($1 . $1),hex($2 . $2),hex($3 . $3) );
27     if ( ! defined( $im_col->{$hex} ) ) {
28     my $col = $im->colorAllocate( $r, $g, $b );
29     warn "creating color $col $hex\n";
30     $im_col->{$hex} = $col;
31     }
32     return $im_col->{$hex};
33     }
34    
35     my @cols = (
36     '000',
37     'f00',
38     '0f0',
39     '00f',
40     'ff0',
41     '0ff',
42     'fff',
43     );
44    
45     my $frame = 1;
46    
47     foreach my $c ( @cols ) {
48     foreach ( 1 .. 16 ) {
49     $im->fill(50,50, col($c) );
50     warn "frame $frame\n";
51     my $path = sprintf('%s/%03d.jpg', $tmp, $frame++);
52     open(my $fh, '>', $path) || die "can't open $path: $!";
53 dpavlin 2 print $fh $im->jpeg( $jpeg_q ) || die "can't save picture $path: $!";
54 dpavlin 1 close($fh) || die "can't close picture $path: $!";
55     }
56     }
57    
58     system("ffmpeg -i $tmp/%03d.jpg -r 16 -vcodec copy -y $out") == 0 or
59     die "encoding failed: $?";
60    
61     rmdir $tmp || die "can't remove $tmp: $!";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26