/[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 7 by dpavlin, Thu Jul 19 21:16:30 2007 UTC
# Line 3  Line 3 
3  # amv.pl  # amv.pl
4  #  #
5  # 07/19/07 19:21:39 CEST Dobrica Pavlinusic <dpavlin@rot13.org>  # 07/19/07 19:21:39 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6    #
7    # Various useful links used to produce this:
8    # http://www.moviecodec.com/topics/15431p1.html
9    # http://en.wikipedia.org/wiki/RIFF_(File_format)
10    
11  use strict;  use strict;
12    
# Line 13  my $path = shift @ARGV || die "usage: $0 Line 17  my $path = shift @ARGV || die "usage: $0
17    
18  open(my $fh, '<', $path) || die "can't open $path: $!";  open(my $fh, '<', $path) || die "can't open $path: $!";
19    
20    # offset in file
21    my $o = 0;
22    
23    # shared data hash
24    my $d;
25    
26  sub hex_dump {  sub hex_dump {
27          my $bytes = shift || return;          my $bytes = shift || return;
28    
# Line 20  sub hex_dump { Line 30  sub hex_dump {
30          $ascii =~ s/\W/./gs;          $ascii =~ s/\W/./gs;
31          my $hex = unpack('h*', $bytes);          my $hex = unpack('h*', $bytes);
32          $hex =~ s/(..)/$1 /g;          $hex =~ s/(..)/$1 /g;
         my $o = 0;  
33          # calculate number of characters for offset          # calculate number of characters for offset
34          my $d = length( sprintf("%x",length($bytes)) );          #my $d = length( sprintf("%x",length($bytes)) );
35            my $d = 4;
36            my $prefix = '#.';
37          while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {          while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {
38                  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 );
39                    $prefix = '##';
40                  if ( length($ascii) >= 16 ) {                  if ( length($ascii) >= 16 ) {
41                          $ascii = substr( $ascii, 16 );                          $ascii = substr( $ascii, 16 );
42                            $o += 16;
43                  } else {                  } else {
44                            $o += length($ascii);
45                          last;                          last;
46                  }                  }
                 $o += 16;  
47          }          }
48  }  }
49    
# Line 45  sub x { Line 58  sub x {
58    
59          hex_dump( $bytes );          hex_dump( $bytes );
60    
61            if ( $bytes eq 'AMV_END_' ) {
62                    warn "> end of file marker AMV_END_\n";
63                    $d->{eof}++;
64                    return;
65            }
66    
67          if ( $format ) {          if ( $format ) {
68                  my @data = unpack($format, $bytes);                  my @data = unpack($format, $bytes);
69                  dump(@data);                  warn "## unpacked = ",dump(@data),"\n";
70                  return @data;                  return @data;
71          } else {          } else {
72                  return $bytes;                  return $bytes;
# Line 57  sub x { Line 76  sub x {
76  sub next_part {  sub next_part {
77          my ( $expected_part, $expected_len, $skip ) = @_;          my ( $expected_part, $expected_len, $skip ) = @_;
78          my ( $part, $len ) = x(8,'A4V');          my ( $part, $len ) = x(8,'A4V');
79            return unless $len;
80          confess "not $expected_part but $part" if $expected_part ne $part;          confess "not $expected_part but $part" if $expected_part ne $part;
81          if ( $expected_len ) {          if ( $expected_len ) {
82                  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;
83          }          }
84          printf ">> %s | %d 0x%x bytes\n", $part, $len, $len;          printf ">> %s - %d 0x%x bytes\n", $part, $len, $len;
85          x($len) if $skip;          x($len) if $skip;
86          return $len;          return $len;
87  }  }
# Line 70  my ( $riff, $amv ) = x(12, 'Z8Z4'); Line 90  my ( $riff, $amv ) = x(12, 'Z8Z4');
90  die "not RIFF but $riff" if $riff ne 'RIFF';  die "not RIFF but $riff" if $riff ne 'RIFF';
91  die "not AMV but $amv" if $amv ne 'AMV ';  die "not AMV but $amv" if $amv ne 'AMV ';
92    
93  my $d;  while ( ! defined($d->{eof}) ) {
   
 while ( 1 ) {  
94          my ( $list, $name ) = x(12,'A4x4A4');          my ( $list, $name ) = x(12,'A4x4A4');
95          die "not LIST but $list" if $list ne 'LIST';          die "not LIST but $list" if $list ne 'LIST';
96          print "> $list .. $name\n";          print "> $list .. $name\n";
# Line 80  while ( 1 ) { Line 98  while ( 1 ) {
98          if ( $name eq 'hdrl' ) {          if ( $name eq 'hdrl' ) {
99    
100                  my $len = next_part( 'amvh', hex(38) );                  my $len = next_part( 'amvh', hex(38) );
           
                 print ">> $name $len\n";  
101    
                 my (  
                         $ms_per_frame,  
                         $width,  
                         $height,  
                         $fps,  
                         $ss,  
                         $mm,  
                         $hh,  
                 ) =  
102                  my @names = ( qw/ms_per_frame width height fps ss mm hh/ );                  my @names = ( qw/ms_per_frame width height fps ss mm hh/ );
103                  my $h;                  my $h;
104                  map {                  map {
# Line 112  while ( 1 ) { Line 119  while ( 1 ) {
119                  next_part( 'strh', 0, 1 );                  next_part( 'strh', 0, 1 );
120                  next_part( 'strf', 0, 1 );                  next_part( 'strf', 0, 1 );
121    
122            } elsif ( $name eq 'movi' ) {
123    
124                    while (1) {
125                            my $frame = $d->{movi}++;
126                    
127                            my $len = next_part( '00dc', 0, 1 );
128                            last unless $len;
129                            printf ">> %s 00dc - frame %d jpeg %d 0x%x bytes\n", $name, $frame, $len, $len;
130    
131                            my $len = next_part( '01wb', 0, 1 );
132                            printf ">> %s 01wb - frame %d audio %d 0x%x bytes\n", $name, $frame, $len, $len;
133                    };
134    
135          } else {          } else {
136                  die "unknown $list $name";                  die "unknown $list $name";
137          }          }

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

  ViewVC Help
Powered by ViewVC 1.1.26