/[amv]/amv.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

Diff of /amv.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 28 by dpavlin, Sun Aug 19 11:45:39 2007 UTC revision 29 by dpavlin, Sun Aug 19 19:23:03 2007 UTC
# Line 46  GetOptions( Line 46  GetOptions(
46  my $path = shift @ARGV || die "usage: $0 movie.amv\n";  my $path = shift @ARGV || die "usage: $0 movie.amv\n";
47    
48  # by default, flip frames  # by default, flip frames
49  #$jpegtran = '-flip vertical' unless defined($jpegtran);  $jpegtran = '-flip vertical' unless defined($jpegtran);
50    
51  rmtree $dump_dir if -e $dump_dir;  rmtree $dump_dir if -e $dump_dir;
52  mkpath $dump_dir || die "can't create $dump_dir: $!";  mkpath $dump_dir || die "can't create $dump_dir: $!";
53    
54    $| = 1;
55    
56  open(my $fh, '<', $path) || die "can't open $path: $!";  open(my $fh, '<', $path) || die "can't open $path: $!";
57    
58  # offset in file  # offset in file
# Line 456  sub adpcm_decode_sample { Line 458  sub adpcm_decode_sample {
458          return $pred_val;          return $pred_val;
459  }  }
460    
461  open(my $au_fh, '>', 'out.au') || die "can't open out.au: $!";  my $au_path = "$dump_dir/sound.au";
462    open(my $au_fh, '>', $au_path) || die "can't open $au_path: $!";
463  print $au_fh pack 'a4N5', (  print $au_fh pack 'a4N5', (
464          # magic          # magic
465          '.snd',          '.snd',
# Line 477  sub audio_frame { Line 480  sub audio_frame {
480    
481          my ( $origin, $index, $bytes ) = unpack 'ssL', substr($data,0,8);          my ( $origin, $index, $bytes ) = unpack 'ssL', substr($data,0,8);
482    
 warn "audio_frame origin $origin index $index bytes $bytes\n";  
 hex_dump( substr($data,0,8) );  
   
483          $pred_val = $origin;          $pred_val = $origin;
484          $step_idx = $index;          $step_idx = $index;
485    
# Line 552  my ( $riff, $amv ) = x(12, 'Z4x4Z4'); Line 552  my ( $riff, $amv ) = x(12, 'Z4x4Z4');
552  die "$path not RIFF but $riff" if $riff ne 'RIFF';  die "$path not RIFF but $riff" if $riff ne 'RIFF';
553  die "$path not AMV but $amv" if $amv ne 'AMV ';  die "$path not AMV but $amv" if $amv ne 'AMV ';
554    
555    my $fps = 16;
556    my $duration;
557    
558  while ( ! defined($d->{eof}) ) {  while ( ! defined($d->{eof}) ) {
559          my ( $list, $name ) = x(12,'A4x4A4');          my ( $list, $name ) = x(12,'A4x4A4');
560          die "not LIST but $list" if $list ne 'LIST';          die "not LIST but $list" if $list ne 'LIST';
# Line 569  while ( ! defined($d->{eof}) ) { Line 572  while ( ! defined($d->{eof}) ) {
572                          $h->{$n} = $v;                          $h->{$n} = $v;
573                  } x($len, 'Vx28VVVx8CCv');                  } x($len, 'Vx28VVVx8CCv');
574    
575                  printf "## %s %d*%d %s fps (%d ms/frame) %02d:%02d:%02d\n",                  $duration = sprintf('%02d:%02d:%02d', $h->{hh}, $h->{mm}, $h->{ss} );
576    
577                    printf "## %s %d*%d %s fps (%d ms/frame) %s\n",
578                          $path,                          $path,
579                          $h->{width}, $h->{height}, $h->{fps}, $h->{ms_per_frame},                          $h->{width}, $h->{height}, $h->{fps}, $h->{ms_per_frame},
580                          $h->{hh}, $h->{mm}, $h->{ss};                          $duration;
581    
582                  $d->{amvh} = $h;                  $d->{amvh} = $h;
583                    $fps = $h->{fps};
584    
585          } elsif ( $name eq 'strl' ) {          } elsif ( $name eq 'strl' ) {
586    
# Line 601  while ( ! defined($d->{eof}) ) { Line 607  while ( ! defined($d->{eof}) ) {
607                                  hex_dump( $audio_frame );                                  hex_dump( $audio_frame );
608                          }                          }
609    
                         # 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 );  
                         }  
   
610  #                       print $audio_fh mp3_frame;  #                       print $audio_fh mp3_frame;
611                          audio_frame( $audio_frame );                          audio_frame( $audio_frame );
612    
613                          $frame_nr++;                          $frame_nr++;
614    
615                            if ( $frame_nr % $fps == 0 ) {
616                                    print "\n" if ( ( $frame_nr / $fps ) % 60 == 0 );
617                                    print ".";
618                            }
619                  };                  };
620    
621          } else {          } else {
# Line 620  while ( ! defined($d->{eof}) ) { Line 623  while ( ! defined($d->{eof}) ) {
623          }          }
624  }  }
625    
626  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";
627  system($cmd) == 0 || die "can't convert frames to avi using $cmd: $!";  system($cmd) == 0 || die "can't convert frames to avi using $cmd: $!";
628    
629  print ">>>> created $frame_nr frames $dump_avi ", -s $dump_avi, "\n";  print ">>>> created $frame_nr frames $dump_avi ", -s $dump_avi, "\n";

Legend:
Removed from v.28  
changed lines
  Added in v.29

  ViewVC Help
Powered by ViewVC 1.1.26