/[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

Annotation of /amv.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (hide annotations)
Thu Jul 19 20:56:25 2007 UTC (11 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 2913 byte(s)
show beginning of hex_dump with #. istead of ## to be better noticable in output
1 dpavlin 3 #!/usr/bin/perl -w
2    
3     # amv.pl
4     #
5     # 07/19/07 19:21:39 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6    
7     use strict;
8    
9     use Data::Dump qw/dump/;
10     use Carp qw/confess/;
11    
12     my $path = shift @ARGV || die "usage: $0 movie.amv\n";
13    
14     open(my $fh, '<', $path) || die "can't open $path: $!";
15    
16 dpavlin 4 # offset in file
17     my $o = 0;
18    
19     # shared data hash
20     my $d;
21    
22 dpavlin 3 sub hex_dump {
23     my $bytes = shift || return;
24    
25     my $ascii = $bytes;
26     $ascii =~ s/\W/./gs;
27     my $hex = unpack('h*', $bytes);
28     $hex =~ s/(..)/$1 /g;
29     # calculate number of characters for offset
30 dpavlin 4 #my $d = length( sprintf("%x",length($bytes)) );
31     my $d = 4;
32 dpavlin 6 my $prefix = '#.';
33 dpavlin 3 while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {
34 dpavlin 6 printf "$prefix %0${d}x | %-48s| %s\n", $o, $1, substr( $ascii, 0, 16 );
35     $prefix = '##';
36 dpavlin 3 if ( length($ascii) >= 16 ) {
37     $ascii = substr( $ascii, 16 );
38 dpavlin 4 $o += 16;
39 dpavlin 3 } else {
40 dpavlin 4 $o += length($ascii);
41 dpavlin 3 last;
42     }
43     }
44     }
45    
46     sub x {
47     my ($len,$format) = @_;
48    
49     my $bytes;
50     read($fh, $bytes, $len);
51    
52     my $r_len = length($bytes);
53     confess "read $r_len bytes, expected $len" if $len != $r_len;
54    
55     hex_dump( $bytes );
56    
57 dpavlin 4 if ( $bytes eq 'AMV_END_' ) {
58 dpavlin 5 warn "> end of file marker AMV_END_\n";
59 dpavlin 4 $d->{eof}++;
60     return;
61     }
62    
63 dpavlin 3 if ( $format ) {
64     my @data = unpack($format, $bytes);
65 dpavlin 4 warn "## unpacked = ",dump(@data),"\n";
66 dpavlin 3 return @data;
67     } else {
68     return $bytes;
69     }
70     }
71    
72     sub next_part {
73     my ( $expected_part, $expected_len, $skip ) = @_;
74     my ( $part, $len ) = x(8,'A4V');
75 dpavlin 4 return unless $len;
76 dpavlin 3 confess "not $expected_part but $part" if $expected_part ne $part;
77     if ( $expected_len ) {
78     confess "expected $expected_len bytes for $part got $len" if $len != $expected_len;
79     }
80 dpavlin 5 printf ">> %s - %d 0x%x bytes\n", $part, $len, $len;
81 dpavlin 3 x($len) if $skip;
82     return $len;
83     }
84    
85     my ( $riff, $amv ) = x(12, 'Z8Z4');
86     die "not RIFF but $riff" if $riff ne 'RIFF';
87     die "not AMV but $amv" if $amv ne 'AMV ';
88    
89 dpavlin 4 while ( ! defined($d->{eof}) ) {
90 dpavlin 3 my ( $list, $name ) = x(12,'A4x4A4');
91     die "not LIST but $list" if $list ne 'LIST';
92     print "> $list .. $name\n";
93    
94     if ( $name eq 'hdrl' ) {
95    
96     my $len = next_part( 'amvh', hex(38) );
97    
98     my @names = ( qw/ms_per_frame width height fps ss mm hh/ );
99     my $h;
100     map {
101     my $v = $_;
102     my $n = shift @names || die "no more names?";
103     $h->{$n} = $v;
104     } x($len, 'Vx28VVVx8CCv');
105    
106     printf "## %s %d*%d %s fps (%d ms/frame) %02d:%02d:%02d\n",
107     $h->{path},
108     $h->{width}, $h->{height}, $h->{fps}, $h->{ms_per_frame},
109     $h->{hh}, $h->{mm}, $h->{ss};
110    
111     $d->{amvh} = $h;
112    
113     } elsif ( $name eq 'strl' ) {
114    
115     next_part( 'strh', 0, 1 );
116     next_part( 'strf', 0, 1 );
117    
118 dpavlin 4 } 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 dpavlin 3 } else {
132     die "unknown $list $name";
133     }
134     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26