Revision 11
Legend:
- Added
- Removed
- Modified
-
amv.pl
22 22 my $path = shift @ARGV || die "usage: $0 movie.amv\n"; 23 23 24 24 my $dump_dir = '/tmp/dump/'; 25 if ( ! -e $dump_dir ) { 26 mkpath $dump_dir || die "can't create $dump_dir: $!"; 27 } 25 rmtree $dump_dir if -e $dump_dir; 26 mkpath $dump_dir || die "can't create $dump_dir: $!"; 28 27 29 28 open(my $fh, '<', $path) || die "can't open $path: $!"; 30 29 … … 164 163 0,0, # X,Y thumbnail 165 164 ). 166 165 #------------------------------------------------------------------ 167 "\xFF\xDB". # Define Quantization table marker 168 "\x00\x43". # len 169 "\x00". # the precision and the quantization table index 170 "\x00" x 64 . 171 #------------------------------------------------------------------ 172 "\xFF\xC0". # Start of frame 166 "\xFF\xC0". # Start of frame 173 167 pack("ncnncc9", 174 168 17, # len 175 169 8, # sample precision in bits 176 170 120,160, # X,Y size 177 171 3, # number of components 178 1,0x22,0, # Component ID, H+V sampling factors, Quantization table number 179 2,0x11,0, 180 3,0x11,0, 172 1,0x21,0, # Component ID, H+V sampling factors, Quantization table number 173 2,0x11,1, 174 3,0x11,1, 181 175 ). 182 176 #------------------------------------------------------------------ 177 "\xFF\xDB". # Define Quantization table marker 178 "\x00\x84". # len 179 "\x00". # 8 bit values, (byte) table 0 180 "\x10\x0B\x0C\x0E\x0C". 181 "\x0A\x10\x0E\x0D\x0E". 182 "\x12\x11\x10\x13\x18". 183 "\x28\x1A\x18\x16\x16". 184 "\x18\x31\x23\x25\x1D". 185 "\x28\x3A\x33\x3D\x3C". 186 "\x39\x33\x38\x37\x40". 187 "\x48\x5C\x4E\x40\x44". 188 "\x57\x45\x37\x38\x50". 189 "\x6D\x51\x57\x5F\x62". 190 "\x67\x68\x67\x3E\x4D". 191 "\x71\x79\x70\x64\x78". 192 "\x5C\x65\x67\x63". 193 "\x01". # 8 bit values, (byte) table 1 194 "\x11\x12\x12\x18\x15". 195 "\x18\x2F\x1A\x1A\x2F". 196 "\x63\x42\x38\x42\x63". 197 "\x63\x63\x63\x63\x63". 198 "\x63\x63\x63\x63\x63". 199 "\x63\x63\x63\x63\x63". 200 "\x63\x63\x63\x63\x63". 201 "\x63\x63\x63\x63\x63". 202 "\x63\x63\x63\x63\x63". 203 "\x63\x63\x63\x63\x63". 204 "\x63\x63\x63\x63\x63". 205 "\x63\x63\x63\x63\x63". 206 "\x63\x63\x63\x63". 207 #------------------------------------------------------------------ 183 208 # huffman("\x00"). # 0 DC 184 huffman("\x01"). # 1 DC 209 # huffman("\x01"). # 1 DC 185 210 # huffman("\x10"). # 0 AC 186 211 # huffman("\x11"). # 1 AC 187 212 #------------------------------------------------------------------ 213 # Define huffman table (section B.2.4.1) 214 "\xFF\xC4". # Marker 215 "\x00\x1F". # Length (31 bytes) 216 "\x00". # DC, (byte) table 0 217 "\x00\x01\x05\x01\x01". 218 "\x01\x01\x01\x01\x00". 219 "\x00\x00\x00\x00\x00". 220 "\x00\x00\x01\x02\x03". 221 "\x04\x05\x06\x07\x08". 222 "\x09\x0A\x0B". 223 # Define huffman table (section B.2.4.1) 224 "\xFF\xC4". # Marker 225 "\x00\xB5". # Length (181 bytes) 226 "\x10". # AC, (byte) table 0 227 "\x00\x02\x01\x03\x03". 228 "\x02\x04\x03\x05\x05". 229 "\x04\x04\x00\x00\x01". 230 "\x7D\x01\x02\x03\x00". 231 "\x04\x11\x05\x12\x21". 232 "\x31\x41\x06\x13\x51". 233 "\x61\x07\x22\x71\x14". 234 "\x32\x81\x91\xA1\x08". 235 "\x23\x42\xB1\xC1\x15". 236 "\x52\xD1\xF0\x24\x33". 237 "\x62\x72\x82\x09\x0A". 238 "\x16\x17\x18\x19\x1A". 239 "\x25\x26\x27\x28\x29". 240 "\x2A\x34\x35\x36\x37". 241 "\x38\x39\x3A\x43\x44". 242 "\x45\x46\x47\x48\x49". 243 "\x4A\x53\x54\x55\x56". 244 "\x57\x58\x59\x5A\x63". 245 "\x64\x65\x66\x67\x68". 246 "\x69\x6A\x73\x74\x75". 247 "\x76\x77\x78\x79\x7A". 248 "\x83\x84\x85\x86\x87". 249 "\x88\x89\x8A\x92\x93". 250 "\x94\x95\x96\x97\x98". 251 "\x99\x9A\xA2\xA3\xA4". 252 "\xA5\xA6\xA7\xA8\xA9". 253 "\xAA\xB2\xB3\xB4\xB5". 254 "\xB6\xB7\xB8\xB9\xBA". 255 "\xC2\xC3\xC4\xC5\xC6". 256 "\xC7\xC8\xC9\xCA\xD2". 257 "\xD3\xD4\xD5\xD6\xD7". 258 "\xD8\xD9\xDA\xE1\xE2". 259 "\xE3\xE4\xE5\xE6\xE7". 260 "\xE8\xE9\xEA\xF1\xF2". 261 "\xF3\xF4\xF5\xF6\xF7". 262 "\xF8\xF9\xFA". 263 # Define huffman table (section B.2.4.1) 264 "\xFF\xC4". # Marker 265 "\x00\x1F". # Length (31 bytes) 266 "\x01". # DC, (byte) table 1 267 "\x00\x03\x01\x01\x01". 268 "\x01\x01\x01\x01\x01". 269 "\x01\x00\x00\x00\x00". 270 "\x00\x00\x01\x02\x03". 271 "\x04\x05\x06\x07\x08". 272 "\x09\x0A\x0B". 273 # Define huffman table (section B.2.4.1) 274 "\xFF\xC4". # Marker 275 "\x00\xB5". # Length (181 bytes) 276 "\x11". # AC, (byte) table 1 277 "\x00\x02\x01\x02\x04". 278 "\x04\x03\x04\x07\x05". 279 "\x04\x04\x00\x01\x02". 280 "\x77\x00\x01\x02\x03". 281 "\x11\x04\x05\x21\x31". 282 "\x06\x12\x41\x51\x07". 283 "\x61\x71\x13\x22\x32". 284 "\x81\x08\x14\x42\x91". 285 "\xA1\xB1\xC1\x09\x23". 286 "\x33\x52\xF0\x15\x62". 287 "\x72\xD1\x0A\x16\x24". 288 "\x34\xE1\x25\xF1\x17". 289 "\x18\x19\x1A\x26\x27". 290 "\x28\x29\x2A\x35\x36". 291 "\x37\x38\x39\x3A\x43". 292 "\x44\x45\x46\x47\x48". 293 "\x49\x4A\x53\x54\x55". 294 "\x56\x57\x58\x59\x5A". 295 "\x63\x64\x65\x66\x67". 296 "\x68\x69\x6A\x73\x74". 297 "\x75\x76\x77\x78\x79". 298 "\x7A\x82\x83\x84\x85". 299 "\x86\x87\x88\x89\x8A". 300 "\x92\x93\x94\x95\x96". 301 "\x97\x98\x99\x9A\xA2". 302 "\xA3\xA4\xA5\xA6\xA7". 303 "\xA8\xA9\xAA\xB2\xB3". 304 "\xB4\xB5\xB6\xB7\xB8". 305 "\xB9\xBA\xC2\xC3\xC4". 306 "\xC5\xC6\xC7\xC8\xC9". 307 "\xCA\xD2\xD3\xD4\xD5". 308 "\xD6\xD7\xD8\xD9\xDA". 309 "\xE2\xE3\xE4\xE5\xE6". 310 "\xE7\xE8\xE9\xEA\xF2". 311 "\xF3\xF4\xF5\xF6\xF7". 312 "\xF8\xF9\xFA". 313 #------------------------------------------------------------------ 188 314 "\xFF\xDA". # Start of Scan marker 189 315 pack("nC11", 190 316 12, # length 191 317 3, # number of components 192 1,0, # components DC+AC table numbers 193 2,17, 194 3,17, 195 0,63, # Ss, Se 196 0,165, # Ah, Ai 318 1,0x00, # Scan 1: use DC/AC huff tables 0/0 319 2,0x11, # Scan 2: use DC/AC huff tables 1/1 320 3,0x11, # Scan 3: use DC/AC huff tables 1/1 321 0,0x3f, # Ss, Se 322 0, # Ah, Ai (not used) 197 323 ); 198 324 #------------------------------------------------------------------ 199 325 200 326 201 warn "## created JPEG header...", dump( $header ); 202 hex_dump( $header, 0 ); 327 if ( $dump ) { 328 warn "## created JPEG header...\n"; 329 hex_dump( $header, 0 ); 330 } 203 331 204 print $fh $header . $data || die "can't write frame into $path: $!"; 332 print $fh $header || die "can't write header into $path: $!"; 333 print $fh $data || die "can't write frame into $path: $!"; 205 334 close $fh || die "can't close $path: $!"; 206 335 print ">> created $path ", -s $path, " bytes\n"; 207 336 }