10 |
# http://www.obrador.com/essentialjpeg/HeaderInfo.htm |
# http://www.obrador.com/essentialjpeg/HeaderInfo.htm |
11 |
# http://lists.helixcommunity.org/pipermail/datatype-dev/2005-January/001886.html |
# http://lists.helixcommunity.org/pipermail/datatype-dev/2005-January/001886.html |
12 |
# http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm |
# http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm |
13 |
|
# http://wiki.multimedia.cx/index.php?title=IMA_ADPCM |
14 |
|
|
15 |
use strict; |
use strict; |
16 |
|
|
19 |
use File::Path; |
use File::Path; |
20 |
use Getopt::Long; |
use Getopt::Long; |
21 |
|
|
22 |
my $dump = 0; |
my $dump_amv = 0; |
23 |
|
my $dump_video = 0; |
24 |
|
my $dump_jpeg = 0; |
25 |
|
my $dump_audio = 0; |
26 |
my $debug = 0; |
my $debug = 0; |
27 |
my $verbose = 0; |
my $verbose = 0; |
28 |
my $dump_dir = '/tmp/dump/'; |
my $dump_dir = '/tmp/dump/'; |
32 |
my $jpegtran; |
my $jpegtran; |
33 |
|
|
34 |
GetOptions( |
GetOptions( |
35 |
"dump!" => \$dump, |
"dump-amv!" => \$dump_amv, |
36 |
|
"dump-video!" => \$dump_video, |
37 |
|
"dump-jpeg!" => \$dump_jpeg, |
38 |
|
"dump-audio!" => \$dump_audio, |
39 |
"debug!" => \$debug, |
"debug!" => \$debug, |
40 |
"dump-dir=s" => \$dump_dir, |
"dump-dir=s" => \$dump_dir, |
41 |
"no-jpeg-headers!" => \$no_jpeg_header, |
"no-jpeg-headers!" => \$no_jpeg_header, |
60 |
my $d; |
my $d; |
61 |
|
|
62 |
sub hex_dump { |
sub hex_dump { |
|
return unless $dump; |
|
|
|
|
63 |
my ( $bytes, $offset ) = @_; |
my ( $bytes, $offset ) = @_; |
64 |
return unless $bytes; |
return unless $bytes; |
65 |
|
|
101 |
my $r_len = length($bytes); |
my $r_len = length($bytes); |
102 |
confess "read $r_len bytes, expected $len" if $len != $r_len; |
confess "read $r_len bytes, expected $len" if $len != $r_len; |
103 |
|
|
104 |
hex_dump( $bytes ); |
if ( $dump_amv ) { |
105 |
|
print "## raw $len bytes\n"; |
106 |
|
hex_dump( $bytes ); |
107 |
|
} |
108 |
|
|
109 |
if ( $bytes eq 'AMV_END_' ) { |
if ( $bytes eq 'AMV_END_' ) { |
110 |
print "> end of file marker AMV_END_\n" if $dump; |
print "> end of file marker AMV_END_\n" if $dump_video; |
111 |
$d->{eof}++; |
$d->{eof}++; |
112 |
return; |
return; |
113 |
} |
} |
147 |
$out .= chr($t); |
$out .= chr($t); |
148 |
} |
} |
149 |
|
|
150 |
if ( $dump ) { |
if ( $dump_video ) { |
151 |
print "## quantization table original\n"; |
print "## quantization table original\n"; |
152 |
hex_dump( $in ); |
hex_dump( $in ); |
153 |
print "## quantization table for $jpeg_q %\n"; |
print "## quantization table for $jpeg_q %\n"; |
361 |
0, # Ah, Ai (not used) |
0, # Ah, Ai (not used) |
362 |
); |
); |
363 |
|
|
364 |
if ( $dump ) { |
if ( $dump_jpeg ) { |
365 |
print "## created JPEG header...\n"; |
print "## created JPEG header...\n"; |
366 |
hex_dump( $header, 0 ); |
hex_dump( $header, 0 ); |
367 |
} |
} |
473 |
|
|
474 |
my $audio_frame = x( $len ); |
my $audio_frame = x( $len ); |
475 |
|
|
476 |
|
if ( $dump_audio ) { |
477 |
|
printf "#### dumping audio frame %d 0x%x bytes\n", length($audio_frame), length($audio_frame); |
478 |
|
hex_dump( $audio_frame ); |
479 |
|
} |
480 |
|
|
481 |
# remove 8 bytes of something |
# remove 8 bytes of something |
482 |
$audio_frame = substr( $audio_frame, 8 ); |
$audio_frame = substr( $audio_frame, 8 ); |
483 |
|
|
486 |
# $audio_frame = substr( $audio_frame, 0, -1 ); |
# $audio_frame = substr( $audio_frame, 0, -1 ); |
487 |
} |
} |
488 |
|
|
|
if ( $dump ) { |
|
|
print "#### dumping audio frame ", length($audio_frame), " bytes\n"; |
|
|
hex_dump( $audio_frame ); |
|
|
} |
|
|
|
|
489 |
# print $audio_fh mp3_frame; |
# print $audio_fh mp3_frame; |
490 |
print $audio_fh $audio_frame || die "can't write audio frame in $apath: $!"; |
print $audio_fh $audio_frame || die "can't write audio frame in $apath: $!"; |
491 |
|
|