On Fri, 20 Jan 2012, Martin Storsjö wrote:

---
libavformat/isom.h |    1 +
libavformat/mov.c  |   15 ++++++++++++++-
2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index e6d04dc..16d7776 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -125,6 +125,7 @@ typedef struct MOVStreamContext {
    int dts_shift;        ///< dts shift when ctts is negative
    uint32_t palette[256];
    int has_palette;
+    int64_t data_size;
} MOVStreamContext;

typedef struct MOVContext {
diff --git a/libavformat/mov.c b/libavformat/mov.c
index f12a8b4..dd580de 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1581,8 +1581,10 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)

    init_get_bits(&gb, buf, 8*num_bytes);

-    for (i=0; i<entries; i++)
+    for (i = 0; i < entries; i++) {
        sc->sample_sizes[i] = get_bits_long(&gb, field_size);
+        sc->data_size += sc->sample_sizes[i];
+    }

    av_free(buf);
    return 0;
@@ -2259,6 +2261,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
        distance++;
        dts += sample_duration;
        offset += sample_size;
+        sc->data_size += sample_size;
    }
    frag->moof_offset = offset;
    st->duration = dts + sc->time_offset;
@@ -2577,6 +2580,16 @@ static int mov_read_header(AVFormatContext *s, 
AVFormatParameters *ap)
    if (pb->seekable && mov->chapter_track > 0)
        mov_read_chapters(s);

+    if (mov->trex_data) {
+        int i;
+        for (i = 0; i < s->nb_streams; i++) {
+            AVStream *st = s->streams[i];
+            MOVStreamContext *sc = st->priv_data;
+            if (st->duration)
+                st->codec->bit_rate = 
sc->data_size*8*sc->time_scale/st->duration;
+        }
+    }
+
    return 0;
}

--
1.7.3.1

Ok'd on irc by Ronald and Vladimir - Vladimir asked for some spaces between operators in the bit_rate calculation, which I added locally.

// Martin
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to