Revision feaa8d11 libavformat/movenc.c

View differences:

libavformat/movenc.c
402 402
    return 8+track->vosLen;
403 403
}
404 404

  
405
/**
406
 * Compute flags for 'lpcm' tag.
407
 * See CoreAudioTypes and AudioStreamBasicDescription at Apple.
408
 */
409
static int mov_get_lpcm_flags(enum CodecID codec_id)
410
{
411
    switch (codec_id) {
412
    case CODEC_ID_PCM_F32BE:
413
    case CODEC_ID_PCM_F64BE:
414
        return 11;
415
    case CODEC_ID_PCM_F32LE:
416
    case CODEC_ID_PCM_F64LE:
417
        return 9;
418
    case CODEC_ID_PCM_U8:
419
        return 10;
420
    case CODEC_ID_PCM_S16BE:
421
    case CODEC_ID_PCM_S24BE:
422
    case CODEC_ID_PCM_S32BE:
423
        return 14;
424
    case CODEC_ID_PCM_S8:
425
    case CODEC_ID_PCM_S16LE:
426
    case CODEC_ID_PCM_S24LE:
427
    case CODEC_ID_PCM_S32LE:
428
        return 12;
429
    default:
430
        return 0;
431
    }
432
}
433

  
405 434
static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track)
406 435
{
407 436
    int64_t pos = url_ftell(pb);
408
    int version = track->mode == MODE_MOV &&
409
        (track->audio_vbr ||
410
         track->enc->codec_id == CODEC_ID_PCM_S32LE ||
411
         track->enc->codec_id == CODEC_ID_PCM_S24LE);
437
    int version = 0;
438
    uint32_t tag = track->tag;
439

  
440
    if (track->mode == MODE_MOV) {
441
        if (track->timescale > UINT16_MAX) {
442
            if (mov_get_lpcm_flags(track->enc->codec_id))
443
                tag = AV_RL32("lpcm");
444
            version = 2;
445
        } else if (track->audio_vbr ||
446
                   track->enc->codec_id == CODEC_ID_PCM_S32LE ||
447
                   track->enc->codec_id == CODEC_ID_PCM_S24LE) {
448
            version = 1;
449
        }
450
    }
412 451

  
413 452
    put_be32(pb, 0); /* size */
414
    put_le32(pb, track->tag); // store it byteswapped
453
    put_le32(pb, tag); // store it byteswapped
415 454
    put_be32(pb, 0); /* Reserved */
416 455
    put_be16(pb, 0); /* Reserved */
417 456
    put_be16(pb, 1); /* Data-reference index, XXX  == 1 */
......
421 460
    put_be16(pb, 0); /* Revision level */
422 461
    put_be32(pb, 0); /* Reserved */
423 462

  
463
    if (version == 2) {
464
        put_be16(pb, 3);
465
        put_be16(pb, 16);
466
        put_be16(pb, 0xfffe);
467
        put_be16(pb, 0);
468
        put_be32(pb, 0x00010000);
469
        put_be32(pb, 72);
470
        put_be64(pb, av_dbl2int(track->timescale));
471
        put_be32(pb, track->enc->channels);
472
        put_be32(pb, 0x7F000000);
473
        put_be32(pb, av_get_bits_per_sample(track->enc->codec_id));
474
        put_be32(pb, mov_get_lpcm_flags(track->enc->codec_id));
475
        put_be32(pb, track->sampleSize);
476
        put_be32(pb, track->enc->frame_size);
477
    } else {
424 478
    if (track->mode == MODE_MOV) {
425 479
        put_be16(pb, track->enc->channels);
426 480
        if (track->enc->codec_id == CODEC_ID_PCM_U8 ||
......
438 492
    put_be16(pb, 0); /* packet size (= 0) */
439 493
    put_be16(pb, track->timescale); /* Time scale */
440 494
    put_be16(pb, 0); /* Reserved */
495
    }
441 496

  
442 497
    if(version == 1) { /* SoundDescription V1 extended info */
443 498
        put_be32(pb, track->enc->frame_size); /* Samples per packet */
......
1788 1843
                st->codec->frame_size = 1;
1789 1844
                track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels;
1790 1845
            }
1791
            if(track->mode != MODE_MOV &&
1792
               track->enc->codec_id == CODEC_ID_MP3 && track->enc->sample_rate < 16000){
1846
            if (track->mode != MODE_MOV) {
1847
                if (track->timescale > INT16_MAX) {
1848
                    av_log(s, AV_LOG_ERROR, "track %d: output format does not support "
1849
                           "sample rate %dhz\n", i, track->timescale);
1850
                    goto error;
1851
                }
1852
                if (track->enc->codec_id == CODEC_ID_MP3 && track->timescale < 16000) {
1793 1853
                av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not supported\n",
1794 1854
                       i, track->enc->sample_rate);
1795 1855
                goto error;
1856
                }
1796 1857
            }
1797 1858
        }else if(st->codec->codec_type == CODEC_TYPE_SUBTITLE){
1798 1859
            track->timescale = st->codec->time_base.den;

Also available in: Unified diff