diff mbox

[FFmpeg-devel] lavf/mov.c: Set skip_samples according to first edit list, when -ignore_editlist is set.

Message ID 1478930548-17982-1-git-send-email-isasi@google.com
State New
Headers show

Commit Message

Sasi Inguva Nov. 12, 2016, 6:02 a.m. UTC
Signed-off-by: Sasi Inguva <isasi@google.com>
---
 libavformat/isom.h |  2 ++
 libavformat/mov.c  | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

Comments

Derek Buitenhuis Nov. 14, 2016, 1:48 p.m. UTC | #1
On 11/12/2016 6:02 AM, Sasi Inguva wrote:
> +    /* Adjust skip_samples correctly when ignore_editlist is set, to support gapless playback */
> +    if (mov->ignore_editlist && sc->num_non_empty_elst <= 1 &&
> +        st->codecpar->codec_id == AV_CODEC_ID_AAC && sc->first_elist_start_time > 0) {
> +        sc->start_pad = sc->first_elist_start_time;
> +    }

Doesn't this make the name "ignore_editlist" rather untrue?

Also, pinging wm4.

- Derek
Michael Niedermayer Dec. 13, 2016, 12:27 a.m. UTC | #2
On Fri, Nov 11, 2016 at 10:02:28PM -0800, Sasi Inguva wrote:
> Signed-off-by: Sasi Inguva <isasi@google.com>
> ---
>  libavformat/isom.h |  2 ++
>  libavformat/mov.c  | 22 +++++++++++++++++++++-
>  2 files changed, 23 insertions(+), 1 deletion(-)

The commit message should be a bit more verbose,it says whats done
but not why

[...]
wm4 Dec. 13, 2016, 10:24 a.m. UTC | #3
On Fri, 11 Nov 2016 22:02:28 -0800
Sasi Inguva <isasi-at-google.com@ffmpeg.org> wrote:

> Signed-off-by: Sasi Inguva <isasi@google.com>
> ---
>  libavformat/isom.h |  2 ++
>  libavformat/mov.c  | 22 +++++++++++++++++++++-
>  2 files changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index d684502..6a8a4e3 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -164,6 +164,8 @@ typedef struct MOVStreamContext {
>      uint32_t tmcd_flags;  ///< tmcd track flags
>      int64_t track_end;    ///< used for dts generation in fragmented movie files
>      int start_pad;        ///< amount of samples to skip due to enc-dec delay
> +    int first_elist_start_time;   ///< first edit list start time.
> +    int num_non_empty_elst;       ///< number of non empty edit lists.
>      unsigned int rap_group_count;
>      MOVSbgp *rap_group;
>  
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 9ec7d03..676694e 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3245,6 +3245,12 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
>          }
>      }
>  
> +    /* Adjust skip_samples correctly when ignore_editlist is set, to support gapless playback */
> +    if (mov->ignore_editlist && sc->num_non_empty_elst <= 1 &&
> +        st->codecpar->codec_id == AV_CODEC_ID_AAC && sc->first_elist_start_time > 0) {
> +        sc->start_pad = sc->first_elist_start_time;
> +    }
> +
>      /* only use old uncompressed audio chunk demuxing when stts specifies it */
>      if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
>            sc->stts_count == 1 && sc->stts_data[0].duration == 1)) {
> @@ -4424,9 +4430,11 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>      MOVStreamContext *sc;
>      int i, edit_count, version;
>  
> -    if (c->fc->nb_streams < 1 || c->ignore_editlist)
> +    if (c->fc->nb_streams < 1)
>          return 0;
>      sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
> +    sc->first_elist_start_time = 0;
> +    sc->num_non_empty_elst = 0;
>  
>      version = avio_r8(pb); /* version */
>      avio_rb24(pb); /* flags */
> @@ -4463,9 +4471,21 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>                     c->fc->nb_streams-1, i, e->time);
>              return AVERROR_INVALIDDATA;
>          }
> +
> +        if (!sc->first_elist_start_time && e->time > 0) {
> +            sc->first_elist_start_time = e->time;
> +        }
> +
> +        if (e->time >= 0) {
> +            sc->num_non_empty_elst++;
> +        }
>      }
>      sc->elst_count = i;
>  
> +    if (c->ignore_editlist) {
> +        av_freep(&sc->elst_data);
> +        sc->elst_count = 0;
> +    }
>      return 0;
>  }
>  

