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

Contents of /frames.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26