/[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 16 - (hide annotations)
Sat Jul 21 11:18:15 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 14325 byte(s)
use width and height from header
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 dpavlin 7 #
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 dpavlin 8 # http://www.obrador.com/essentialjpeg/HeaderInfo.htm
11     # http://lists.helixcommunity.org/pipermail/datatype-dev/2005-January/001886.html
12 dpavlin 3
13     use strict;
14    
15     use Data::Dump qw/dump/;
16     use Carp qw/confess/;
17 dpavlin 8 use File::Path;
18 dpavlin 15 use Getopt::Long;
19 dpavlin 3
20 dpavlin 8 my $dump = 0;
21     my $debug = 0;
22 dpavlin 15 my $dump_dir = '/tmp/dump/';
23 dpavlin 8
24 dpavlin 15 GetOptions(
25     "dump!" => \$dump,
26     "debug!" => \$debug,
27     "dump-dir=s" => \$dump_dir,
28     );
29    
30 dpavlin 3 my $path = shift @ARGV || die "usage: $0 movie.amv\n";
31    
32 dpavlin 15
33 dpavlin 11 rmtree $dump_dir if -e $dump_dir;
34     mkpath $dump_dir || die "can't create $dump_dir: $!";
35 dpavlin 8
36 dpavlin 3 open(my $fh, '<', $path) || die "can't open $path: $!";
37    
38 dpavlin 4 # offset in file
39     my $o = 0;
40    
41     # shared data hash
42     my $d;
43    
44 dpavlin 3 sub hex_dump {
45 dpavlin 8 return unless $dump;
46 dpavlin 3
47 dpavlin 8 my ( $bytes, $offset ) = @_;
48     return unless $bytes;
49    
50     my $old_o;
51     if (defined($offset)) {
52     $old_o = $o;
53     $o = $offset;
54     }
55    
56 dpavlin 3 my $ascii = $bytes;
57     $ascii =~ s/\W/./gs;
58 dpavlin 8 my $hex = uc( unpack('h*', $bytes) );
59 dpavlin 3 $hex =~ s/(..)/$1 /g;
60     # calculate number of characters for offset
61 dpavlin 4 #my $d = length( sprintf("%x",length($bytes)) );
62     my $d = 4;
63 dpavlin 6 my $prefix = '#.';
64 dpavlin 3 while ( $hex =~ s/^((?:\w\w\s){1,16})// ) {
65 dpavlin 6 printf "$prefix %0${d}x | %-48s| %s\n", $o, $1, substr( $ascii, 0, 16 );
66     $prefix = '##';
67 dpavlin 3 if ( length($ascii) >= 16 ) {
68     $ascii = substr( $ascii, 16 );
69 dpavlin 4 $o += 16;
70 dpavlin 3 } else {
71 dpavlin 4 $o += length($ascii);
72 dpavlin 3 last;
73     }
74     }
75 dpavlin 8
76     $o = $old_o if $old_o;
77 dpavlin 3 }
78    
79     sub x {
80     my ($len,$format) = @_;
81    
82     my $bytes;
83     read($fh, $bytes, $len);
84    
85     my $r_len = length($bytes);
86     confess "read $r_len bytes, expected $len" if $len != $r_len;
87    
88     hex_dump( $bytes );
89    
90 dpavlin 4 if ( $bytes eq 'AMV_END_' ) {
91 dpavlin 5 warn "> end of file marker AMV_END_\n";
92 dpavlin 4 $d->{eof}++;
93     return;
94     }
95    
96 dpavlin 3 if ( $format ) {
97     my @data = unpack($format, $bytes);
98 dpavlin 8 warn "## unpacked = ",dump(@data),"\n" if $debug;
99 dpavlin 3 return @data;
100     } else {
101     return $bytes;
102     }
103     }
104    
105     sub next_part {
106     my ( $expected_part, $expected_len, $skip ) = @_;
107     my ( $part, $len ) = x(8,'A4V');
108 dpavlin 4 return unless $len;
109 dpavlin 3 confess "not $expected_part but $part" if $expected_part ne $part;
110     if ( $expected_len ) {
111     confess "expected $expected_len bytes for $part got $len" if $len != $expected_len;
112     }
113 dpavlin 8 printf "<< %s - %d 0x%x bytes\n", $part, $len, $len;
114 dpavlin 3 x($len) if $skip;
115     return $len;
116     }
117    
118 dpavlin 8 sub huffman {
119 dpavlin 3
120 dpavlin 8 # JPEG DHT Segment for YCrCb omitted from MJPG data
121     return
122     "\xFF\xC4\x01\xA2" .
123     "\x00\x00\x01\x05\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00" .
124     "\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x01" .
125     "\x00\x03\x01\x01\x01\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00" .
126     "\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x10\x00" .
127     "\x02\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01\x7D" .
128     "\x01\x02\x03\x00\x04\x11\x05\x12\x21\x31\x41\x06\x13\x51\x61" .
129     "\x07\x22\x71\x14\x32\x81\x91\xA1\x08\x23\x42\xB1\xC1\x15\x52" .
130     "\xD1\xF0\x24\x33\x62\x72\x82\x09\x0A\x16\x17\x18\x19\x1A\x25" .
131     "\x26\x27\x28\x29\x2A\x34\x35\x36\x37\x38\x39\x3A\x43\x44\x45" .
132     "\x46\x47\x48\x49\x4A\x53\x54\x55\x56\x57\x58\x59\x5A\x63\x64" .
133     "\x65\x66\x67\x68\x69\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x83" .
134     "\x84\x85\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96\x97\x98\x99" .
135     "\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xB2\xB3\xB4\xB5\xB6" .
136     "\xB7\xB8\xB9\xBA\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xD2\xD3" .
137     "\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8" .
138     "\xE9\xEA\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\x11\x00\x02" .
139     "\x01\x02\x04\x04\x03\x04\x07\x05\x04\x04\x00\x01\x02\x77\x00" .
140     "\x01\x02\x03\x11\x04\x05\x21\x31\x06\x12\x41\x51\x07\x61\x71" .
141     "\x13\x22\x32\x81\x08\x14\x42\x91\xA1\xB1\xC1\x09\x23\x33\x52" .
142     "\xF0\x15\x62\x72\xD1\x0A\x16\x24\x34\xE1\x25\xF1\x17\x18\x19" .
143     "\x1A\x26\x27\x28\x29\x2A\x35\x36\x37\x38\x39\x3A\x43\x44\x45" .
144     "\x46\x47\x48\x49\x4A\x53\x54\x55\x56\x57\x58\x59\x5A\x63\x64" .
145     "\x65\x66\x67\x68\x69\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x82" .
146     "\x83\x84\x85\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96\x97\x98" .
147     "\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xB2\xB3\xB4\xB5" .
148     "\xB6\xB7\xB8\xB9\xBA\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xD2" .
149     "\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xE2\xE3\xE4\xE5\xE6\xE7\xE8" .
150     "\xE9\xEA\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA";
151    
152     }
153    
154     sub mkjpg {
155     my ($path,$data) = @_;
156     open(my $fh, '>', $path) || die "can't create $path: $!";
157    
158     confess "no SOI marker in data" if substr($data,0,2) ne "\xFF\xD8";
159     $data = substr($data,2);
160    
161 dpavlin 16 my $w = $d->{amvh}->{width} || die "no width?";
162     my $h = $d->{amvh}->{height} || confess "no height?";
163    
164 dpavlin 8 my $header =
165     "\xFF\xD8". # Start of Image (SOI) marker
166     #------------------------------------------------------------------
167     "\xFF\xE0". # JFIF marker
168     pack("nZ5CCCnnCC",
169     16, # length
170     'JFIF', # identifier
171     1,1, # version
172     0, # units (none)
173     1,1, # X,Y density
174     0,0, # X,Y thumbnail
175     ).
176     #------------------------------------------------------------------
177 dpavlin 11 "\xFF\xC0". # Start of frame
178 dpavlin 8 pack("ncnncc9",
179     17, # len
180     8, # sample precision in bits
181 dpavlin 16 $h,$w, # X,Y size
182 dpavlin 8 3, # number of components
183 dpavlin 11 1,0x21,0, # Component ID, H+V sampling factors, Quantization table number
184     2,0x11,1,
185     3,0x11,1,
186 dpavlin 8 ).
187     #------------------------------------------------------------------
188 dpavlin 11 "\xFF\xDB". # Define Quantization table marker
189     "\x00\x84". # len
190     "\x00". # 8 bit values, (byte) table 0
191     "\x10\x0B\x0C\x0E\x0C".
192     "\x0A\x10\x0E\x0D\x0E".
193     "\x12\x11\x10\x13\x18".
194     "\x28\x1A\x18\x16\x16".
195     "\x18\x31\x23\x25\x1D".
196     "\x28\x3A\x33\x3D\x3C".
197     "\x39\x33\x38\x37\x40".
198     "\x48\x5C\x4E\x40\x44".
199     "\x57\x45\x37\x38\x50".
200     "\x6D\x51\x57\x5F\x62".
201     "\x67\x68\x67\x3E\x4D".
202     "\x71\x79\x70\x64\x78".
203     "\x5C\x65\x67\x63".
204     "\x01". # 8 bit values, (byte) table 1
205     "\x11\x12\x12\x18\x15".
206     "\x18\x2F\x1A\x1A\x2F".
207     "\x63\x42\x38\x42\x63".
208     "\x63\x63\x63\x63\x63".
209     "\x63\x63\x63\x63\x63".
210     "\x63\x63\x63\x63\x63".
211     "\x63\x63\x63\x63\x63".
212     "\x63\x63\x63\x63\x63".
213     "\x63\x63\x63\x63\x63".
214     "\x63\x63\x63\x63\x63".
215     "\x63\x63\x63\x63\x63".
216     "\x63\x63\x63\x63\x63".
217     "\x63\x63\x63\x63".
218     #------------------------------------------------------------------
219 dpavlin 8 # huffman("\x00"). # 0 DC
220 dpavlin 11 # huffman("\x01"). # 1 DC
221 dpavlin 8 # huffman("\x10"). # 0 AC
222     # huffman("\x11"). # 1 AC
223     #------------------------------------------------------------------
224 dpavlin 11 # Define huffman table (section B.2.4.1)
225     "\xFF\xC4". # Marker
226     "\x00\x1F". # Length (31 bytes)
227     "\x00". # DC, (byte) table 0
228     "\x00\x01\x05\x01\x01".
229     "\x01\x01\x01\x01\x00".
230     "\x00\x00\x00\x00\x00".
231     "\x00\x00\x01\x02\x03".
232     "\x04\x05\x06\x07\x08".
233     "\x09\x0A\x0B".
234     # Define huffman table (section B.2.4.1)
235     "\xFF\xC4". # Marker
236     "\x00\xB5". # Length (181 bytes)
237     "\x10". # AC, (byte) table 0
238     "\x00\x02\x01\x03\x03".
239     "\x02\x04\x03\x05\x05".
240     "\x04\x04\x00\x00\x01".
241     "\x7D\x01\x02\x03\x00".
242     "\x04\x11\x05\x12\x21".
243     "\x31\x41\x06\x13\x51".
244     "\x61\x07\x22\x71\x14".
245     "\x32\x81\x91\xA1\x08".
246     "\x23\x42\xB1\xC1\x15".
247     "\x52\xD1\xF0\x24\x33".
248     "\x62\x72\x82\x09\x0A".
249     "\x16\x17\x18\x19\x1A".
250     "\x25\x26\x27\x28\x29".
251     "\x2A\x34\x35\x36\x37".
252     "\x38\x39\x3A\x43\x44".
253     "\x45\x46\x47\x48\x49".
254     "\x4A\x53\x54\x55\x56".
255     "\x57\x58\x59\x5A\x63".
256     "\x64\x65\x66\x67\x68".
257     "\x69\x6A\x73\x74\x75".
258     "\x76\x77\x78\x79\x7A".
259     "\x83\x84\x85\x86\x87".
260     "\x88\x89\x8A\x92\x93".
261     "\x94\x95\x96\x97\x98".
262     "\x99\x9A\xA2\xA3\xA4".
263     "\xA5\xA6\xA7\xA8\xA9".
264     "\xAA\xB2\xB3\xB4\xB5".
265     "\xB6\xB7\xB8\xB9\xBA".
266     "\xC2\xC3\xC4\xC5\xC6".
267     "\xC7\xC8\xC9\xCA\xD2".
268     "\xD3\xD4\xD5\xD6\xD7".
269     "\xD8\xD9\xDA\xE1\xE2".
270     "\xE3\xE4\xE5\xE6\xE7".
271     "\xE8\xE9\xEA\xF1\xF2".
272     "\xF3\xF4\xF5\xF6\xF7".
273     "\xF8\xF9\xFA".
274     # Define huffman table (section B.2.4.1)
275     "\xFF\xC4". # Marker
276     "\x00\x1F". # Length (31 bytes)
277     "\x01". # DC, (byte) table 1
278     "\x00\x03\x01\x01\x01".
279     "\x01\x01\x01\x01\x01".
280     "\x01\x00\x00\x00\x00".
281     "\x00\x00\x01\x02\x03".
282     "\x04\x05\x06\x07\x08".
283     "\x09\x0A\x0B".
284     # Define huffman table (section B.2.4.1)
285     "\xFF\xC4". # Marker
286     "\x00\xB5". # Length (181 bytes)
287     "\x11". # AC, (byte) table 1
288     "\x00\x02\x01\x02\x04".
289     "\x04\x03\x04\x07\x05".
290     "\x04\x04\x00\x01\x02".
291     "\x77\x00\x01\x02\x03".
292     "\x11\x04\x05\x21\x31".
293     "\x06\x12\x41\x51\x07".
294     "\x61\x71\x13\x22\x32".
295     "\x81\x08\x14\x42\x91".
296     "\xA1\xB1\xC1\x09\x23".
297     "\x33\x52\xF0\x15\x62".
298     "\x72\xD1\x0A\x16\x24".
299     "\x34\xE1\x25\xF1\x17".
300     "\x18\x19\x1A\x26\x27".
301     "\x28\x29\x2A\x35\x36".
302     "\x37\x38\x39\x3A\x43".
303     "\x44\x45\x46\x47\x48".
304     "\x49\x4A\x53\x54\x55".
305     "\x56\x57\x58\x59\x5A".
306     "\x63\x64\x65\x66\x67".
307     "\x68\x69\x6A\x73\x74".
308     "\x75\x76\x77\x78\x79".
309     "\x7A\x82\x83\x84\x85".
310     "\x86\x87\x88\x89\x8A".
311     "\x92\x93\x94\x95\x96".
312     "\x97\x98\x99\x9A\xA2".
313     "\xA3\xA4\xA5\xA6\xA7".
314     "\xA8\xA9\xAA\xB2\xB3".
315     "\xB4\xB5\xB6\xB7\xB8".
316     "\xB9\xBA\xC2\xC3\xC4".
317     "\xC5\xC6\xC7\xC8\xC9".
318     "\xCA\xD2\xD3\xD4\xD5".
319     "\xD6\xD7\xD8\xD9\xDA".
320     "\xE2\xE3\xE4\xE5\xE6".
321     "\xE7\xE8\xE9\xEA\xF2".
322     "\xF3\xF4\xF5\xF6\xF7".
323     "\xF8\xF9\xFA".
324     #------------------------------------------------------------------
325 dpavlin 8 "\xFF\xDA". # Start of Scan marker
326     pack("nC11",
327     12, # length
328     3, # number of components
329 dpavlin 11 1,0x00, # Scan 1: use DC/AC huff tables 0/0
330     2,0x11, # Scan 2: use DC/AC huff tables 1/1
331     3,0x11, # Scan 3: use DC/AC huff tables 1/1
332     0,0x3f, # Ss, Se
333     0, # Ah, Ai (not used)
334 dpavlin 8 );
335     #------------------------------------------------------------------
336    
337 dpavlin 16 $header =
338 dpavlin 13 # SOI
339     "\xFF\xD8".
340     # JFIF
341     "\xFF\xE0".
342     "\x00\x0e\x41\x56\x49\x31\x00\x00\x00\x00\x00\x00\x00\x00".
343     "\xff\xDD\x00\x04\x00\x00".
344     # quantization table
345     "\xFF\xDB".
346     "\x00\x43\x00\x21\x16\x18".
347     "\x1D\x18\x14\x21\x1D\x1B\x1D\x25".
348     "\x23\x21\x27\x31\x53\x36\x31\x2D".
349     "\x2D\x31\x65\x48\x4c\x3c\x53\x78".
350     "\x6a\x7e\x7c\x76\x6a\x74\x72\x85".
351     "\x95\xbf\xa2\x85\x8d\xb4\x8f\x72".
352     "\x74\xa6\xe2\xa8\xb4\xc5\xcb\xd6".
353     "\xd8\xd6\x80\xa0\xeb\xfb\xe8\xd0".
354     "\xf9\xbf\xd2\xd6\xcd".
355     # quantization table
356     "\xff\xdb".
357     "\x00\x43\x01\x23\x25\x25\x31\x2b\x31".
358     "\x61\x36\x36\x61\xcd\x89\x74\x89".
359     "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd".
360     "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd".
361     "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd".
362     "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd".
363     "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd".
364     "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd".
365     "\xcd\xcd".
366     # Define huffman table (section B.2.4.1)
367     "\xFF\xC4". # Marker
368     "\x00\x1F". # Length (31 bytes)
369 dpavlin 14 "\x00". # DC luminance, table 0
370     "\x00\x01\x05\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00".
371     "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B".
372 dpavlin 13 # Define huffman table (section B.2.4.1)
373     "\xFF\xC4". # Marker
374 dpavlin 14 "\x00\x1F". # Length (31 bytes)
375     "\x01". # DC chrominance, table 1
376     "\x00\x03\x01\x01\x01\x01\x01\x01\x01\x01\x01\x00".
377     "\x00\x00\x00\x00".
378     "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B".
379     # Define huffman table (section B.2.4.1)
380     "\xFF\xC4". # Marker
381 dpavlin 13 "\x00\xB5". # Length (181 bytes)
382 dpavlin 14 "\x10". # AC luminance, table 0
383     "\x00\x02\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01\x7D".
384     "\x01\x02\x03\x00\x04\x11\x05\x12".
385 dpavlin 13 "\x21\x31\x41\x06\x13\x51\x61\x07\x22\x71\x14\x32".
386     "\x81\x91\xA1\x08\x23\x42\xB1\xC1\x15\x52\xD1\xF0".
387     "\x24\x33\x62\x72\x82\x09\x0A\x16\x17\x18\x19\x1A".
388     "\x25\x26\x27\x28\x29\x2A\x34\x35\x36\x37\x38\x39".
389     "\x3A\x43\x44\x45\x46\x47\x48\x49\x4A\x53\x54\x55".
390     "\x56\x57\x58\x59\x5A\x63\x64\x65\x66\x67\x68\x69".
391     "\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x83\x84\x85".
392     "\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96\x97\x98".
393     "\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xB2".
394     "\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3\xC4\xC5".
395     "\xC6\xC7\xC8\xC9\xCA\xD2\xD3\xD4\xD5\xD6\xD7\xD8".
396     "\xD9\xDA\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA".
397     "\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA".
398     #/* Define huffman table (section B.2.4.1) */
399 dpavlin 14 "\xFF\xC4". # Marker
400     "\x00\xB5". # Length (181 bytes)
401     "\x11". # AC chrominance, table 1
402 dpavlin 13 "\x00\x02\x01\x02\x04\x04\x03\x04\x07\x05\x04\x04".
403 dpavlin 14 "\x00\x01\x02\x77".
404     "\x00\x01\x02\x03\x11\x04\x05\x21".
405 dpavlin 13 "\x31\x06\x12\x41\x51\x07\x61\x71\x13\x22\x32\x81".
406     "\x08\x14\x42\x91\xA1\xB1\xC1\x09\x23\x33\x52\xF0".
407     "\x15\x62\x72\xD1\x0A\x16\x24\x34\xE1\x25\xF1\x17".
408     "\x18\x19\x1A\x26\x27\x28\x29\x2A\x35\x36\x37\x38".
409     "\x39\x3A\x43\x44\x45\x46\x47\x48\x49\x4A\x53\x54".
410     "\x55\x56\x57\x58\x59\x5A\x63\x64\x65\x66\x67\x68".
411     "\x69\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x82\x83".
412     "\x84\x85\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96".
413     "\x97\x98\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9".
414     "\xAA\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3".
415     "\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xD2\xD3\xD4\xD5\xD6".
416     "\xD7\xD8\xD9\xDA\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9".
417     "\xEA\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA".
418     # start of frame
419     "\xff\xc0".
420     "\x00\x11\x08".
421 dpavlin 16 pack("nn", $h, $w).
422 dpavlin 13 "\x03\x01\x21\x00\x02\x11\x01\x03\x11\x01".
423     #
424     "\xff\xda".
425     "\x00\x0c\x03\x01\x00\x02\x11\x03\x11".
426     "\x00\x3f\x00";
427 dpavlin 8
428 dpavlin 11 if ( $dump ) {
429     warn "## created JPEG header...\n";
430     hex_dump( $header, 0 );
431     }
432 dpavlin 8
433 dpavlin 11 print $fh $header || die "can't write header into $path: $!";
434     print $fh $data || die "can't write frame into $path: $!";
435 dpavlin 8 close $fh || die "can't close $path: $!";
436     print ">> created $path ", -s $path, " bytes\n";
437     }
438    
439     my ( $riff, $amv ) = x(12, 'Z4x4Z4');
440     die "$path not RIFF but $riff" if $riff ne 'RIFF';
441     die "$path not AMV but $amv" if $amv ne 'AMV ';
442    
443 dpavlin 4 while ( ! defined($d->{eof}) ) {
444 dpavlin 3 my ( $list, $name ) = x(12,'A4x4A4');
445     die "not LIST but $list" if $list ne 'LIST';
446 dpavlin 8 print "< $list * $name\n";
447 dpavlin 3
448     if ( $name eq 'hdrl' ) {
449    
450     my $len = next_part( 'amvh', hex(38) );
451    
452     my @names = ( qw/ms_per_frame width height fps ss mm hh/ );
453     my $h;
454     map {
455     my $v = $_;
456     my $n = shift @names || die "no more names?";
457     $h->{$n} = $v;
458     } x($len, 'Vx28VVVx8CCv');
459    
460     printf "## %s %d*%d %s fps (%d ms/frame) %02d:%02d:%02d\n",
461 dpavlin 8 $path,
462 dpavlin 3 $h->{width}, $h->{height}, $h->{fps}, $h->{ms_per_frame},
463     $h->{hh}, $h->{mm}, $h->{ss};
464    
465     $d->{amvh} = $h;
466    
467     } elsif ( $name eq 'strl' ) {
468    
469     next_part( 'strh', 0, 1 );
470     next_part( 'strf', 0, 1 );
471    
472 dpavlin 4 } elsif ( $name eq 'movi' ) {
473    
474     while (1) {
475     my $frame = $d->{movi}++;
476    
477 dpavlin 8 my $len = next_part( '00dc' );
478 dpavlin 4 last unless $len;
479 dpavlin 8 printf "<< %s 00dc - frame %d jpeg %d 0x%x bytes\n", $name, $frame, $len, $len;
480     mkjpg( sprintf("$dump_dir/%03d.jpg", $frame ), x($len) );
481 dpavlin 4
482 dpavlin 8 $len = next_part( '01wb', 0, 1 );
483     printf "<< %s 01wb - frame %d audio %d 0x%x bytes\n", $name, $frame, $len, $len;
484 dpavlin 4 };
485    
486 dpavlin 3 } else {
487     die "unknown $list $name";
488     }
489     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26