/[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 30 by dpavlin, Fri Sep 14 19:35:32 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    
486            my $size = 0;
487    
488          foreach my $b ( map { ord($_) } split(//, substr($data,8)) ) {          foreach my $b ( map { ord($_) } split(//, substr($data,8)) ) {
489                  print $au_fh pack 'n', adpcm_decode_sample( $b >> 4 );                            print $au_fh pack 'n', adpcm_decode_sample( $b >> 4 );          
490                  print $au_fh pack 'n', adpcm_decode_sample( $b & 15 );                            print $au_fh pack 'n', adpcm_decode_sample( $b & 15 );          
491                    $size += 2;
492          }          }
493    
494            warn "length isn't corrent $bytes != $size" if $bytes != $size;
495  }  }
496    
497    
# Line 552  my ( $riff, $amv ) = x(12, 'Z4x4Z4'); Line 557  my ( $riff, $amv ) = x(12, 'Z4x4Z4');
557  die "$path not RIFF but $riff" if $riff ne 'RIFF';  die "$path not RIFF but $riff" if $riff ne 'RIFF';
558  die "$path not AMV but $amv" if $amv ne 'AMV ';  die "$path not AMV but $amv" if $amv ne 'AMV ';
559    
560    my $fps = 16;
561    my $duration;
562    
563  while ( ! defined($d->{eof}) ) {  while ( ! defined($d->{eof}) ) {
564          my ( $list, $name ) = x(12,'A4x4A4');          my ( $list, $name ) = x(12,'A4x4A4');
565          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 577  while ( ! defined($d->{eof}) ) {
577                          $h->{$n} = $v;                          $h->{$n} = $v;
578                  } x($len, 'Vx28VVVx8CCv');                  } x($len, 'Vx28VVVx8CCv');
579    
580                  printf "## %s %d*%d %s fps (%d ms/frame) %02d:%02d:%02d\n",                  $duration = sprintf('%02d:%02d:%02d', $h->{hh}, $h->{mm}, $h->{ss} );
581    
582                    printf "## %s %d*%d %s fps (%d ms/frame) %s\n",
583                          $path,                          $path,
584                          $h->{width}, $h->{height}, $h->{fps}, $h->{ms_per_frame},                          $h->{width}, $h->{height}, $h->{fps}, $h->{ms_per_frame},
585                          $h->{hh}, $h->{mm}, $h->{ss};                          $duration;
586    
587                  $d->{amvh} = $h;                  $d->{amvh} = $h;
588                    $fps = $h->{fps};
589    
590          } elsif ( $name eq 'strl' ) {          } elsif ( $name eq 'strl' ) {
591    
# Line 601  while ( ! defined($d->{eof}) ) { Line 612  while ( ! defined($d->{eof}) ) {
612                                  hex_dump( $audio_frame );                                  hex_dump( $audio_frame );
613                          }                          }
614    
                         # 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 );  
                         }  
   
615  #                       print $audio_fh mp3_frame;  #                       print $audio_fh mp3_frame;
616                          audio_frame( $audio_frame );                          audio_frame( $audio_frame );
617    
618                          $frame_nr++;                          $frame_nr++;
619    
620                            if ( $frame_nr % $fps == 0 ) {
621                                    print "\n" if ( ( $frame_nr / $fps ) % 60 == 0 );
622                                    print ".";
623                            }
624                  };                  };
625    
626          } else {          } else {
# Line 620  while ( ! defined($d->{eof}) ) { Line 628  while ( ! defined($d->{eof}) ) {
628          }          }
629  }  }
630    
631  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";
632  system($cmd) == 0 || die "can't convert frames to avi using $cmd: $!";  system($cmd) == 0 || die "can't convert frames to avi using $cmd: $!";
633    
634  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.30

  ViewVC Help
Powered by ViewVC 1.1.26