--- amv.pl 2007/08/19 11:45:39 28 +++ amv.pl 2007/08/19 19:23:03 29 @@ -46,11 +46,13 @@ my $path = shift @ARGV || die "usage: $0 movie.amv\n"; # by default, flip frames -#$jpegtran = '-flip vertical' unless defined($jpegtran); +$jpegtran = '-flip vertical' unless defined($jpegtran); rmtree $dump_dir if -e $dump_dir; mkpath $dump_dir || die "can't create $dump_dir: $!"; +$| = 1; + open(my $fh, '<', $path) || die "can't open $path: $!"; # offset in file @@ -456,7 +458,8 @@ return $pred_val; } -open(my $au_fh, '>', 'out.au') || die "can't open out.au: $!"; +my $au_path = "$dump_dir/sound.au"; +open(my $au_fh, '>', $au_path) || die "can't open $au_path: $!"; print $au_fh pack 'a4N5', ( # magic '.snd', @@ -477,9 +480,6 @@ my ( $origin, $index, $bytes ) = unpack 'ssL', substr($data,0,8); -warn "audio_frame origin $origin index $index bytes $bytes\n"; -hex_dump( substr($data,0,8) ); - $pred_val = $origin; $step_idx = $index; @@ -552,6 +552,9 @@ die "$path not RIFF but $riff" if $riff ne 'RIFF'; die "$path not AMV but $amv" if $amv ne 'AMV '; +my $fps = 16; +my $duration; + while ( ! defined($d->{eof}) ) { my ( $list, $name ) = x(12,'A4x4A4'); die "not LIST but $list" if $list ne 'LIST'; @@ -569,12 +572,15 @@ $h->{$n} = $v; } x($len, 'Vx28VVVx8CCv'); - printf "## %s %d*%d %s fps (%d ms/frame) %02d:%02d:%02d\n", + $duration = sprintf('%02d:%02d:%02d', $h->{hh}, $h->{mm}, $h->{ss} ); + + printf "## %s %d*%d %s fps (%d ms/frame) %s\n", $path, $h->{width}, $h->{height}, $h->{fps}, $h->{ms_per_frame}, - $h->{hh}, $h->{mm}, $h->{ss}; + $duration; $d->{amvh} = $h; + $fps = $h->{fps}; } elsif ( $name eq 'strl' ) { @@ -601,18 +607,15 @@ hex_dump( $audio_frame ); } - # remove 8 bytes of something -# $audio_frame = substr( $audio_frame, 8 ); - - if ( length($audio_frame) % 2 == 0 ) { - print "#### even sized frame!"; -# $audio_frame = substr( $audio_frame, 0, -1 ); - } - # print $audio_fh mp3_frame; audio_frame( $audio_frame ); $frame_nr++; + + if ( $frame_nr % $fps == 0 ) { + print "\n" if ( ( $frame_nr / $fps ) % 60 == 0 ); + print "."; + } }; } else { @@ -620,7 +623,7 @@ } } -my $cmd = "ffmpeg -i $dump_dir/%04d.jpg -r 16 -y $dump_avi"; +my $cmd = "ffmpeg -r $fps -i $dump_dir/%04d.jpg -i $au_path -y $dump_avi"; system($cmd) == 0 || die "can't convert frames to avi using $cmd: $!"; print ">>>> created $frame_nr frames $dump_avi ", -s $dump_avi, "\n";