--- amv.pl 2007/07/20 11:13:55 8 +++ amv.pl 2007/07/21 11:05:43 15 @@ -15,16 +15,23 @@ use Data::Dump qw/dump/; use Carp qw/confess/; use File::Path; +use Getopt::Long; my $dump = 0; my $debug = 0; +my $dump_dir = '/tmp/dump/'; + +GetOptions( + "dump!" => \$dump, + "debug!" => \$debug, + "dump-dir=s" => \$dump_dir, +); my $path = shift @ARGV || die "usage: $0 movie.amv\n"; -my $dump_dir = '/tmp/dump/'; -if ( ! -e $dump_dir ) { - mkpath $dump_dir || die "can't create $dump_dir: $!"; -} + +rmtree $dump_dir if -e $dump_dir; +mkpath $dump_dir || die "can't create $dump_dir: $!"; open(my $fh, '<', $path) || die "can't open $path: $!"; @@ -164,44 +171,264 @@ 0,0, # X,Y thumbnail ). #------------------------------------------------------------------ - "\xFF\xDB". # Define Quantization table marker - "\x00\x43". # len - "\x00". # the precision and the quantization table index - "\x00" x 64 . -#------------------------------------------------------------------ - "\xFF\xC0". # Start of frame + "\xFF\xC0". # Start of frame pack("ncnncc9", 17, # len 8, # sample precision in bits 120,160, # X,Y size 3, # number of components - 1,0x22,0, # Component ID, H+V sampling factors, Quantization table number - 2,0x11,0, - 3,0x11,0, + 1,0x21,0, # Component ID, H+V sampling factors, Quantization table number + 2,0x11,1, + 3,0x11,1, ). #------------------------------------------------------------------ + "\xFF\xDB". # Define Quantization table marker + "\x00\x84". # len + "\x00". # 8 bit values, (byte) table 0 + "\x10\x0B\x0C\x0E\x0C". + "\x0A\x10\x0E\x0D\x0E". + "\x12\x11\x10\x13\x18". + "\x28\x1A\x18\x16\x16". + "\x18\x31\x23\x25\x1D". + "\x28\x3A\x33\x3D\x3C". + "\x39\x33\x38\x37\x40". + "\x48\x5C\x4E\x40\x44". + "\x57\x45\x37\x38\x50". + "\x6D\x51\x57\x5F\x62". + "\x67\x68\x67\x3E\x4D". + "\x71\x79\x70\x64\x78". + "\x5C\x65\x67\x63". + "\x01". # 8 bit values, (byte) table 1 + "\x11\x12\x12\x18\x15". + "\x18\x2F\x1A\x1A\x2F". + "\x63\x42\x38\x42\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63\x63". + "\x63\x63\x63\x63". +#------------------------------------------------------------------ # huffman("\x00"). # 0 DC - huffman("\x01"). # 1 DC +# huffman("\x01"). # 1 DC # huffman("\x10"). # 0 AC # huffman("\x11"). # 1 AC #------------------------------------------------------------------ + # Define huffman table (section B.2.4.1) + "\xFF\xC4". # Marker + "\x00\x1F". # Length (31 bytes) + "\x00". # DC, (byte) table 0 + "\x00\x01\x05\x01\x01". + "\x01\x01\x01\x01\x00". + "\x00\x00\x00\x00\x00". + "\x00\x00\x01\x02\x03". + "\x04\x05\x06\x07\x08". + "\x09\x0A\x0B". + # Define huffman table (section B.2.4.1) + "\xFF\xC4". # Marker + "\x00\xB5". # Length (181 bytes) + "\x10". # AC, (byte) table 0 + "\x00\x02\x01\x03\x03". + "\x02\x04\x03\x05\x05". + "\x04\x04\x00\x00\x01". + "\x7D\x01\x02\x03\x00". + "\x04\x11\x05\x12\x21". + "\x31\x41\x06\x13\x51". + "\x61\x07\x22\x71\x14". + "\x32\x81\x91\xA1\x08". + "\x23\x42\xB1\xC1\x15". + "\x52\xD1\xF0\x24\x33". + "\x62\x72\x82\x09\x0A". + "\x16\x17\x18\x19\x1A". + "\x25\x26\x27\x28\x29". + "\x2A\x34\x35\x36\x37". + "\x38\x39\x3A\x43\x44". + "\x45\x46\x47\x48\x49". + "\x4A\x53\x54\x55\x56". + "\x57\x58\x59\x5A\x63". + "\x64\x65\x66\x67\x68". + "\x69\x6A\x73\x74\x75". + "\x76\x77\x78\x79\x7A". + "\x83\x84\x85\x86\x87". + "\x88\x89\x8A\x92\x93". + "\x94\x95\x96\x97\x98". + "\x99\x9A\xA2\xA3\xA4". + "\xA5\xA6\xA7\xA8\xA9". + "\xAA\xB2\xB3\xB4\xB5". + "\xB6\xB7\xB8\xB9\xBA". + "\xC2\xC3\xC4\xC5\xC6". + "\xC7\xC8\xC9\xCA\xD2". + "\xD3\xD4\xD5\xD6\xD7". + "\xD8\xD9\xDA\xE1\xE2". + "\xE3\xE4\xE5\xE6\xE7". + "\xE8\xE9\xEA\xF1\xF2". + "\xF3\xF4\xF5\xF6\xF7". + "\xF8\xF9\xFA". + # Define huffman table (section B.2.4.1) + "\xFF\xC4". # Marker + "\x00\x1F". # Length (31 bytes) + "\x01". # DC, (byte) table 1 + "\x00\x03\x01\x01\x01". + "\x01\x01\x01\x01\x01". + "\x01\x00\x00\x00\x00". + "\x00\x00\x01\x02\x03". + "\x04\x05\x06\x07\x08". + "\x09\x0A\x0B". + # Define huffman table (section B.2.4.1) + "\xFF\xC4". # Marker + "\x00\xB5". # Length (181 bytes) + "\x11". # AC, (byte) table 1 + "\x00\x02\x01\x02\x04". + "\x04\x03\x04\x07\x05". + "\x04\x04\x00\x01\x02". + "\x77\x00\x01\x02\x03". + "\x11\x04\x05\x21\x31". + "\x06\x12\x41\x51\x07". + "\x61\x71\x13\x22\x32". + "\x81\x08\x14\x42\x91". + "\xA1\xB1\xC1\x09\x23". + "\x33\x52\xF0\x15\x62". + "\x72\xD1\x0A\x16\x24". + "\x34\xE1\x25\xF1\x17". + "\x18\x19\x1A\x26\x27". + "\x28\x29\x2A\x35\x36". + "\x37\x38\x39\x3A\x43". + "\x44\x45\x46\x47\x48". + "\x49\x4A\x53\x54\x55". + "\x56\x57\x58\x59\x5A". + "\x63\x64\x65\x66\x67". + "\x68\x69\x6A\x73\x74". + "\x75\x76\x77\x78\x79". + "\x7A\x82\x83\x84\x85". + "\x86\x87\x88\x89\x8A". + "\x92\x93\x94\x95\x96". + "\x97\x98\x99\x9A\xA2". + "\xA3\xA4\xA5\xA6\xA7". + "\xA8\xA9\xAA\xB2\xB3". + "\xB4\xB5\xB6\xB7\xB8". + "\xB9\xBA\xC2\xC3\xC4". + "\xC5\xC6\xC7\xC8\xC9". + "\xCA\xD2\xD3\xD4\xD5". + "\xD6\xD7\xD8\xD9\xDA". + "\xE2\xE3\xE4\xE5\xE6". + "\xE7\xE8\xE9\xEA\xF2". + "\xF3\xF4\xF5\xF6\xF7". + "\xF8\xF9\xFA". +#------------------------------------------------------------------ "\xFF\xDA". # Start of Scan marker pack("nC11", 12, # length 3, # number of components - 1,0, # components DC+AC table numbers - 2,17, - 3,17, - 0,63, # Ss, Se - 0,165, # Ah, Ai + 1,0x00, # Scan 1: use DC/AC huff tables 0/0 + 2,0x11, # Scan 2: use DC/AC huff tables 1/1 + 3,0x11, # Scan 3: use DC/AC huff tables 1/1 + 0,0x3f, # Ss, Se + 0, # Ah, Ai (not used) ); #------------------------------------------------------------------ + my $header = + # SOI + "\xFF\xD8". + # JFIF + "\xFF\xE0". + "\x00\x0e\x41\x56\x49\x31\x00\x00\x00\x00\x00\x00\x00\x00". + "\xff\xDD\x00\x04\x00\x00". + # quantization table + "\xFF\xDB". + "\x00\x43\x00\x21\x16\x18". + "\x1D\x18\x14\x21\x1D\x1B\x1D\x25". + "\x23\x21\x27\x31\x53\x36\x31\x2D". + "\x2D\x31\x65\x48\x4c\x3c\x53\x78". + "\x6a\x7e\x7c\x76\x6a\x74\x72\x85". + "\x95\xbf\xa2\x85\x8d\xb4\x8f\x72". + "\x74\xa6\xe2\xa8\xb4\xc5\xcb\xd6". + "\xd8\xd6\x80\xa0\xeb\xfb\xe8\xd0". + "\xf9\xbf\xd2\xd6\xcd". + # quantization table + "\xff\xdb". + "\x00\x43\x01\x23\x25\x25\x31\x2b\x31". + "\x61\x36\x36\x61\xcd\x89\x74\x89". + "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd". + "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd". + "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd". + "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd". + "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd". + "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd". + "\xcd\xcd". + # Define huffman table (section B.2.4.1) + "\xFF\xC4". # Marker + "\x00\x1F". # Length (31 bytes) + "\x00". # DC luminance, table 0 + "\x00\x01\x05\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00". + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B". + # Define huffman table (section B.2.4.1) + "\xFF\xC4". # Marker + "\x00\x1F". # Length (31 bytes) + "\x01". # DC chrominance, table 1 + "\x00\x03\x01\x01\x01\x01\x01\x01\x01\x01\x01\x00". + "\x00\x00\x00\x00". + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B". + # Define huffman table (section B.2.4.1) + "\xFF\xC4". # Marker + "\x00\xB5". # Length (181 bytes) + "\x10". # AC luminance, table 0 + "\x00\x02\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01\x7D". + "\x01\x02\x03\x00\x04\x11\x05\x12". + "\x21\x31\x41\x06\x13\x51\x61\x07\x22\x71\x14\x32". + "\x81\x91\xA1\x08\x23\x42\xB1\xC1\x15\x52\xD1\xF0". + "\x24\x33\x62\x72\x82\x09\x0A\x16\x17\x18\x19\x1A". + "\x25\x26\x27\x28\x29\x2A\x34\x35\x36\x37\x38\x39". + "\x3A\x43\x44\x45\x46\x47\x48\x49\x4A\x53\x54\x55". + "\x56\x57\x58\x59\x5A\x63\x64\x65\x66\x67\x68\x69". + "\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x83\x84\x85". + "\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96\x97\x98". + "\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xB2". + "\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3\xC4\xC5". + "\xC6\xC7\xC8\xC9\xCA\xD2\xD3\xD4\xD5\xD6\xD7\xD8". + "\xD9\xDA\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA". + "\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA". + #/* Define huffman table (section B.2.4.1) */ + "\xFF\xC4". # Marker + "\x00\xB5". # Length (181 bytes) + "\x11". # AC chrominance, table 1 + "\x00\x02\x01\x02\x04\x04\x03\x04\x07\x05\x04\x04". + "\x00\x01\x02\x77". + "\x00\x01\x02\x03\x11\x04\x05\x21". + "\x31\x06\x12\x41\x51\x07\x61\x71\x13\x22\x32\x81". + "\x08\x14\x42\x91\xA1\xB1\xC1\x09\x23\x33\x52\xF0". + "\x15\x62\x72\xD1\x0A\x16\x24\x34\xE1\x25\xF1\x17". + "\x18\x19\x1A\x26\x27\x28\x29\x2A\x35\x36\x37\x38". + "\x39\x3A\x43\x44\x45\x46\x47\x48\x49\x4A\x53\x54". + "\x55\x56\x57\x58\x59\x5A\x63\x64\x65\x66\x67\x68". + "\x69\x6A\x73\x74\x75\x76\x77\x78\x79\x7A\x82\x83". + "\x84\x85\x86\x87\x88\x89\x8A\x92\x93\x94\x95\x96". + "\x97\x98\x99\x9A\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9". + "\xAA\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xC2\xC3". + "\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xD2\xD3\xD4\xD5\xD6". + "\xD7\xD8\xD9\xDA\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9". + "\xEA\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA". + # start of frame + "\xff\xc0". + "\x00\x11\x08". + pack("nn", 120, 160). + "\x03\x01\x21\x00\x02\x11\x01\x03\x11\x01". + # + "\xff\xda". + "\x00\x0c\x03\x01\x00\x02\x11\x03\x11". + "\x00\x3f\x00"; + + if ( $dump ) { + warn "## created JPEG header...\n"; + hex_dump( $header, 0 ); + } - warn "## created JPEG header...", dump( $header ); - hex_dump( $header, 0 ); - - print $fh $header . $data || die "can't write frame into $path: $!"; + print $fh $header || die "can't write header into $path: $!"; + print $fh $data || die "can't write frame into $path: $!"; close $fh || die "can't close $path: $!"; print ">> created $path ", -s $path, " bytes\n"; }