Why only AAC?
Sasi Inguva Dec. 29, 2016, 10:13 p.m. UTC | #4
Because, AAC had this hack before my patch.
http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavformat/mov.c;h=6e80b93271a4f998af6ba1af795d7d7c5d67f5a1;hb=7b3bc365f9923e30a925f8dece4fddd127a54c5d#l2800


On Tue, Dec 13, 2016 at 2:24 AM, wm4 <nfxjfg@googlemail.com> wrote:

> On Fri, 11 Nov 2016 22:02:28 -0800
> Sasi Inguva <isasi-at-google.com@ffmpeg.org> wrote:
>
> > Signed-off-by: Sasi Inguva <isasi@google.com>
> > ---
> >  libavformat/isom.h |  2 ++
> >  libavformat/mov.c  | 22 +++++++++++++++++++++-
> >  2 files changed, 23 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/isom.h b/libavformat/isom.h
> > index d684502..6a8a4e3 100644
> > --- a/libavformat/isom.h
> > +++ b/libavformat/isom.h
> > @@ -164,6 +164,8 @@ typedef struct MOVStreamContext {
> >      uint32_t tmcd_flags;  ///< tmcd track flags
> >      int64_t track_end;    ///< used for dts generation in fragmented
> movie files
> >      int start_pad;        ///< amount of samples to skip due to enc-dec
> delay
> > +    int first_elist_start_time;   ///< first edit list start time.
> > +    int num_non_empty_elst;       ///< number of non empty edit lists.
> >      unsigned int rap_group_count;
> >      MOVSbgp *rap_group;
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index 9ec7d03..676694e 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -3245,6 +3245,12 @@ static void mov_build_index(MOVContext *mov,
> AVStream *st)
> >          }
> >      }
> >
> > +    /* Adjust skip_samples correctly when ignore_editlist is set, to
> support gapless playback */
> > +    if (mov->ignore_editlist && sc->num_non_empty_elst <= 1 &&
> > +        st->codecpar->codec_id == AV_CODEC_ID_AAC &&
> sc->first_elist_start_time > 0) {
> > +        sc->start_pad = sc->first_elist_start_time;
> > +    }
> > +
> >      /* only use old uncompressed audio chunk demuxing when stts
> specifies it */
> >      if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
> >            sc->stts_count == 1 && sc->stts_data[0].duration == 1)) {
> > @@ -4424,9 +4430,11 @@ static int mov_read_elst(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
> >      MOVStreamContext *sc;
> >      int i, edit_count, version;
> >
> > -    if (c->fc->nb_streams < 1 || c->ignore_editlist)
> > +    if (c->fc->nb_streams < 1)
> >          return 0;
> >      sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
> > +    sc->first_elist_start_time = 0;
> > +    sc->num_non_empty_elst = 0;
> >
> >      version = avio_r8(pb); /* version */
> >      avio_rb24(pb); /* flags */
> > @@ -4463,9 +4471,21 @@ static int mov_read_elst(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
> >                     c->fc->nb_streams-1, i, e->time);
> >              return AVERROR_INVALIDDATA;
> >          }
> > +
> > +        if (!sc->first_elist_start_time && e->time > 0) {
> > +            sc->first_elist_start_time = e->time;
> > +        }
> > +
> > +        if (e->time >= 0) {
> > +            sc->num_non_empty_elst++;
> > +        }
> >      }
> >      sc->elst_count = i;
> >
> > +    if (c->ignore_editlist) {
> > +        av_freep(&sc->elst_data);
> > +        sc->elst_count = 0;
> > +    }
> >      return 0;
> >  }
> >
>
> Why only AAC?
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Sasi Inguva Dec. 29, 2016, 10:15 p.m. UTC | #5
True.  Correct way would be to have another option controlling just the
mov_fix_index part for the edit list code.

On Mon, Nov 14, 2016 at 5:48 AM, Derek Buitenhuis <
derek.buitenhuis@gmail.com> wrote:

