Mercurial > libavformat.hg
comparison movenc.c @ 1082:4239bc0dc05e libavformat
add pcm 24/32 le/be support
author | bcoudurier |
---|---|
date | Sat, 13 May 2006 20:05:02 +0000 |
parents | ee5aac70a7dc |
children | 96283b259b1a |
comparison
equal
deleted
inserted
replaced
1081:ee5aac70a7dc | 1082:4239bc0dc05e |
---|---|
222 put_be16(pb, 0x81ff); /* Mode set (all modes for AMR_NB) */ | 222 put_be16(pb, 0x81ff); /* Mode set (all modes for AMR_NB) */ |
223 put_be16(pb, 1); /* Mode change period (no restriction) */ | 223 put_be16(pb, 1); /* Mode change period (no restriction) */ |
224 return 0x11; | 224 return 0x11; |
225 } | 225 } |
226 | 226 |
227 static int mov_write_enda_tag(ByteIOContext *pb) | |
228 { | |
229 put_be32(pb, 10); | |
230 put_tag(pb, "enda"); | |
231 put_be16(pb, 1); /* little endian */ | |
232 return 10; | |
233 } | |
234 | |
227 static unsigned int descrLength(unsigned int len) | 235 static unsigned int descrLength(unsigned int len) |
228 { | 236 { |
229 int i; | 237 int i; |
230 for(i=1; len>>(7*i); i++); | 238 for(i=1; len>>(7*i); i++); |
231 return len + 1 + i; | 239 return len + 1 + i; |
240 put_byte(pb, size & 0x7F); | 248 put_byte(pb, size & 0x7F); |
241 } | 249 } |
242 | 250 |
243 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic | 251 static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic |
244 { | 252 { |
245 int decoderSpecificInfoLen; | 253 offset_t pos = url_ftell(pb); |
246 offset_t pos = url_ftell(pb); | 254 int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0; |
247 | |
248 decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0; | |
249 | 255 |
250 put_be32(pb, 0); // size | 256 put_be32(pb, 0); // size |
251 put_tag(pb, "esds"); | 257 put_tag(pb, "esds"); |
252 put_be32(pb, 0); // Version | 258 put_be32(pb, 0); // Version |
253 | 259 |
300 put_be32(pb, 0); /* size */ | 306 put_be32(pb, 0); /* size */ |
301 put_tag(pb, "wave"); | 307 put_tag(pb, "wave"); |
302 | 308 |
303 put_be32(pb, 12); /* size */ | 309 put_be32(pb, 12); /* size */ |
304 put_tag(pb, "frma"); | 310 put_tag(pb, "frma"); |
305 put_tag(pb, "mp4a"); | 311 put_le32(pb, track->tag); |
306 | 312 |
307 put_be32(pb, 12); /* size */ | 313 if (track->enc->codec_id == CODEC_ID_AAC) { |
308 put_tag(pb, "mp4a"); | 314 put_be32(pb, 12); /* size */ |
309 put_be32(pb, 0); | 315 put_tag(pb, "mp4a"); |
310 | 316 put_be32(pb, 0); |
311 mov_write_esds_tag(pb, track); | 317 |
312 | 318 mov_write_esds_tag(pb, track); |
313 put_be32(pb, 12); /* size */ | 319 } else if (track->enc->codec_id == CODEC_ID_PCM_S24LE || |
314 put_tag(pb, "srcq"); | 320 track->enc->codec_id == CODEC_ID_PCM_S32LE) { |
315 put_be32(pb, 0x40); | 321 mov_write_enda_tag(pb); |
322 } | |
316 | 323 |
317 put_be32(pb, 8); /* size */ | 324 put_be32(pb, 8); /* size */ |
318 put_be32(pb, 0); /* null tag */ | 325 put_be32(pb, 0); /* null tag */ |
319 | 326 |
320 return updateSize (pb, pos); | 327 return updateSize (pb, pos); |
329 { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, | 336 { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, |
330 { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, | 337 { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, |
331 { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, | 338 { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, |
332 { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, | 339 { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, |
333 { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, | 340 { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, |
341 { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') }, | |
342 { CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') }, | |
343 { CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') }, | |
344 { CODEC_ID_PCM_S32LE, MKTAG('i', 'n', '3', '2') }, | |
334 { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') }, | 345 { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') }, |
335 { CODEC_ID_NONE, 0 }, | 346 { CODEC_ID_NONE, 0 }, |
336 }; | 347 }; |
337 | 348 |
338 static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track) | 349 static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track) |
339 { | 350 { |
340 offset_t pos = url_ftell(pb); | 351 offset_t pos = url_ftell(pb); |
352 int version = track->mode == MODE_MOV && | |
353 (track->enc->codec_id == CODEC_ID_AAC || | |
354 track->enc->codec_id == CODEC_ID_PCM_S32LE || | |
355 track->enc->codec_id == CODEC_ID_PCM_S24LE); | |
341 | 356 |
342 put_be32(pb, 0); /* size */ | 357 put_be32(pb, 0); /* size */ |
343 put_le32(pb, track->tag); // store it byteswapped | 358 put_le32(pb, track->tag); // store it byteswapped |
344 put_be32(pb, 0); /* Reserved */ | 359 put_be32(pb, 0); /* Reserved */ |
345 put_be16(pb, 0); /* Reserved */ | 360 put_be16(pb, 0); /* Reserved */ |
346 put_be16(pb, 1); /* Data-reference index, XXX == 1 */ | 361 put_be16(pb, 1); /* Data-reference index, XXX == 1 */ |
347 | 362 |
348 /* SoundDescription */ | 363 /* SoundDescription */ |
349 if(track->mode == MODE_MOV && track->enc->codec_id == CODEC_ID_AAC) | 364 put_be16(pb, version); /* Version */ |
350 put_be16(pb, 1); /* Version 1 */ | |
351 else | |
352 put_be16(pb, 0); /* Version 0 */ | |
353 put_be16(pb, 0); /* Revision level */ | 365 put_be16(pb, 0); /* Revision level */ |
354 put_be32(pb, 0); /* Reserved */ | 366 put_be32(pb, 0); /* Reserved */ |
355 | 367 |
356 put_be16(pb, track->enc->channels); /* Number of channels */ | 368 put_be16(pb, track->enc->channels); /* Number of channels */ |
357 /* TODO: Currently hard-coded to 16-bit, there doesn't seem | 369 /* TODO: Currently hard-coded to 16-bit, there doesn't seem |
367 } | 379 } |
368 put_be16(pb, 0); /* packet size (= 0) */ | 380 put_be16(pb, 0); /* packet size (= 0) */ |
369 put_be16(pb, track->timescale); /* Time scale */ | 381 put_be16(pb, track->timescale); /* Time scale */ |
370 put_be16(pb, 0); /* Reserved */ | 382 put_be16(pb, 0); /* Reserved */ |
371 | 383 |
372 if(track->mode == MODE_MOV && track->enc->codec_id == CODEC_ID_AAC) { | 384 if(version == 1) { |
373 /* SoundDescription V1 extended info */ | 385 /* SoundDescription V1 extended info */ |
374 put_be32(pb, track->enc->frame_size); /* Samples per packet */ | 386 put_be32(pb, track->enc->frame_size); /* Samples per packet */ |
375 put_be32(pb, 1536); /* Bytes per packet */ | 387 put_be32(pb, track->sampleDuration); /* Bytes per frame */ |
376 put_be32(pb, 2); /* Bytes per frame */ | 388 put_be32(pb, 8); /* Bytes per sample */ |
377 put_be32(pb, 2); /* Bytes per sample */ | 389 put_be32(pb, 2); /* Bytes per sample */ |
378 } | 390 } |
379 | 391 |
380 if(track->enc->codec_id == CODEC_ID_AAC) { | 392 if(track->enc->codec_id == CODEC_ID_AAC) { |
381 if( track->mode == MODE_MOV ) mov_write_wave_tag(pb, track); | 393 if (track->mode == MODE_MOV) mov_write_wave_tag(pb, track); |
382 else mov_write_esds_tag(pb, track); | 394 else mov_write_esds_tag(pb, track); |
383 } | 395 } else if(track->enc->codec_id == CODEC_ID_AMR_NB) { |
384 if(track->enc->codec_id == CODEC_ID_AMR_NB) | |
385 mov_write_damr_tag(pb); | 396 mov_write_damr_tag(pb); |
397 } else if(track->enc->codec_id == CODEC_ID_PCM_S24LE || | |
398 track->enc->codec_id == CODEC_ID_PCM_S32LE) { | |
399 mov_write_wave_tag(pb, track); | |
400 } | |
386 return updateSize (pb, pos); | 401 return updateSize (pb, pos); |
387 } | 402 } |
388 | 403 |
389 static int mov_write_d263_tag(ByteIOContext *pb) | 404 static int mov_write_d263_tag(ByteIOContext *pb) |
390 { | 405 { |
1602 break; | 1617 break; |
1603 case CODEC_ID_PCM_S16BE: | 1618 case CODEC_ID_PCM_S16BE: |
1604 case CODEC_ID_PCM_S16LE: | 1619 case CODEC_ID_PCM_S16LE: |
1605 samplesInChunk = size/(2*enc->channels); | 1620 samplesInChunk = size/(2*enc->channels); |
1606 break; | 1621 break; |
1622 case CODEC_ID_PCM_S24BE: | |
1623 case CODEC_ID_PCM_S24LE: | |
1624 samplesInChunk = size/(3*enc->channels); | |
1625 break; | |
1626 case CODEC_ID_PCM_S32BE: | |
1627 case CODEC_ID_PCM_S32LE: | |
1628 samplesInChunk = size/(4*enc->channels); | |
1629 break; | |
1607 default: | 1630 default: |
1608 samplesInChunk = 1; | 1631 samplesInChunk = 1; |
1609 } | 1632 } |
1610 } else { | 1633 } else { |
1611 samplesInChunk = 1; | 1634 samplesInChunk = 1; |