[FFmpeg-cvslog] movenc: use timestamps instead of frame_size for samples-per-packet

Justin Ruggles git at videolan.org
Tue Feb 28 03:53:26 CET 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Sun Feb 26 16:25:46 2012 -0500| [f234e8a32e6c69d7b63f8627f278be7c2c987f43] | committer: Justin Ruggles

movenc: use timestamps instead of frame_size for samples-per-packet

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f234e8a32e6c69d7b63f8627f278be7c2c987f43
---

 libavformat/movenc.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index a74dd2e..10bcedc 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -566,6 +566,25 @@ static int get_cluster_duration(MOVTrack *track, int cluster_idx)
     return next_dts - track->cluster[cluster_idx].dts;
 }
 
+static int get_samples_per_packet(MOVTrack *track)
+{
+    int i, first_duration;
+
+    /* use 1 for raw PCM */
+    if (!track->audio_vbr)
+        return 1;
+
+    /* check to see if duration is constant for all clusters */
+    if (!track->entry)
+        return 0;
+    first_duration = get_cluster_duration(track, 0);
+    for (i = 1; i < track->entry; i++) {
+        if (get_cluster_duration(track, i) != first_duration)
+            return 0;
+    }
+    return first_duration;
+}
+
 static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track)
 {
     int64_t pos = avio_tell(pb);
@@ -602,7 +621,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track)
         avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id));
         avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id));
         avio_wb32(pb, track->sample_size);
-        avio_wb32(pb, track->audio_vbr ? track->enc->frame_size : 1);
+        avio_wb32(pb, get_samples_per_packet(track));
     } else {
         /* reserved for mp4/3gp */
         avio_wb16(pb, 2);
@@ -3112,10 +3131,6 @@ static int mov_write_header(AVFormatContext *s)
             }
             /* set audio_vbr for compressed audio */
             if (av_get_bits_per_sample(st->codec->codec_id) < 8) {
-                if (!st->codec->frame_size && track->mode == MODE_MOV) {
-                    av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i);
-                    goto error;
-                }
                 track->audio_vbr = 1;
             }
             if (track->mode != MODE_MOV) {



More information about the ffmpeg-cvslog mailing list