> On 11/12/2016 6:02 AM, Sasi Inguva wrote:
> > +    /* Adjust skip_samples correctly when ignore_editlist is set, to
> support gapless playback */
> > +    if (mov->ignore_editlist && sc->num_non_empty_elst <= 1 &&
> > +        st->codecpar->codec_id == AV_CODEC_ID_AAC &&
> sc->first_elist_start_time > 0) {
> > +        sc->start_pad = sc->first_elist_start_time;
> > +    }
>
> Doesn't this make the name "ignore_editlist" rather untrue?
>
> Also, pinging wm4.
>
> - Derek
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Sasi Inguva Dec. 29, 2016, 11:07 p.m. UTC | #6
Sent a patch adding a new option to lavf/mov.c . PTAL.

Thanks.

On Thu, Dec 29, 2016 at 2:15 PM, Sasi Inguva <isasi@google.com> wrote:

> True.  Correct way would be to have another option controlling just the
> mov_fix_index part for the edit list code.
>
> On Mon, Nov 14, 2016 at 5:48 AM, Derek Buitenhuis <
> derek.buitenhuis@gmail.com> wrote:
>
>> On 11/12/2016 6:02 AM, Sasi Inguva wrote:
>> > +    /* Adjust skip_samples correctly when ignore_editlist is set, to
>> support gapless playback */
>> > +    if (mov->ignore_editlist && sc->num_non_empty_elst <= 1 &&
>> > +        st->codecpar->codec_id == AV_CODEC_ID_AAC &&
>> sc->first_elist_start_time > 0) {
>> > +        sc->start_pad = sc->first_elist_start_time;
>> > +    }
>>
>> Doesn't this make the name "ignore_editlist" rather untrue?
>>
>> Also, pinging wm4.
>>
>> - Derek
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
diff mbox

Patch

diff --git a/libavformat/isom.h b/libavformat/isom.h
index d684502..6a8a4e3 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -164,6 +164,8 @@  typedef struct MOVStreamContext {
     uint32_t tmcd_flags;  ///< tmcd track flags
     int64_t track_end;    ///< used for dts generation in fragmented movie files
     int start_pad;        ///< amount of samples to skip due to enc-dec delay
+    int first_elist_start_time;   ///< first edit list start time.
+    int num_non_empty_elst;       ///< number of non empty edit lists.
     unsigned int rap_group_count;
     MOVSbgp *rap_group;
 
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 9ec7d03..676694e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3245,6 +3245,12 @@  static void mov_build_index(MOVContext *mov, AVStream *st)
         }
     }
 
+    /* Adjust skip_samples correctly when ignore_editlist is set, to support gapless playback */
+    if (mov->ignore_editlist && sc->num_non_empty_elst <= 1 &&
+        st->codecpar->codec_id == AV_CODEC_ID_AAC && sc->first_elist_start_time > 0) {
+        sc->start_pad = sc->first_elist_start_time;
+    }
+
     /* only use old uncompressed audio chunk demuxing when stts specifies it */
     if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
           sc->stts_count == 1 && sc->stts_data[0].duration == 1)) {
@@ -4424,9 +4430,11 @@  static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     MOVStreamContext *sc;
     int i, edit_count, version;
 
-    if (c->fc->nb_streams < 1 || c->ignore_editlist)
+    if (c->fc->nb_streams < 1)
         return 0;
     sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
+    sc->first_elist_start_time = 0;
+    sc->num_non_empty_elst = 0;
 
     version = avio_r8(pb); /* version */
     avio_rb24(pb); /* flags */
@@ -4463,9 +4471,21 @@  static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
                    c->fc->nb_streams-1, i, e->time);
             return AVERROR_INVALIDDATA;
         }
+
+        if (!sc->first_elist_start_time && e->time > 0) {
+            sc->first_elist_start_time = e->time;
+        }
+
+        if (e->time >= 0) {
+            sc->num_non_empty_elst++;
+        }
     }
     sc->elst_count = i;
 
+    if (c->ignore_editlist) {
+        av_freep(&sc->elst_data);
+        sc->elst_count = 0;
+    }
     return 0;
 }