/[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 6 by dpavlin, Thu Jul 19 20:56:25 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            my $prefix = '#.';
33          while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {          while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {
34                  printf "## %0${d}x | %-48s| %s\n", $o, $1, substr( $ascii, 0, 16 );                  printf "$prefix %0${d}x | %-48s| %s\n", $o, $1, substr( $ascii, 0, 16 );
35                    $prefix = '##';
36                  if ( length($ascii) >= 16 ) {                  if ( length($ascii) >= 16 ) {
37                          $ascii = substr( $ascii, 16 );                          $ascii = substr( $ascii, 16 );
38                            $o += 16;
39                  } else {                  } else {
40                            $o += length($ascii);
41                          last;                          last;
42                  }                  }
                 $o += 16;  
43          }          }
44  }  }
45    
# Line 45  sub x { Line 54  sub x {
54    
55          hex_dump( $bytes );          hex_dump( $bytes );
56    
57            if ( $bytes eq 'AMV_END_' ) {
58                    warn "> end of file marker AMV_END_\n";
59                    $d->{eof}++;
60                    return;
61            }
62    
63          if ( $format ) {          if ( $format ) {
64                  my @data = unpack($format, $bytes);                  my @data = unpack($format, $bytes);
65                  dump(@data);                  warn "## unpacked = ",dump(@data),"\n";
66                  return @data;                  return @data;
67          } else {          } else {
68                  return $bytes;                  return $bytes;
# Line 57  sub x { Line 72  sub x {
72  sub next_part {  sub next_part {
73          my ( $expected_part, $expected_len, $skip ) = @_;          my ( $expected_part, $expected_len, $skip ) = @_;
74          my ( $part, $len ) = x(8,'A4V');          my ( $part, $len ) = x(8,'A4V');
75            return unless $len;
76          confess "not $expected_part but $part" if $expected_part ne $part;          confess "not $expected_part but $part" if $expected_part ne $part;
77          if ( $expected_len ) {          if ( $expected_len ) {
78                  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;
79          }          }
80          printf ">> %s | %d 0x%x bytes\n", $part, $len, $len;          printf ">> %s - %d 0x%x bytes\n", $part, $len, $len;
81          x($len) if $skip;          x($len) if $skip;
82          return $len;          return $len;
83  }  }
# Line 70  my ( $riff, $amv ) = x(12, 'Z8Z4'); Line 86  my ( $riff, $amv ) = x(12, 'Z8Z4');
86  die "not RIFF but $riff" if $riff ne 'RIFF';  die "not RIFF but $riff" if $riff ne 'RIFF';
87  die "not AMV but $amv" if $amv ne 'AMV ';  die "not AMV but $amv" if $amv ne 'AMV ';
88    
89  my $d;  while ( ! defined($d->{eof}) ) {
   
 while ( 1 ) {  
90          my ( $list, $name ) = x(12,'A4x4A4');          my ( $list, $name ) = x(12,'A4x4A4');
91          die "not LIST but $list" if $list ne 'LIST';          die "not LIST but $list" if $list ne 'LIST';
92          print "> $list .. $name\n";          print "> $list .. $name\n";
# Line 80  while ( 1 ) { Line 94  while ( 1 ) {
94          if ( $name eq 'hdrl' ) {          if ( $name eq 'hdrl' ) {
95    
96                  my $len = next_part( 'amvh', hex(38) );                  my $len = next_part( 'amvh', hex(38) );
           
                 print ">> $name $len\n";  
97    
                 my (  
                         $ms_per_frame,  
                         $width,  
                         $height,  
                         $fps,  
                         $ss,  
                         $mm,  
                         $hh,  
                 ) =  
98                  my @names = ( qw/ms_per_frame width height fps ss mm hh/ );                  my @names = ( qw/ms_per_frame width height fps ss mm hh/ );
99                  my $h;                  my $h;
100                  map {                  map {
# Line 112  while ( 1 ) { Line 115  while ( 1 ) {
115                  next_part( 'strh', 0, 1 );                  next_part( 'strh', 0, 1 );
116                  next_part( 'strf', 0, 1 );                  next_part( 'strf', 0, 1 );
117    
118            } elsif ( $name eq 'movi' ) {
119    
120                    while (1) {
121                            my $frame = $d->{movi}++;
122                    
123                            my $len = next_part( '00dc', 0, 1 );
124                            last unless $len;
125                            printf ">> %s 00dc - frame %d jpeg %d 0x%x bytes\n", $name, $frame, $len, $len;
126    
127                            my $len = next_part( '01wb', 0, 1 );
128                            printf ">> %s 01wb - frame %d audio %d 0x%x bytes\n", $name, $frame, $len, $len;
129                    };
130    
131          } else {          } else {
132                  die "unknown $list $name";                  die "unknown $list $name";
133          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26