just directly to subtitle *text*
[HTML5TV.git] / bin / video-timecoded.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Graphics::Magick;
7 use File::Path qw(rmtree);
8
9 my $length = 100;
10 my $fps = 5;
11
12 if ( my $original = shift @ARGV ) {
13         my $len_ms = `oggLength $original`;
14         $length = int( ( $len_ms + 500 ) / 1000 );
15         warn "$original\t$length s\n";
16 }
17
18 rmtree "/tmp/blank";
19 mkdir "/tmp/blank";
20
21 my $frame_fmt = '/tmp/blank/f%08d.jpg';
22
23 foreach my $pos ( 0 .. $length * $fps ) {
24
25         my $im = Graphics::Magick->new( size => '320x200' );
26         $im->ReadImage( 'xc:black' );
27         my $t = $pos / $fps;
28         my $hh = int( $t / 60 / 60 );
29         my $mm = int( $t / 60 );
30         my $ss = $t - $mm * 60 - $hh * 60 * 60;
31         $im->Annotate(
32                 x => 10, y => 175,
33                 font => 'Sans', pointsize => 24,
34                 text => sprintf("%02d:%02d:%06.3f", $hh, $mm, $ss ),
35                 fill => 'yellow',
36         );
37         my $path = sprintf $frame_fmt, $pos;
38         $im->Write( filename => $path );
39 #       warn "# $hh $mm $ss $path ", -s $path, $/ if $t % $fps == 0;
40         print STDERR $pos % 60 * $fps == 0 ? '*' : '.' if $pos % $fps == 0;
41 }
42
43 print STDERR "\n";
44
45 #system "oggSlideshow -f $fps -o /tmp/blank.ogv -d 20000 -e -l $fps -t p /tmp/blank/f*";
46 system "ffmpeg2theora --framerate $fps --keyint $fps -o /tmp/blank.ogv $frame_fmt";
47
48 rmtree "/tmp/blank";
49