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

Contents of /amv.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26