/[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 3 by dpavlin, Thu Jul 19 20:17:37 2007 UTC revision 4 by dpavlin, Thu Jul 19 20:49:06 2007 UTC
# Line 13  my $path = shift @ARGV || die "usage: $0 Line 13  my $path = shift @ARGV || die "usage: $0
13    
14  open(my $fh, '<', $path) || die "can't open $path: $!";  open(my $fh, '<', $path) || die "can't open $path: $!";
15    
16    # offset in file
17    my $o = 0;
18    
19    # shared data hash
20    my $d;
21    
22  sub hex_dump {  sub hex_dump {
23          my $bytes = shift || return;          my $bytes = shift || return;
24    
# Line 20  sub hex_dump { Line 26  sub hex_dump {
26          $ascii =~ s/\W/./gs;          $ascii =~ s/\W/./gs;
27          my $hex = unpack('h*', $bytes);          my $hex = unpack('h*', $bytes);
28          $hex =~ s/(..)/$1 /g;          $hex =~ s/(..)/$1 /g;
         my $o = 0;  
29          # calculate number of characters for offset          # calculate number of characters for offset
30          my $d = length( sprintf("%x",length($bytes)) );          #my $d = length( sprintf("%x",length($bytes)) );
31            my $d = 4;
32          while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {          while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {
33                  printf "## %0${d}x | %-48s| %s\n", $o, $1, substr( $ascii, 0, 16 );                  printf "## %0${d}x | %-48s| %s\n", $o, $1, substr( $ascii, 0, 16 );
34                  if ( length($ascii) >= 16 ) {                  if ( length($ascii) >= 16 ) {
35                          $ascii = substr( $ascii, 16 );                          $ascii = substr( $ascii, 16 );
36                            $o += 16;
37                  } else {                  } else {
38                            $o += length($ascii);
39                          last;                          last;
40                  }                  }
                 $o += 16;  
41          }          }
42  }  }
43    
# Line 45  sub x { Line 52  sub x {
52    
53          hex_dump( $bytes );          hex_dump( $bytes );
54    
55            if ( $bytes eq 'AMV_END_' ) {
56                    warn "## end of file marker AMV_END_\n";
57                    $d->{eof}++;
58                    return;
59            }
60    
61          if ( $format ) {          if ( $format ) {
62                  my @data = unpack($format, $bytes);                  my @data = unpack($format, $bytes);
63                  dump(@data);                  warn "## unpacked = ",dump(@data),"\n";
64                  return @data;                  return @data;
65          } else {          } else {
66                  return $bytes;                  return $bytes;
# Line 57  sub x { Line 70  sub x {
70  sub next_part {  sub next_part {
71          my ( $expected_part, $expected_len, $skip ) = @_;          my ( $expected_part, $expected_len, $skip ) = @_;
72          my ( $part, $len ) = x(8,'A4V');          my ( $part, $len ) = x(8,'A4V');
73            return unless $len;
74          confess "not $expected_part but $part" if $expected_part ne $part;          confess "not $expected_part but $part" if $expected_part ne $part;
75          if ( $expected_len ) {          if ( $expected_len ) {
76                  confess "expected $expected_len bytes for $part got $len" if $len != $expected_len;                  confess "expected $expected_len bytes for $part got $len" if $len != $expected_len;
77          }          }
78          printf ">> %s | %d 0x%x bytes\n", $part, $len, $len;          printf ">>> %s | %d 0x%x bytes\n", $part, $len, $len;
79          x($len) if $skip;          x($len) if $skip;
80          return $len;          return $len;
81  }  }
# Line 70  my ( $riff, $amv ) = x(12, 'Z8Z4'); Line 84  my ( $riff, $amv ) = x(12, 'Z8Z4');
84  die "not RIFF but $riff" if $riff ne 'RIFF';  die "not RIFF but $riff" if $riff ne 'RIFF';
85  die "not AMV but $amv" if $amv ne 'AMV ';  die "not AMV but $amv" if $amv ne 'AMV ';
86    
87  my $d;  while ( ! defined($d->{eof}) ) {
   
 while ( 1 ) {  
88          my ( $list, $name ) = x(12,'A4x4A4');          my ( $list, $name ) = x(12,'A4x4A4');
89          die "not LIST but $list" if $list ne 'LIST';          die "not LIST but $list" if $list ne 'LIST';
90          print "> $list .. $name\n";          print "> $list .. $name\n";
# Line 80  while ( 1 ) { Line 92  while ( 1 ) {
92          if ( $name eq 'hdrl' ) {          if ( $name eq 'hdrl' ) {
93    
94                  my $len = next_part( 'amvh', hex(38) );                  my $len = next_part( 'amvh', hex(38) );
           
                 print ">> $name $len\n";  
95    
                 my (  
                         $ms_per_frame,  
                         $width,  
                         $height,  
                         $fps,  
                         $ss,  
                         $mm,  
                         $hh,  
                 ) =  
96                  my @names = ( qw/ms_per_frame width height fps ss mm hh/ );                  my @names = ( qw/ms_per_frame width height fps ss mm hh/ );
97                  my $h;                  my $h;
98                  map {                  map {
# Line 112  while ( 1 ) { Line 113  while ( 1 ) {
113                  next_part( 'strh', 0, 1 );                  next_part( 'strh', 0, 1 );
114                  next_part( 'strf', 0, 1 );                  next_part( 'strf', 0, 1 );
115    
116            } elsif ( $name eq 'movi' ) {
117    
118                    while (1) {
119                            my $frame = $d->{movi}++;
120                    
121                            my $len = next_part( '00dc', 0, 1 );
122                            last unless $len;
123                            printf ">> %s 00dc - frame %d jpeg %d 0x%x bytes\n", $name, $frame, $len, $len;
124    
125                            my $len = next_part( '01wb', 0, 1 );
126                            printf ">> %s 01wb - frame %d audio %d 0x%x bytes\n", $name, $frame, $len, $len;
127                    };
128    
129          } else {          } else {
130                  die "unknown $list $name";                  die "unknown $list $name";
131          }          }

Legend:
Removed from v.3  
changed lines
  Added in v.4

  ViewVC Help
Powered by ViewVC 1.1.26