[4/4] mov: extract audio initial_padding from edit list

Message ID 20170224202416.13106-4-stebbins@jetheaddev.com
State New
Headers show

Commit Message

John Stebbins Feb. 24, 2017, 8:24 p.m.
---
 libavformat/mov.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Patch

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1657647..a080216 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3806,13 +3806,24 @@  static int mov_read_header(AVFormatContext *s)
         MOVStreamContext *sc = st->priv_data;
 
         switch (st->codecpar->codec_type) {
-        case AVMEDIA_TYPE_AUDIO:
+        case AVMEDIA_TYPE_AUDIO: {
+            int64_t skip_samples;
             err = ff_replaygain_export(st, s->metadata);
             if (err < 0) {
                 mov_read_close(s);
                 return err;
             }
+            skip_samples = av_rescale(sc->time_offset_skip,
+                                      st->codecpar->sample_rate,
+                                      sc->time_scale);
+            /* If the number of skipped samples specified in the edit list
+             * is in a range that looks like an initial_padding, set
+             * initial_padding to tell decoders to drop the samples */
+            if (skip_samples > 0 && skip_samples <= 3840) {
+                st->codecpar->initial_padding = skip_samples;
+            }
             break;
+        }
         case AVMEDIA_TYPE_VIDEO:
             if (sc->display_matrix) {
                 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX,