For encoding, AVCodecContext.frame_size is the number of input samples to
send to the encoder and does not necessarily correspond directly to the
timestamps of the output packets.
... | ... |
@@ -566,6 +566,25 @@ static int get_cluster_duration(MOVTrack *track, int cluster_idx) |
566 | 566 |
return next_dts - track->cluster[cluster_idx].dts; |
567 | 567 |
} |
568 | 568 |
|
569 |
+static int get_samples_per_packet(MOVTrack *track) |
|
570 |
+{ |
|
571 |
+ int i, first_duration; |
|
572 |
+ |
|
573 |
+ /* use 1 for raw PCM */ |
|
574 |
+ if (!track->audio_vbr) |
|
575 |
+ return 1; |
|
576 |
+ |
|
577 |
+ /* check to see if duration is constant for all clusters */ |
|
578 |
+ if (!track->entry) |
|
579 |
+ return 0; |
|
580 |
+ first_duration = get_cluster_duration(track, 0); |
|
581 |
+ for (i = 1; i < track->entry; i++) { |
|
582 |
+ if (get_cluster_duration(track, i) != first_duration) |
|
583 |
+ return 0; |
|
584 |
+ } |
|
585 |
+ return first_duration; |
|
586 |
+} |
|
587 |
+ |
|
569 | 588 |
static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) |
570 | 589 |
{ |
571 | 590 |
int64_t pos = avio_tell(pb); |
... | ... |
@@ -602,7 +621,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) |
602 | 602 |
avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); |
603 | 603 |
avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id)); |
604 | 604 |
avio_wb32(pb, track->sample_size); |
605 |
- avio_wb32(pb, track->audio_vbr ? track->enc->frame_size : 1); |
|
605 |
+ avio_wb32(pb, get_samples_per_packet(track)); |
|
606 | 606 |
} else { |
607 | 607 |
/* reserved for mp4/3gp */ |
608 | 608 |
avio_wb16(pb, 2); |
... | ... |
@@ -3112,10 +3131,6 @@ static int mov_write_header(AVFormatContext *s) |
3112 | 3112 |
} |
3113 | 3113 |
/* set audio_vbr for compressed audio */ |
3114 | 3114 |
if (av_get_bits_per_sample(st->codec->codec_id) < 8) { |
3115 |
- if (!st->codec->frame_size && track->mode == MODE_MOV) { |
|
3116 |
- av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); |
|
3117 |
- goto error; |
|
3118 |
- } |
|
3119 | 3115 |
track->audio_vbr = 1; |
3120 | 3116 |
} |
3121 | 3117 |
if (track->mode != MODE_MOV) { |