Re: [FFmpeg-devel] [PATCH] avformat/mov: set AVFMT_SEEK_TO_PTS flag

2019-05-02 Thread Sasi Inguva
Looks good to me. We were already doing PTS based seeking in MOV demuxer
(although it's not perfect).

On Thu, May 2, 2019 at 3:23 AM Gyan  wrote:

>
> FATE passes. Checked that transcoded output remains the same whereas in
> copy mode, seek to a video KF using ffmpeg cli returns the desired KF
> and not the earlier KF, as happens at present.
>
> Gyan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set start_time for all sterams (in case of edit lists).

2018-08-09 Thread Sasi Inguva
Thanks. Attaching the corrected patch


On Thu, Aug 9, 2018 at 5:59 AM Moritz Barsnick  wrote:

> > [PATCH] lavf/mov.c: Set start_time for all sterams (in case of edit
> lists).
>  ^ streams
>
> Moritz
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
From a0da82579a1c9ebb81bd029750fa718fa5f1c152 Mon Sep 17 00:00:00 2001
From: Sasi Inguva 
Date: Mon, 6 Aug 2018 16:28:50 -0700
Subject: [PATCH] lavf/mov.c: Set start_time for all streams (in case of edit
 lists).

Fixes vorbis mp4 audio files, with edit list specified. Since
st->skip_samples is not set in case of vorbis , ffmpeg computes the
start_time as negative.

Signed-off-by: Sasi Inguva 
---
 libavformat/mov.c  | 4 ++--
 tests/fate/mov.mak | 5 +
 tests/ref/fate/mov-neg-firstpts-discard-vorbis | 3 +++
 3 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 tests/ref/fate/mov-neg-firstpts-discard-vorbis

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 82cd410a72..c0f90edef7 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3684,9 +3684,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 st->index_entries[i].timestamp -= msc->min_corrected_pts;
 }
 }
-// Start time should be equal to zero or the duration of any empty edits.
-st->start_time = empty_edits_sum_duration;
 }
+// Start time should be equal to zero or the duration of any empty edits.
+st->start_time = empty_edits_sum_duration;
 
 // Update av stream length, if it ends up shorter than the track's media duration
 st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts);
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 6f0e28d21e..3d9e4280bb 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -19,6 +19,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-stream-shorter-than-movie \
 
 FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
+   fate-mov-neg-firstpts-discard-vorbis \
fate-mov-aac-2048-priming \
fate-mov-zombie \
fate-mov-init-nonkeyframe \
@@ -89,6 +90,10 @@ fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -acodec aac_fixed -i
 # Makes sure that the stream start_time is not negative when the first packet is a DISCARD packet with negative timestamp.
 fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream=start_time -bitexact $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov
 
+# Makes sure that the VORBIS audio stream start_time is not negative when the first few packets are DISCARD packets
+# with negative timestamps (skip_samples is not set for Vorbis, so ffmpeg computes start_time as negative if not specified by demuxer).
+fate-mov-neg-firstpts-discard-vorbis: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream=start_time -bitexact $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard_vorbis.mp4
+
 # Makes sure that expected frames are generated for mov_neg_first_pts_discard.mov with -vsync 1
 fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact -i $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
 
diff --git a/tests/ref/fate/mov-neg-firstpts-discard-vorbis b/tests/ref/fate/mov-neg-firstpts-discard-vorbis
new file mode 100644
index 00..2e295e3b68
--- /dev/null
+++ b/tests/ref/fate/mov-neg-firstpts-discard-vorbis
@@ -0,0 +1,3 @@
+[STREAM]
+start_time=0.00
+[/STREAM]
-- 
2.18.0.597.ga71716f1ad-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set start_time for audio too (in case of edit lists).

2018-08-09 Thread Sasi Inguva
Pls find attached, the corrected patch.

On Wed, Aug 8, 2018 at 5:24 PM Sasi Inguva  wrote:

> Ok. i'll correct the commit message.
>
> On Wed, Aug 8, 2018 at 4:25 PM Michael Niedermayer 
> wrote:
>
>> On Wed, Aug 08, 2018 at 12:20:34PM -0700, Sasi Inguva wrote:
>> > i intended it only for audio, but i don't see any harm if it gets
>> applied
>> > to subtitle tracks also .
>>
>> if you want subs incldued then the commit message is wrong at least
>> if you dont want subs incldued the change is wrong
>>
>>
>> [...]
>> --
>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>
>> If you drop bombs on a foreign country and kill a hundred thousand
>> innocent people, expect your government to call the consequence
>> "unprovoked inhuman terrorist attacks" and use it to justify dropping
>> more bombs and killing more people. The technology changed, the idea is
>> old.
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
From a0da82579a1c9ebb81bd029750fa718fa5f1c152 Mon Sep 17 00:00:00 2001
From: Sasi Inguva 
Date: Mon, 6 Aug 2018 16:28:50 -0700
Subject: [PATCH] lavf/mov.c: Set start_time for all streams (in case of edit
 lists).

Fixes vorbis mp4 audio files, with edit list specified. Since
st->skip_samples is not set in case of vorbis , ffmpeg computes the
start_time as negative.

Signed-off-by: Sasi Inguva 
---
 libavformat/mov.c  | 4 ++--
 tests/fate/mov.mak | 5 +
 tests/ref/fate/mov-neg-firstpts-discard-vorbis | 3 +++
 3 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 tests/ref/fate/mov-neg-firstpts-discard-vorbis

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 82cd410a72..c0f90edef7 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3684,9 +3684,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 st->index_entries[i].timestamp -= msc->min_corrected_pts;
 }
 }
-// Start time should be equal to zero or the duration of any empty edits.
-st->start_time = empty_edits_sum_duration;
 }
+// Start time should be equal to zero or the duration of any empty edits.
+st->start_time = empty_edits_sum_duration;
 
 // Update av stream length, if it ends up shorter than the track's media duration
 st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts);
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 6f0e28d21e..3d9e4280bb 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -19,6 +19,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-stream-shorter-than-movie \
 
 FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
+   fate-mov-neg-firstpts-discard-vorbis \
fate-mov-aac-2048-priming \
fate-mov-zombie \
fate-mov-init-nonkeyframe \
@@ -89,6 +90,10 @@ fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -acodec aac_fixed -i
 # Makes sure that the stream start_time is not negative when the first packet is a DISCARD packet with negative timestamp.
 fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream=start_time -bitexact $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov
 
+# Makes sure that the VORBIS audio stream start_time is not negative when the first few packets are DISCARD packets
+# with negative timestamps (skip_samples is not set for Vorbis, so ffmpeg computes start_time as negative if not specified by demuxer).
+fate-mov-neg-firstpts-discard-vorbis: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream=start_time -bitexact $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard_vorbis.mp4
+
 # Makes sure that expected frames are generated for mov_neg_first_pts_discard.mov with -vsync 1
 fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact -i $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
 
diff --git a/tests/ref/fate/mov-neg-firstpts-discard-vorbis b/tests/ref/fate/mov-neg-firstpts-discard-vorbis
new file mode 100644
index 00..2e295e3b68
--- /dev/null
+++ b/tests/ref/fate/mov-neg-firstpts-discard-vorbis
@@ -0,0 +1,3 @@
+[STREAM]
+start_time=0.00
+[/STREAM]
-- 
2.18.0.597.ga71716f1ad-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set start_time for audio too (in case of edit lists).

2018-08-08 Thread Sasi Inguva
Ok. i'll correct the commit message.

On Wed, Aug 8, 2018 at 4:25 PM Michael Niedermayer 
wrote:

> On Wed, Aug 08, 2018 at 12:20:34PM -0700, Sasi Inguva wrote:
> > i intended it only for audio, but i don't see any harm if it gets applied
> > to subtitle tracks also .
>
> if you want subs incldued then the commit message is wrong at least
> if you dont want subs incldued the change is wrong
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> If you drop bombs on a foreign country and kill a hundred thousand
> innocent people, expect your government to call the consequence
> "unprovoked inhuman terrorist attacks" and use it to justify dropping
> more bombs and killing more people. The technology changed, the idea is
> old.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set start_time for audio too (in case of edit lists).

2018-08-08 Thread Sasi Inguva
i intended it only for audio, but i don't see any harm if it gets applied
to subtitle tracks also .

On Tue, Aug 7, 2018 at 3:23 PM Michael Niedermayer 
wrote:

> On Mon, Aug 06, 2018 at 04:32:29PM -0700, isasi-at-google@ffmpeg.org
> wrote:
> > From: Sasi Inguva 
> >
> > Fixes vorbis mp4 audio files, with edit list specified. Since
> > st->skip_samples is not set in case of vorbis , ffmpeg computes the
> > start_time as negative.
> >
> > Signed-off-by: Sasi Inguva 
> > ---
> >  libavformat/mov.c  | 4 ++--
> >  tests/fate/mov.mak | 5 +
> >  tests/ref/fate/mov-neg-firstpts-discard-vorbis | 3 +++
> >  3 files changed, 10 insertions(+), 2 deletions(-)
> >  create mode 100644 tests/ref/fate/mov-neg-firstpts-discard-vorbis
>
> The commit message speaks of audio, this changes subtitles too
> is this intended ?
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I have often repented speaking, but never of holding my tongue.
> -- Xenocrates
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set start_time for audio too (in case of edit lists).

2018-08-06 Thread Sasi Inguva
Attaching the fate file.

On Mon, Aug 6, 2018 at 4:33 PM  wrote:

> From: Sasi Inguva 
>
> Fixes vorbis mp4 audio files, with edit list specified. Since
> st->skip_samples is not set in case of vorbis , ffmpeg computes the
> start_time as negative.
>
> Signed-off-by: Sasi Inguva 
> ---
>  libavformat/mov.c  | 4 ++--
>  tests/fate/mov.mak | 5 +
>  tests/ref/fate/mov-neg-firstpts-discard-vorbis | 3 +++
>  3 files changed, 10 insertions(+), 2 deletions(-)
>  create mode 100644 tests/ref/fate/mov-neg-firstpts-discard-vorbis
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 82cd410a72..c0f90edef7 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3684,9 +3684,9 @@ static void mov_fix_index(MOVContext *mov, AVStream
> *st)
>  st->index_entries[i].timestamp -= msc->min_corrected_pts;
>  }
>  }
> -// Start time should be equal to zero or the duration of any
> empty edits.
> -st->start_time = empty_edits_sum_duration;
>  }
> +// Start time should be equal to zero or the duration of any empty
> edits.
> +st->start_time = empty_edits_sum_duration;
>
>  // Update av stream length, if it ends up shorter than the track's
> media duration
>  st->duration = FFMIN(st->duration, edit_list_dts_entry_end -
> start_dts);
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 6f0e28d21e..3d9e4280bb 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -19,6 +19,7 @@ FATE_MOV = fate-mov-3elist \
> fate-mov-stream-shorter-than-movie \
>
>  FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
> +   fate-mov-neg-firstpts-discard-vorbis \
> fate-mov-aac-2048-priming \
> fate-mov-zombie \
> fate-mov-init-nonkeyframe \
> @@ -89,6 +90,10 @@ fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags
> +bitexact -acodec aac_fixed -i
>  # Makes sure that the stream start_time is not negative when the first
> packet is a DISCARD packet with negative timestamp.
>  fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF)
> -show_entries stream=start_time -bitexact
> $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov
>
> +# Makes sure that the VORBIS audio stream start_time is not negative when
> the first few packets are DISCARD packets
> +# with negative timestamps (skip_samples is not set for Vorbis, so ffmpeg
> computes start_time as negative if not specified by demuxer).
> +fate-mov-neg-firstpts-discard-vorbis: CMD = run
> ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream=start_time -bitexact
> $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard_vorbis.mp4
> +
>  # Makes sure that expected frames are generated for
> mov_neg_first_pts_discard.mov with -vsync 1
>  fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact -i
> $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
>
> diff --git a/tests/ref/fate/mov-neg-firstpts-discard-vorbis
> b/tests/ref/fate/mov-neg-firstpts-discard-vorbis
> new file mode 100644
> index 00..2e295e3b68
> --- /dev/null
> +++ b/tests/ref/fate/mov-neg-firstpts-discard-vorbis
> @@ -0,0 +1,3 @@
> +[STREAM]
> +start_time=0.00
> +[/STREAM]
> --
> 2.18.0.597.ga71716f1ad-goog
>
>


mov_neg_first_pts_discard_vorbis.mp4
Description: video/mp4
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/4] avformat/mov: Break out of inner loop early in mov_estimate_video_delay()

2018-07-11 Thread Sasi Inguva
LGTM. thanks
On Tue, Jul 10, 2018 at 5:18 PM Michael Niedermayer 
wrote:

> 0.266 <- 0.299 sec (this is time ffmpeg so containing alot other things)
>
> Sample for benchmark was: ffmpeg -f rawvideo -pix_fmt yuv420p -s 32x32 -i
> /dev/zero -t 24:00:00.00 out.mp4
>
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mov.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 951a337cca..b0b9fd99cc 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3331,7 +3331,8 @@ static void mov_estimate_video_delay(MOVContext *c,
> AVStream* st) {
>  if (pts_buf[j] < pts_buf[r]) {
>  FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
>  ++num_swaps;
> -}
> +} else
> +break;
>
Prefer keeping paranthesis around break especially since there are
paranthesis around the if block.


>  j = r;
>  }
>  st->codecpar->video_delay = FFMAX(st->codecpar->video_delay,
> num_swaps);
> --
> 2.18.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/4] avformat/mov: Simplify last element computation in mov_estimate_video_delay()

2018-07-11 Thread Sasi Inguva
LGTM.

On Tue, Jul 10, 2018 at 5:18 PM Michael Niedermayer 
wrote:

> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mov.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 67b3e11eb9..951a337cca 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3310,13 +3310,12 @@ static void mov_estimate_video_delay(MOVContext
> *c, AVStream* st) {
>  st->codecpar->codec_id == AV_CODEC_ID_H264) {
>  st->codecpar->video_delay = 0;
>  for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
> +// Point j to the last elem of the buffer and insert the
> current pts there.
> +j = buf_start;
>  buf_start = (buf_start + 1);
>  if (buf_start == MAX_REORDER_DELAY + 1)
>  buf_start = 0;
>
> -// Point j to the last elem of the buffer and insert the
> current pts there.
> -j = buf_start - 1;
> -if (j < 0) j = MAX_REORDER_DELAY;
>  pts_buf[j] = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
>
>  // The timestamps that are already in the sorted buffer, and
> are greater than the
> --
> 2.18.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/4] bavformat/mov: Eliminate variable buf_size from mov_estimate_video_delay()

2018-07-11 Thread Sasi Inguva
LGTM. thanks

On Tue, Jul 10, 2018 at 5:18 PM Michael Niedermayer 
wrote:

> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mov.c | 19 ---
>  1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index aabf06de12..67b3e11eb9 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3301,25 +3301,22 @@ static void mov_estimate_video_delay(MOVContext
> *c, AVStream* st) {
>  int ctts_sample = 0;
>  int64_t pts_buf[MAX_REORDER_DELAY + 1]; // Circular buffer to sort
> pts.
>  int buf_start = 0;
> -int buf_size = 0;
>  int j, r, num_swaps;
>
> +for (j = 0; j < MAX_REORDER_DELAY + 1; j++)
> +pts_buf[j] = INT64_MIN;
> +
>  if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
>  st->codecpar->codec_id == AV_CODEC_ID_H264) {
>  st->codecpar->video_delay = 0;
>  for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
> -if (buf_size == (MAX_REORDER_DELAY + 1)) {
> -// If circular buffer is full, then move the first
> element forward.
> -buf_start = (buf_start + 1);
> -if (buf_start == MAX_REORDER_DELAY + 1)
> -buf_start = 0;
> -} else {
> -++buf_size;
> -}
> +buf_start = (buf_start + 1);
> +if (buf_start == MAX_REORDER_DELAY + 1)
> +buf_start = 0;
>
>  // Point j to the last elem of the buffer and insert the
> current pts there.
>  j = buf_start - 1;
> -if (j < 0) j = buf_size - 1;
> +if (j < 0) j = MAX_REORDER_DELAY;
>  pts_buf[j] = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
>
>  // The timestamps that are already in the sorted buffer, and
> are greater than the
> @@ -3331,7 +3328,7 @@ static void mov_estimate_video_delay(MOVContext *c,
> AVStream* st) {
>  num_swaps = 0;
>  while (j != buf_start) {
>  r = j - 1;
> -if (r < 0) r = buf_size - 1;
> +if (r < 0) r = MAX_REORDER_DELAY;
>  if (pts_buf[j] < pts_buf[r]) {
>  FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
>  ++num_swaps;
> --
> 2.18.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/4] avformat/mov: remove modulo operations from mov_estimate_video_delay()

2018-07-11 Thread Sasi Inguva
This one LGTM. Thanks for doing this.

On Tue, Jul 10, 2018 at 5:18 PM Michael Niedermayer 
wrote:

> 0.324 <-0.491 sec
>
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mov.c | 10 +++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 1346ffe480..aabf06de12 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3310,13 +3310,16 @@ static void mov_estimate_video_delay(MOVContext
> *c, AVStream* st) {
>  for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
>  if (buf_size == (MAX_REORDER_DELAY + 1)) {
>  // If circular buffer is full, then move the first
> element forward.
> -buf_start = (buf_start + 1) % buf_size;
> +buf_start = (buf_start + 1);
> +if (buf_start == MAX_REORDER_DELAY + 1)
> +buf_start = 0;
>  } else {
>  ++buf_size;
>  }
>
>  // Point j to the last elem of the buffer and insert the
> current pts there.
> -j = (buf_start + buf_size - 1) % buf_size;
> +j = buf_start - 1;
> +if (j < 0) j = buf_size - 1;
>  pts_buf[j] = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
>
>  // The timestamps that are already in the sorted buffer, and
> are greater than the
> @@ -3327,7 +3330,8 @@ static void mov_estimate_video_delay(MOVContext *c,
> AVStream* st) {
>  // go through, to keep this buffer in sorted order.
>  num_swaps = 0;
>  while (j != buf_start) {
> -r = (j - 1 + buf_size) % buf_size;
> +r = j - 1;
> +if (r < 0) r = buf_size - 1;
>  if (pts_buf[j] < pts_buf[r]) {
>  FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
>  ++num_swaps;
> --
> 2.18.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavformat/yuv4mpeg: Add color range support for Y4M Add color_range support in Y4M. Also set pixel format and color_range for YUVJ pixel formats.

2018-06-25 Thread Sasi Inguva
Friendly ping! Thx.

On Fri, Jun 22, 2018 at 6:25 AM Carl Eugen Hoyos  wrote:

> 2018-06-22 9:29 GMT+02:00, Wang Cao :
> >>
> >> My question was which authority defined this metadata for
> >> y4m? Or which (non-FFmpeg-based) other software
> >> understands the metadata your patch adds to the files.
> >>
> > AFAIK, no other software and authority has defined this metadata
> > for color range. According to https://linux.die.net/man/5/yuv4mpeg,
> > we should be able to use X tag to support color range.
>
> No more comments from me.
>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/3] avformat/mov: Only set pkt->duration to non negative values

2018-06-14 Thread Sasi Inguva
looks good to me

On Wed, Jun 13, 2018 at 10:11 AM Michael Niedermayer 
wrote:

> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/mov.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 5d9ffa69a3..0acf981aef 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -7586,7 +7586,9 @@ static int mov_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>  } else {
>  int64_t next_dts = (sc->current_sample < st->nb_index_entries) ?
>  st->index_entries[sc->current_sample].timestamp :
> st->duration;
> -pkt->duration = next_dts - pkt->dts;
> +
> +if (next_dts >= pkt->dts)
> +pkt->duration = next_dts - pkt->dts;
>  pkt->pts = pkt->dts;
>  }
>  if (st->discard == AVDISCARD_ALL)
> --
> 2.17.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set st->start_time for video streams explicitly.

2018-06-04 Thread Sasi Inguva
friendly ping. thx.

On Thu, May 31, 2018 at 4:26 PM Sasi Inguva  wrote:

> Pls find attached, the correctly signed patch
> Thanks.
>
> On Thu, May 31, 2018 at 4:14 PM Sasi Inguva  wrote:
>
>> Sorry. Forgot to attach the file. Pls find it attached. Also resending
>> the patch signed with correct email address
>>
>> On Thu, May 31, 2018 at 2:14 PM Michael Niedermayer
>>  wrote:
>>
>>> On Tue, May 29, 2018 at 03:39:40PM -0700, Sasi Inguva wrote:
>>> > If start_time is not set, ffmpeg takes the duration from the global
>>> > movie instead of the per stream duration.
>>> > Signed-off-by: Sasi Inguva <
>>> is...@rodete-desktop-imager.corp.google.com>
>>> > ---
>>> >  libavformat/mov.c| 20 +---
>>> >  tests/fate/mov.mak   |  4 +++
>>> >  tests/ref/fate/mov-neg-firstpts-discard  |  2 +-
>>> >  tests/ref/fate/mov-stream-shorter-than-movie | 33 
>>> >  4 files changed, 54 insertions(+), 5 deletions(-)
>>> >  create mode 100644 tests/ref/fate/mov-stream-shorter-than-movie
>>>
>>> i may have missed a link to a sample file
>>>
>>> fate-suite//mov/mov_stream_shorter_than_movie.mov: No such file or
>>> directory
>>> make: *** [fate-mov-stream-shorter-than-movie] Error 1
>>>
>>>
>>>
>>>
>>> [...]
>>> --
>>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>>
>>> It is dangerous to be right in matters on which the established
>>> authorities
>>> are wrong. -- Voltaire
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set st->start_time for video streams explicitly.

2018-05-31 Thread Sasi Inguva
Pls find attached, the correctly signed patch
Thanks.

On Thu, May 31, 2018 at 4:14 PM Sasi Inguva  wrote:

> Sorry. Forgot to attach the file. Pls find it attached. Also resending the
> patch signed with correct email address
>
> On Thu, May 31, 2018 at 2:14 PM Michael Niedermayer 
> wrote:
>
>> On Tue, May 29, 2018 at 03:39:40PM -0700, Sasi Inguva wrote:
>> > If start_time is not set, ffmpeg takes the duration from the global
>> > movie instead of the per stream duration.
>> > Signed-off-by: Sasi Inguva > >
>> > ---
>> >  libavformat/mov.c| 20 +---
>> >  tests/fate/mov.mak   |  4 +++
>> >  tests/ref/fate/mov-neg-firstpts-discard  |  2 +-
>> >  tests/ref/fate/mov-stream-shorter-than-movie | 33 
>> >  4 files changed, 54 insertions(+), 5 deletions(-)
>> >  create mode 100644 tests/ref/fate/mov-stream-shorter-than-movie
>>
>> i may have missed a link to a sample file
>>
>> fate-suite//mov/mov_stream_shorter_than_movie.mov: No such file or
>> directory
>> make: *** [fate-mov-stream-shorter-than-movie] Error 1
>>
>>
>>
>>
>> [...]
>> --
>> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>
>> It is dangerous to be right in matters on which the established
>> authorities
>> are wrong. -- Voltaire
>> _______
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
From ba2feb04ef1ca94f7e1972e23c84c2acde93bf68 Mon Sep 17 00:00:00 2001
From: Sasi Inguva 
Date: Tue, 29 May 2018 15:36:07 -0700
Subject: [PATCH] lavf/mov.c: Set st->start_time for video streams explicitly.

If start_time is not set, ffmpeg takes the duration from the global
movie instead of the per stream duration.
Signed-off-by: Sasi Inguva 
---
 libavformat/mov.c| 20 +---
 tests/fate/mov.mak   |  4 +++
 tests/ref/fate/mov-neg-firstpts-discard  |  2 +-
 tests/ref/fate/mov-stream-shorter-than-movie | 33 
 4 files changed, 54 insertions(+), 5 deletions(-)
 create mode 100644 tests/ref/fate/mov-stream-shorter-than-movie

diff --git a/libavformat/mov.c b/libavformat/mov.c
index f2a540ad50..1915be5fb5 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3672,11 +3672,15 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // If the minimum pts turns out to be greater than zero after fixing the index, then we subtract the
 // dts by that amount to make the first pts zero.
-if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && msc->min_corrected_pts > 0) {
-av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts);
-for (i = 0; i < st->nb_index_entries; ++i) {
-st->index_entries[i].timestamp -= msc->min_corrected_pts;
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (msc->min_corrected_pts > 0) {
+av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first pts zero.\n", msc->min_corrected_pts);
+for (i = 0; i < st->nb_index_entries; ++i) {
+st->index_entries[i].timestamp -= msc->min_corrected_pts;
+}
 }
+// Start time should be equal to zero or the duration of any empty edits.
+st->start_time = empty_edits_sum_duration;
 }
 
 // Update av stream length, if it ends up shorter than the track's media duration
@@ -4012,6 +4016,14 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 mov_fix_index(mov, st);
 }
 
+// Update start time of the stream.
+if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries > 0) {
+st->start_time = st->index_entries[0].timestamp + sc->dts_shift;
+if (sc->ctts_data) {
+st->start_time += sc->ctts_data[0].duration;
+}
+}
+
 mov_estimate_video_delay(mov, st);
 }
 
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index eadee3abfa..c1d399e5c0 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -16,6 +16,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-frag-overlap \
fate-mov-bbi-elst-starts-b \
fate-mov-neg-firstpts-discard-frames \
+	   fate-mov-stream-shorter-than-movie \
 
 FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
fate-mov-aac-2048-priming \
@@ -88,6 +89,9 @@ fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Set st->start_time for video streams explicitly.

2018-05-31 Thread Sasi Inguva
Sorry. Forgot to attach the file. Pls find it attached. Also resending the
patch signed with correct email address

On Thu, May 31, 2018 at 2:14 PM Michael Niedermayer 
wrote:

> On Tue, May 29, 2018 at 03:39:40PM -0700, Sasi Inguva wrote:
> > If start_time is not set, ffmpeg takes the duration from the global
> > movie instead of the per stream duration.
> > Signed-off-by: Sasi Inguva 
> > ---
> >  libavformat/mov.c| 20 +---
> >  tests/fate/mov.mak   |  4 +++
> >  tests/ref/fate/mov-neg-firstpts-discard  |  2 +-
> >  tests/ref/fate/mov-stream-shorter-than-movie | 33 
> >  4 files changed, 54 insertions(+), 5 deletions(-)
> >  create mode 100644 tests/ref/fate/mov-stream-shorter-than-movie
>
> i may have missed a link to a sample file
>
> fate-suite//mov/mov_stream_shorter_than_movie.mov: No such file or
> directory
> make: *** [fate-mov-stream-shorter-than-movie] Error 1
>
>
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> It is dangerous to be right in matters on which the established authorities
> are wrong. -- Voltaire
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


mov_stream_shorter_than_movie.mov
Description: QuickTime movie
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Set st->start_time for video streams explicitly.

2018-05-29 Thread Sasi Inguva
If start_time is not set, ffmpeg takes the duration from the global
movie instead of the per stream duration.
Signed-off-by: Sasi Inguva 
---
 libavformat/mov.c| 20 +---
 tests/fate/mov.mak   |  4 +++
 tests/ref/fate/mov-neg-firstpts-discard  |  2 +-
 tests/ref/fate/mov-stream-shorter-than-movie | 33 
 4 files changed, 54 insertions(+), 5 deletions(-)
 create mode 100644 tests/ref/fate/mov-stream-shorter-than-movie

diff --git a/libavformat/mov.c b/libavformat/mov.c
index f2a540ad50..1915be5fb5 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3672,11 +3672,15 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // If the minimum pts turns out to be greater than zero after fixing the 
index, then we subtract the
 // dts by that amount to make the first pts zero.
-if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && 
msc->min_corrected_pts > 0) {
-av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first 
pts zero.\n", msc->min_corrected_pts);
-for (i = 0; i < st->nb_index_entries; ++i) {
-st->index_entries[i].timestamp -= msc->min_corrected_pts;
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (msc->min_corrected_pts > 0) {
+av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make 
first pts zero.\n", msc->min_corrected_pts);
+for (i = 0; i < st->nb_index_entries; ++i) {
+st->index_entries[i].timestamp -= msc->min_corrected_pts;
+}
 }
+// Start time should be equal to zero or the duration of any empty 
edits.
+st->start_time = empty_edits_sum_duration;
 }
 
 // Update av stream length, if it ends up shorter than the track's media 
duration
@@ -4012,6 +4016,14 @@ static void mov_build_index(MOVContext *mov, AVStream 
*st)
 mov_fix_index(mov, st);
 }
 
+// Update start time of the stream.
+if (st->start_time == AV_NOPTS_VALUE && st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO && st->nb_index_entries > 0) {
+st->start_time = st->index_entries[0].timestamp + sc->dts_shift;
+if (sc->ctts_data) {
+st->start_time += sc->ctts_data[0].duration;
+}
+}
+
 mov_estimate_video_delay(mov, st);
 }
 
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index eadee3abfa..c1d399e5c0 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -16,6 +16,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-frag-overlap \
fate-mov-bbi-elst-starts-b \
fate-mov-neg-firstpts-discard-frames \
+  fate-mov-stream-shorter-than-movie \
 
 FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
fate-mov-aac-2048-priming \
@@ -88,6 +89,9 @@ fate-mov-neg-firstpts-discard: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entri
 # Makes sure that expected frames are generated for 
mov_neg_first_pts_discard.mov with -vsync 1
 fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
 
+# Makes sure that no frame is dropped/duplicated with fps filter due to 
start_time / duration miscalculations.
+fate-mov-stream-shorter-than-movie: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/mov/mov_stream_shorter_than_movie.mov -vf fps=fps=24 -an
+
 fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets 
-print_format compact $(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
 fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams 
-show_packets -show_frames -bitexact -print_format compact 
$(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
diff --git a/tests/ref/fate/mov-neg-firstpts-discard 
b/tests/ref/fate/mov-neg-firstpts-discard
index 7c982d3ffe..2e295e3b68 100644
--- a/tests/ref/fate/mov-neg-firstpts-discard
+++ b/tests/ref/fate/mov-neg-firstpts-discard
@@ -1,3 +1,3 @@
 [STREAM]
-start_time=N/A
+start_time=0.00
 [/STREAM]
diff --git a/tests/ref/fate/mov-stream-shorter-than-movie 
b/tests/ref/fate/mov-stream-shorter-than-movie
new file mode 100644
index 00..28f3ef378c
--- /dev/null
+++ b/tests/ref/fate/mov-stream-shorter-than-movie
@@ -0,0 +1,33 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 640x480
+#sar 0: 0/1
+#stream#, dts,pts, duration, size, hash
+0,  0,  0,1,   460800, 3a26ddfa53f09d535c701138027e49dc
+0,  1,  1,1,   460800, f09fe0d079ee81eb7db617b48ab5eecf
+0,  2,  2,1,   460800, 40a165b074c7f4d34a41f320400737fc
+0,  3,  3,1,   460800, 8ba73359c89ebc51e29847ef0e27f7c3
+0,  4,  4, 

Re: [FFmpeg-devel] [PATCH] mov: Make sure PTS are both monotonically increasing, and unique

2018-05-29 Thread Sasi Inguva
Hi. sorry for the late reply. I sent a patch similar to this a while back
https://patchwork.ffmpeg.org/patch/8227/  but it got lost in the sea. You
also want to do,
@@ -3579,7 +3579,8 @@ static void mov_fix_index(MOVContext *mov, AVStream
*st)
 frame_duration_buffer[num_discarded_begin - 1] =
frame_duration;

-if (first_non_zero_audio_edit > 0 &&
st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO
&&
+first_non_zero_audio_edit > 0 &&
st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
 st->skip_samples += frame_duration;
 }

so that we only increment skip samples for audio streams. Otherwise patch
looks good to me.

On Thu, May 17, 2018 at 7:03 AM Derek Buitenhuis 
wrote:

> On Tue, May 15, 2018 at 8:44 PM, Derek Buitenhuis
>  wrote:
> > We already did this for audio, but it should be done for video too.
> > If we don't, seeking back to the start of the file, for example, can
> > become quite broken, since the first N packets will have repeating
> > and nonmonotonic PTS, yet they need to be decoded even if they are
> > to be discarded.
> >
> > Signed-off-by: Derek Buitenhuis 
> > ---
> >  libavformat/mov.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
>
> Ping.
>
> Is nobody outside Sasi able to review code in this part of
> mov.c? That is slightly worrying to me.
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] display: Add AVDisplayOrientation API

2018-04-04 Thread Sasi Inguva
On Wed, Apr 4, 2018 at 8:30 AM, Vittorio Giovara  wrote:

> The transformation operations that can be described by a display matrix
> are not limited to pure rotation, but include horizontal and vertical
> flip, as well as transpose and antitranspose. Unfortunately the current
> API can only return a rotation angle in degrees, and is not designed to
> detect flip operations or a combination of rotation and flip.
>
> So implement an additional API to analyze the display matrix and return
> the most common rotation operations (multiples of 90º) as well flips or
> a combination thereof. This function returns a bitfield mask composed of
> AVDisplayOrientation elements that describe which rendering operations
> should be performed on the frame. The existing API is still available
> and useful in case of custom rotations.
>
> Signed-off-by: Vittorio Giovara 
> ---
> Note: the new operations describe a clockwise rotation, while the
> old API provided a counterclockwise rotation. I always felt this was
> a mistake as it's counterintuitive and suprising to new users, so I
> didn't want to cargo-cult it to a new API. What do people think about it?
>
i am more used to counter-clockwise angle representation just like
zero-indexing, but either way is fine with me.


> See also https://github.com/FFMS/ffms2/issues/317 for flipped samples,
> code,
> and additional discussion.
>
> Missing changelog entry and version bump.
> Vittorio
>
>  libavutil/display.c | 92 ++
> +++
>  libavutil/display.h | 53 ++
>  2 files changed, 145 insertions(+)
>
> diff --git a/libavutil/display.c b/libavutil/display.c
> index f7500948ff..839961ec20 100644
> --- a/libavutil/display.c
> +++ b/libavutil/display.c
> @@ -22,6 +22,7 @@
>  #include 
>  #include 
>
> +#include "avstring.h"
>  #include "display.h"
>  #include "mathematics.h"
>
> @@ -73,3 +74,94 @@ void av_display_matrix_flip(int32_t matrix[9], int
> hflip, int vflip)
>  for (i = 0; i < 9; i++)
>  matrix[i] *= flip[i % 3];
>  }
> +
> +uint32_t av_display_orientation_get(int32_t matrix_src[9])
> +{
> +int32_t matrix[9];
> +uint32_t orientation = 0;
> +int64_t det = (int64_t)matrix_src[0] * matrix_src[4] -
> (int64_t)matrix_src[1] * matrix_src[3];
> +
> +/* Duplicate matrix so that the input one is not modified in case of
> flip. */
> +memcpy(matrix, matrix_src, sizeof(*matrix_src) * 9);
> +
> +if (det < 0) {
> +/* Always assume an horizontal flip for simplicity, it can be
> + * changed later if rotation is 180º. */
> +orientation = AV_FLIP_HORIZONTAL;
> +av_display_matrix_flip(matrix, 1, 0);
> +}
> +
> +if (matrix[1] == (1 << 16) && matrix[3] == -(1 << 16)) {
> +orientation |= AV_ROTATION_90;
> +} else if (matrix[0] == -(1 << 16) && matrix[4] == -(1 << 16)) {
> +if (det < 0)
> +orientation = AV_FLIP_VERTICAL;
> +else
> +orientation |= AV_ROTATION_180;
> +} else if (matrix[1] == -(1 << 16) && matrix[3] == (1 << 16)) {
> +orientation |= AV_ROTATION_270;
> +} else if (matrix[0] == (1 << 16) && matrix[4] == (1 << 16)) {
> +orientation |= AV_IDENTITY;
> +} else {
> +orientation |= AV_ROTATION_CUSTOM;
> +}
> +
> +return orientation;
> +}
> +
> +void av_display_orientation_set(int32_t matrix[9], uint32_t orientation,
> double angle)
> +{
> +int hflip = !!(orientation & AV_FLIP_HORIZONTAL);
> +int vflip = !!(orientation & AV_FLIP_VERTICAL);
> +
> +memset(matrix, 0, sizeof(*matrix) * 9);
> +matrix[8] = 1 << 30;
> +
> +if (orientation & AV_IDENTITY) {
> +matrix[0] = 1 << 16;
> +matrix[4] = 1 << 16;
> +} else if (orientation & AV_ROTATION_90) {
> +matrix[1] = 1 << 16;
> +matrix[3] = -(1 << 16);
> +} else if (orientation & AV_ROTATION_180) {
> +matrix[0] = -(1 << 16);
> +matrix[4] = -(1 << 16);
> +} else if (orientation & AV_ROTATION_270) {
> +matrix[1] = -(1 << 16);
> +matrix[3] = 1 << 16;
> +} else if (orientation & AV_ROTATION_CUSTOM) {
> +av_display_rotation_set(matrix, angle);
> +}
> +
> +av_display_matrix_flip(matrix, hflip, vflip);
> +}
> +
> +void av_display_orientation_name(uint32_t orientation, char *buf, size_t
> buf_size)
> +{
> +if (orientation == 0) {
> +av_strlcpy(buf, "identity", buf_size);
> +return;
> +}
> +
> +if (orientation & AV_ROTATION_90)
> +av_strlcpy(buf, "rotation_90", buf_size);
> +else if (orientation & AV_ROTATION_180)
> +av_strlcpy(buf, "rotation_180", buf_size);
> +else if (orientation & AV_ROTATION_270)
> +av_strlcpy(buf, "rotation_270", buf_size);
> +else if (orientation & AV_ROTATION_CUSTOM)
> +av_strlcpy(buf, "rotation_custom", buf_size);
> +else
> +buf[0] = 

[FFmpeg-devel] [PATCH] lavf/mov.c: Fix timestamps to be strictly monotonic for video also.

2018-04-02 Thread Sasi Inguva
From: Sasi Inguva <is...@isasi.mtv.corp.google.com>

Using same timestamp for multiple packets confuses clients like Ffms2
while seeking to a packet with specific timestamp.

Signed-off-by: Sasi Inguva <is...@isasi.mtv.corp.google.com>
---
 libavformat/mov.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index cb6f3a45de..39d21e6e1c 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3554,7 +3554,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 edit_list_dts_counter -= packet_skip_samples;
 if (edit_list_start_encountered == 0)  {
 edit_list_start_encountered = 1;
-// Make timestamps strictly monotonically increasing 
for audio, by rewriting timestamps for
+// Make timestamps strictly monotonically increasing, 
by rewriting timestamps for
 // discarded packets.
 if (frame_duration_buffer) {
 fix_index_entry_timestamps(st, 
st->nb_index_entries, edit_list_dts_counter,
@@ -3568,7 +3568,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 flags |= AVINDEX_DISCARD_FRAME;
 av_log(mov->fc, AV_LOG_DEBUG, "drop a frame at curr_cts: 
%"PRId64" @ %"PRId64"\n", curr_cts, index);
 
-if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
edit_list_start_encountered == 0) {
+if (edit_list_start_encountered == 0) {
 num_discarded_begin++;
 frame_duration_buffer = 
av_realloc(frame_duration_buffer,
num_discarded_begin 
* sizeof(int64_t));
@@ -3579,7 +3579,8 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 frame_duration_buffer[num_discarded_begin - 1] = 
frame_duration;
 
 // Increment skip_samples for the first non-zero audio 
edit list
-if (first_non_zero_audio_edit > 0 && 
st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+first_non_zero_audio_edit > 0 && 
st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
 st->skip_samples += frame_duration;
 }
 }
@@ -3594,7 +3595,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 edit_list_start_encountered = 1;
 // Make timestamps strictly monotonically increasing for 
audio, by rewriting timestamps for
 // discarded packets.
-if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
frame_duration_buffer) {
+if (frame_duration_buffer) {
 fix_index_entry_timestamps(st, st->nb_index_entries, 
edit_list_dts_counter,
frame_duration_buffer, 
num_discarded_begin);
 av_freep(_duration_buffer);
-- 
2.17.0.rc1.321.gba9d0f2565-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Fix timestamps to be strictly monotonic for video also.

2018-03-29 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@isasi.mtv.corp.google.com>
---
 libavformat/mov.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index cb6f3a45de..6b13742e4d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3568,7 +3568,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 flags |= AVINDEX_DISCARD_FRAME;
 av_log(mov->fc, AV_LOG_DEBUG, "drop a frame at curr_cts: 
%"PRId64" @ %"PRId64"\n", curr_cts, index);
 
-if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
edit_list_start_encountered == 0) {
+if (edit_list_start_encountered == 0) {
 num_discarded_begin++;
 frame_duration_buffer = 
av_realloc(frame_duration_buffer,
num_discarded_begin 
* sizeof(int64_t));
@@ -3579,7 +3579,8 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 frame_duration_buffer[num_discarded_begin - 1] = 
frame_duration;
 
 // Increment skip_samples for the first non-zero audio 
edit list
-if (first_non_zero_audio_edit > 0 && 
st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+first_non_zero_audio_edit > 0 && 
st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
 st->skip_samples += frame_duration;
 }
 }
@@ -3594,7 +3595,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 edit_list_start_encountered = 1;
 // Make timestamps strictly monotonically increasing for 
audio, by rewriting timestamps for
 // discarded packets.
-if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
frame_duration_buffer) {
+if (frame_duration_buffer) {
 fix_index_entry_timestamps(st, st->nb_index_entries, 
edit_list_dts_counter,
frame_duration_buffer, 
num_discarded_begin);
 av_freep(_duration_buffer);
-- 
2.17.0.rc1.321.gba9d0f2565-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [RFC] Exporting virtual timelines as stream side data

2018-03-29 Thread Sasi Inguva
If we can support ffmpeg to parse and display a timeline with multiple
edits correctly, I am ok with deleting that code.

On Thu, Mar 29, 2018 at 6:43 AM, Derek Buitenhuis <
derek.buitenh...@gmail.com> wrote:

> On 3/29/2018 1:06 PM, wm4 wrote:
> > I think mov files at least use a
> > filename/URL for external references, which actually could be handled
> > in generic files.
>
> The dref box is for the whole track, FWIW, and not for edit list entries.
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/utils.c: Don't compute start_time from DISCARD packets for video.

2018-03-23 Thread Sasi Inguva
friendly ping

On Wed, Mar 21, 2018 at 2:55 PM, Michael Niedermayer <michae...@gmx.at>
wrote:

> On Wed, Mar 21, 2018 at 01:35:05PM -0700, Sasi Inguva wrote:
> > Attaching fate sample.
>
> sample uploded
>
> thx
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Take away the freedom of one citizen and you will be jailed, take away
> the freedom of all citizens and you will be congratulated by your peers
> in Parliament.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/utils.c: Don't compute start_time from DISCARD packets for video.

2018-03-21 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@isasi.mtv.corp.google.com>
---
 libavformat/utils.c   |  4 +++-
 tests/fate/mov.mak| 10 +++-
 tests/ref/fate/mov-neg-firstpts-discard   |  3 +++
 .../ref/fate/mov-neg-firstpts-discard-frames  | 24 +++
 4 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 tests/ref/fate/mov-neg-firstpts-discard
 create mode 100644 tests/ref/fate/mov-neg-firstpts-discard-frames

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4d0b56c2a8..f13c8208b1 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1158,7 +1158,9 @@ static void update_initial_timestamps(AVFormatContext *s, 
int stream_index,
 }
 
 if (st->start_time == AV_NOPTS_VALUE) {
-st->start_time = pts;
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || !(pkt->flags & 
AV_PKT_FLAG_DISCARD)) {
+st->start_time = pts;
+}
 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
st->codecpar->sample_rate)
 st->start_time += av_rescale_q(st->skip_samples, (AVRational){1, 
st->codecpar->sample_rate}, st->time_base);
 }
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 64f92e9488..84ca20bb9f 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -13,8 +13,10 @@ FATE_MOV = fate-mov-3elist \
fate-mov-elst-ends-betn-b-and-i \
fate-mov-frag-overlap \
fate-mov-bbi-elst-starts-b \
+  fate-mov-neg-firstpts-discard-frames \
 
-FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
+FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
+   fate-mov-aac-2048-priming \
fate-mov-zombie \
fate-mov-init-nonkeyframe \
fate-mov-displaymatrix \
@@ -72,6 +74,12 @@ fate-mov-frag-overlap: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/frag_overlap.mp4
 # GOP structure : B B I in presentation order.
 fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -acodec aac_fixed 
-i $(TARGET_SAMPLES)/h264/twofields_packet.mp4
 
+# Makes sure that the stream start_time is not negative when the first packet 
is a DISCARD packet with negative timestamp.
+fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream=start_time -bitexact 
$(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov
+
+# Makes sure that expected frames are generated for 
mov_neg_first_pts_discard.mov with -vsync 1
+fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
+
 fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets 
-print_format compact $(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
 fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams 
-show_packets -show_frames -bitexact -print_format compact 
$(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
diff --git a/tests/ref/fate/mov-neg-firstpts-discard 
b/tests/ref/fate/mov-neg-firstpts-discard
new file mode 100644
index 00..7c982d3ffe
--- /dev/null
+++ b/tests/ref/fate/mov-neg-firstpts-discard
@@ -0,0 +1,3 @@
+[STREAM]
+start_time=N/A
+[/STREAM]
diff --git a/tests/ref/fate/mov-neg-firstpts-discard-frames 
b/tests/ref/fate/mov-neg-firstpts-discard-frames
new file mode 100644
index 00..81b59b384b
--- /dev/null
+++ b/tests/ref/fate/mov-neg-firstpts-discard-frames
@@ -0,0 +1,24 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 320x240
+#sar 0: 1/1
+#stream#, dts,pts, duration, size, hash
+0,  0,  0,1,   115200, 1e55263b359b4c99c3463655a1120f11
+0,  1,  1,1,   115200, ce33efea81064e7c23deb57dc4c21995
+0,  2,  2,1,   115200, 42234f25d6191ab13c3676a7937c921b
+0,  3,  3,1,   115200, eab2ccb227c66cba4c9feb8cdbf28ef8
+0,  4,  4,1,   115200, c8816e0b151b2c892163e35086918520
+0,  5,  5,1,   115200, c633f5604c8651165d551ee88fb4cd92
+0,  6,  6,1,   115200, 5f3f8530d720fef3ac4c937e7f488ea7
+0,  7,  7,1,   115200, be24a583909ca92008b642f39be02685
+0,  8,  8,1,   115200, 83872a6e5c3369fe76f684de31bd9a36
+0,  9,  9,1,   115200, 4629d6eb656883b337e8e0b381f2db8d
+0, 10, 10,1,   115200, f6bec55bc026440d23a44b948900e785
+0, 11, 11,1,   115200, 7e12e8113916305c79e5d08354acc9ae
+0, 12, 12,1,   115200, d315c0093536642d340ea50de3b2bfbb
+0, 13, 13,1,   115200, 3d12b24aaed72bfada4a1a3e5e02945a
+0, 14, 14,1,   115200, 070d6b8935c11304d8f9520c4401a130
-- 
2.17.0.rc0.231.g781580f067-goog

__

[FFmpeg-devel] [PATCH] lavf/utils.c: Don't compute start_time from DISCARD packets for video.

2018-03-21 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@isasi.mtv.corp.google.com>
---
 libavformat/utils.c |  4 +++-
 tests/fate/mov.mak  | 10 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4d0b56c2a8..f13c8208b1 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1158,7 +1158,9 @@ static void update_initial_timestamps(AVFormatContext *s, 
int stream_index,
 }
 
 if (st->start_time == AV_NOPTS_VALUE) {
-st->start_time = pts;
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || !(pkt->flags & 
AV_PKT_FLAG_DISCARD)) {
+st->start_time = pts;
+}
 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
st->codecpar->sample_rate)
 st->start_time += av_rescale_q(st->skip_samples, (AVRational){1, 
st->codecpar->sample_rate}, st->time_base);
 }
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 64f92e9488..84ca20bb9f 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -13,8 +13,10 @@ FATE_MOV = fate-mov-3elist \
fate-mov-elst-ends-betn-b-and-i \
fate-mov-frag-overlap \
fate-mov-bbi-elst-starts-b \
+  fate-mov-neg-firstpts-discard-frames \
 
-FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
+FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
+   fate-mov-aac-2048-priming \
fate-mov-zombie \
fate-mov-init-nonkeyframe \
fate-mov-displaymatrix \
@@ -72,6 +74,12 @@ fate-mov-frag-overlap: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/frag_overlap.mp4
 # GOP structure : B B I in presentation order.
 fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -acodec aac_fixed 
-i $(TARGET_SAMPLES)/h264/twofields_packet.mp4
 
+# Makes sure that the stream start_time is not negative when the first packet 
is a DISCARD packet with negative timestamp.
+fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream=start_time -bitexact 
$(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov
+
+# Makes sure that expected frames are generated for 
mov_neg_first_pts_discard.mov with -vsync 1
+fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
+
 fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets 
-print_format compact $(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
 fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams 
-show_packets -show_frames -bitexact -print_format compact 
$(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
-- 
2.17.0.rc0.231.g781580f067-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/utils.c: Don't compute start_time from DISCARD packets for video.

2018-03-21 Thread Sasi Inguva
Attaching fate sample.

On Wed, Mar 21, 2018 at 1:33 PM, Sasi Inguva <is...@google.com> wrote:

> Signed-off-by: Sasi Inguva <is...@isasi.mtv.corp.google.com>
> ---
>  libavformat/utils.c |  4 +++-
>  tests/fate/mov.mak  | 10 +-
>  2 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 4d0b56c2a8..f13c8208b1 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -1158,7 +1158,9 @@ static void update_initial_timestamps(AVFormatContext
> *s, int stream_index,
>  }
>
>  if (st->start_time == AV_NOPTS_VALUE) {
> -st->start_time = pts;
> +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ||
> !(pkt->flags & AV_PKT_FLAG_DISCARD)) {
> +st->start_time = pts;
> +}
>  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
> st->codecpar->sample_rate)
>  st->start_time += av_rescale_q(st->skip_samples,
> (AVRational){1, st->codecpar->sample_rate}, st->time_base);
>  }
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 64f92e9488..84ca20bb9f 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -13,8 +13,10 @@ FATE_MOV = fate-mov-3elist \
> fate-mov-elst-ends-betn-b-and-i \
> fate-mov-frag-overlap \
> fate-mov-bbi-elst-starts-b \
> +  fate-mov-neg-firstpts-discard-frames \
>
> -FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
> +FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
> +   fate-mov-aac-2048-priming \
> fate-mov-zombie \
> fate-mov-init-nonkeyframe \
> fate-mov-displaymatrix \
> @@ -72,6 +74,12 @@ fate-mov-frag-overlap: CMD = framemd5 -i
> $(TARGET_SAMPLES)/mov/frag_overlap.mp4
>  # GOP structure : B B I in presentation order.
>  fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -acodec
> aac_fixed -i $(TARGET_SAMPLES)/h264/twofields_packet.mp4
>
> +# Makes sure that the stream start_time is not negative when the first
> packet is a DISCARD packet with negative timestamp.
> +fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF)
> -show_entries stream=start_time -bitexact $(TARGET_SAMPLES)/mov/mov_neg_
> first_pts_discard.mov
> +
> +# Makes sure that expected frames are generated for
> mov_neg_first_pts_discard.mov with -vsync 1
> +fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact -i
> $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
> +
>  fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF)
> -show_packets -print_format compact $(TARGET_SAMPLES)/mov/aac-
> 2048-priming.mov
>
>  fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams
> -show_packets -show_frames -bitexact -print_format compact
> $(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
> --
> 2.17.0.rc0.231.g781580f067-goog
>
>


mov_neg_first_pts_discard.mov
Description: QuickTime movie
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/utils.c: Don't compute start_time from DISCARD packets for video.

2018-03-21 Thread Sasi Inguva
Sorry, forgot to add the test reference files. Sending the revised patch.

On Wed, Mar 21, 2018 at 1:35 PM, Sasi Inguva <is...@google.com> wrote:

> Attaching fate sample.
>
> On Wed, Mar 21, 2018 at 1:33 PM, Sasi Inguva <is...@google.com> wrote:
>
>> Signed-off-by: Sasi Inguva <is...@isasi.mtv.corp.google.com>
>> ---
>>  libavformat/utils.c |  4 +++-
>>  tests/fate/mov.mak  | 10 +-
>>  2 files changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/utils.c b/libavformat/utils.c
>> index 4d0b56c2a8..f13c8208b1 100644
>> --- a/libavformat/utils.c
>> +++ b/libavformat/utils.c
>> @@ -1158,7 +1158,9 @@ static void update_initial_timestamps(AVFormatContext
>> *s, int stream_index,
>>  }
>>
>>  if (st->start_time == AV_NOPTS_VALUE) {
>> -st->start_time = pts;
>> +if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ||
>> !(pkt->flags & AV_PKT_FLAG_DISCARD)) {
>> +st->start_time = pts;
>> +}
>>  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
>> st->codecpar->sample_rate)
>>  st->start_time += av_rescale_q(st->skip_samples,
>> (AVRational){1, st->codecpar->sample_rate}, st->time_base);
>>  }
>> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
>> index 64f92e9488..84ca20bb9f 100644
>> --- a/tests/fate/mov.mak
>> +++ b/tests/fate/mov.mak
>> @@ -13,8 +13,10 @@ FATE_MOV = fate-mov-3elist \
>> fate-mov-elst-ends-betn-b-and-i \
>> fate-mov-frag-overlap \
>> fate-mov-bbi-elst-starts-b \
>> +  fate-mov-neg-firstpts-discard-frames \
>>
>> -FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
>> +FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
>> +   fate-mov-aac-2048-priming \
>> fate-mov-zombie \
>> fate-mov-init-nonkeyframe \
>> fate-mov-displaymatrix \
>> @@ -72,6 +74,12 @@ fate-mov-frag-overlap: CMD = framemd5 -i
>> $(TARGET_SAMPLES)/mov/frag_overlap.mp4
>>  # GOP structure : B B I in presentation order.
>>  fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -acodec
>> aac_fixed -i $(TARGET_SAMPLES)/h264/twofields_packet.mp4
>>
>> +# Makes sure that the stream start_time is not negative when the first
>> packet is a DISCARD packet with negative timestamp.
>> +fate-mov-neg-firstpts-discard: CMD = run ffprobe$(PROGSSUF)$(EXESUF)
>> -show_entries stream=start_time -bitexact $(TARGET_SAMPLES)/mov/mov_neg_
>> first_pts_discard.mov
>> +
>> +# Makes sure that expected frames are generated for
>> mov_neg_first_pts_discard.mov with -vsync 1
>> +fate-mov-neg-firstpts-discard-frames: CMD = framemd5 -flags +bitexact
>> -i $(TARGET_SAMPLES)/mov/mov_neg_first_pts_discard.mov -vsync 1
>> +
>>  fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF)
>> -show_packets -print_format compact $(TARGET_SAMPLES)/mov/aac-2048
>> -priming.mov
>>
>>  fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams
>> -show_packets -show_frames -bitexact -print_format compact
>> $(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
>> --
>> 2.17.0.rc0.231.g781580f067-goog
>>
>>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Use the correct offset to shift timestamp when seeking.

2018-03-09 Thread Sasi Inguva
Fixes seek for files with empty edits and files with negative ctts
(dts_shift > 0). Added fate samples and tests.

Signed-off-by: Sasi Inguva <is...@isasi.mtv.corp.google.com>
---
 libavformat/isom.h   |   1 +
 libavformat/mov.c|  27 +++--
 tests/fate/seek.mak  |   6 +
 tests/ref/seek/empty-edit-mp4| 134 +++
 tests/ref/seek/test-iibbibb-mp4  | 122 +
 tests/ref/seek/test-iibbibb-neg-ctts-mp4 | 122 +
 6 files changed, 401 insertions(+), 11 deletions(-)
 create mode 100644 tests/ref/seek/empty-edit-mp4
 create mode 100644 tests/ref/seek/test-iibbibb-mp4
 create mode 100644 tests/ref/seek/test-iibbibb-neg-ctts-mp4

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 65676fb0f5..4da34142f0 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -168,6 +168,7 @@ typedef struct MOVStreamContext {
 int *keyframes;
 int time_scale;
 int64_t time_offset;  ///< time offset of the edit list entries
+int64_t min_corrected_pts;  ///< minimum Composition time shown by the 
edits excluding empty edits.
 int current_sample;
 int64_t current_index;
 MOVIndexRange* index_ranges;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 95b9cd3f8b..cfc51482b0 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3378,7 +3378,6 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int64_t edit_list_start_ctts_sample = 0;
 int64_t curr_cts;
 int64_t curr_ctts = 0;
-int64_t min_corrected_pts = -1;
 int64_t empty_edits_sum_duration = 0;
 int64_t edit_list_index = 0;
 int64_t index;
@@ -3419,6 +3418,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 msc->ctts_sample = 0;
 msc->ctts_allocated_size = 0;
 
+// Reinitialize min_corrected_pts so that it can be computed again.
+msc->min_corrected_pts = -1;
+
 // If the dts_shift is positive (in case of negative ctts values in mov),
 // then negate the DTS by dts_shift
 if (msc->dts_shift > 0) {
@@ -3563,10 +3565,10 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 }
 } else {
-if (min_corrected_pts < 0) {
-min_corrected_pts = edit_list_dts_counter + curr_ctts + 
msc->dts_shift;
+if (msc->min_corrected_pts < 0) {
+msc->min_corrected_pts = edit_list_dts_counter + curr_ctts 
+ msc->dts_shift;
 } else {
-min_corrected_pts = FFMIN(min_corrected_pts, 
edit_list_dts_counter + curr_ctts + msc->dts_shift);
+msc->min_corrected_pts = FFMIN(msc->min_corrected_pts, 
edit_list_dts_counter + curr_ctts + msc->dts_shift);
 }
 if (edit_list_start_encountered == 0) {
 edit_list_start_encountered = 1;
@@ -3625,16 +3627,16 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 }
 }
-// If there are empty edits, then min_corrected_pts might be positive 
intentionally. So we subtract the
-// sum duration of emtpy edits here.
-min_corrected_pts -= empty_edits_sum_duration;
+// If there are empty edits, then msc->min_corrected_pts might be positive
+// intentionally. So we subtract the sum duration of emtpy edits here.
+msc->min_corrected_pts -= empty_edits_sum_duration;
 
 // If the minimum pts turns out to be greater than zero after fixing the 
index, then we subtract the
 // dts by that amount to make the first pts zero.
-if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && min_corrected_pts > 
0) {
-av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first 
pts zero.\n", min_corrected_pts);
+if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && 
msc->min_corrected_pts > 0) {
+av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by %"PRId64" to make first 
pts zero.\n", msc->min_corrected_pts);
 for (i = 0; i < st->nb_index_entries; ++i) {
-st->index_entries[i].timestamp -= min_corrected_pts;
+st->index_entries[i].timestamp -= msc->min_corrected_pts;
 }
 }
 
@@ -3697,6 +3699,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 if (empty_duration)
 empty_duration = av_rescale(empty_duration, sc->time_scale, 
mov->time_scale);
 sc->time_offset = start_time - empty_duration;
+sc->min_corrected_pts = start_time;
 if (!mov->advanced_editlist)
 current_dts = -sc->time_offset;
 }
@@ -7158,7 +7161,9 @@ static int mov_seek_stream(AVFormatContext *s, AVStream 
*st, int64_t timestamp,
 int sample, time_sample

Re: [FFmpeg-devel] [PATCH] libavformat/mov.c: use calculated dts offset when seeking in streams

2018-03-09 Thread Sasi Inguva
Seek on files with empty edit lists is failing with this patch. For a file
with empty edit of 1s. (media time: -1 , duration : 1 ) , both DTS and PTS
start at 1s.  Also sc->time_offset is computed as   -1s.  Hence when we
seek to timestamp t, it will actually seek to timestamp t+1 , which is
wrong because there is no offset between DTS and PTS in this case .

The offset by which to shift timestamp, can be computed more accurately.
I'll send a patch to fix this.


On Wed, Mar 7, 2018 at 3:27 AM, Michael Niedermayer <mich...@niedermayer.cc>
wrote:

> On Mon, Mar 05, 2018 at 03:53:04PM -0800, Sasi Inguva wrote:
> > This patch seems to be doing the wrong thing and breaking seek tests for
> us.
> >
> > As far as I understand , seeking for most containers is based on
> "decoding
> > timestamp". Unless  AV_SEEK_TO_PTS flag is specified in container, which
> is
> > not for most containers and MOV.  So if PTS and DTS are like such,
>
> I think most seeking in libavformat uses whatever was convenient for the
> implementation of each demuxer. Some are much more carefully implemented
> than others. Iam not so sure its consistently DTS when AVFMT_SEEK_TO_PTS
> is not set.
>
>
> > Pts  Dts
> >  0  -2   : frame0
> >  1  -1   : frame1
> >  2   0   : frame2
> >  3   1   : frame3
> > ...
> > Seeking  to "0" timestamp without any flags, I should expect frame2 . But
> > instead this patch will give me frame0 . The patch's intention seems to
> be
> > seeking based on PTS (subtracting by the sc->time_offset essentially is a
> > mapping from PTS to DTS) .
>
> IMO, seeking per PTS is more usefull to end users, the user gets what he
> asked
> for, a frame that he can display at that requested time.
> The ultimate goal should be to have proper frame exact seeking or as close
> to
> it as practically implementable.
>
> DTS is sometimes easier to implement on our side.
> But with seeking per DTS it is a heuristic gamble on how to get a frame to
> display at a specific timestamp. Its possible with seek per dts to never
> get a frame displayable at the time requested.
>
> For formats with a full index like mov/mp4 seeking per pts should be IMHO
> be
> preferred over dts.
>
> I agree. But the index in MOV (st->index_entries) is  based on DTS . Exact
seek based on PTS will be hard to implement.  Just subtracting a fixed
offset does not suffice to map PTS to DTS ( especially when there are B
frames) .  To seek to the correct frame , apart from doing
av_index_search_timestamp , we would have to go back and formulate the PTS
using CTTS and search in the neighborhood for correct PTS.

There are more corner cases that require mentioning, like for example that
> there
> can be a B frame after a I frame with a pts prior to the I frame.
> as in
>
> coded order:
> Pts Dts
> 1  -1   I frame
> 0   0   B frame
> 3   1   P frame
> 2   2   B frame
> It is desirable and valid to seek to the I frame at pts=1 for a seek
> targeting
> the B frame  at pts=0 if and only if this B frame can be displayed and
> does not depend on a frame of the prior GOP (streams generally have flags
> in their headers for this specific case to be detectable)
>
> Furthermore, if the goal is to seek to pts=5 and there is a keyframe at
> pts=5
> and one at pts=4. And there is another stream that can only be decoded at
> pts=5
> if demuxing starts at pts=4 then the demuxer can seek to pts=4 instead of
> 5.
> This is especially the case for containers with subtitles where their
> display may require positioning at a earlier place and then potentially
> discarding packets in streams that are unneeded.
>
> also avformat_seek_file() allows much more flexibility for the user to
> specify
> where and how to seek. And where the av_seek_frame() API does not specify
> what timestamp is used. avformat_seek_file() does specify that
> "can be presented successfully" and can thus not be just DTS
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> It is what and why we do it that matters, not just one of them.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavformat/mov.c: use calculated dts offset when seeking in streams

2018-03-05 Thread Sasi Inguva
This patch seems to be doing the wrong thing and breaking seek tests for us.

As far as I understand , seeking for most containers is based on "decoding
timestamp". Unless  AV_SEEK_TO_PTS flag is specified in container, which is
not for most containers and MOV.  So if PTS and DTS are like such,
Pts  Dts
 0  -2   : frame0
 1  -1   : frame1
 2   0   : frame2
 3   1   : frame3
...
Seeking  to "0" timestamp without any flags, I should expect frame2 . But
instead this patch will give me frame0 . The patch's intention seems to be
seeking based on PTS (subtracting by the sc->time_offset essentially is a
mapping from PTS to DTS) .

To fix your specific issue https://trac.ffmpeg.org/ticket/6139

,
you can use AV_SEEK_BACKWARD flag while seeking in seek_to_start
http://git.videolan.org/?p=ffmpeg.git;a=blob;f=fftools/ffmpeg.c;h=ee7258fcd1f65b6670f19686b51d5b41ee72f7ac;hb=HEAD#l4165


On Sun, Oct 29, 2017 at 4:11 AM, Peter Große  wrote:

> From: Jonas Licht 
>
> Subtract the calculated dts offset from the requested timestamp before
> seeking. This fixes an error "Error while filtering: Operation not
> permitted" observed with a short file which contains only one key frame
> and starts with negative timestamps.
>
> Then, av_index_search_timestamp() returns a valid negative timestamp,
> but mov_seek_stream bails out with AVERROR_INVALIDDATA.
>
> Fixes ticket #6139.
>
> Signed-off-by: Jonas Licht 
> Signed-off-by: Peter Große 
> ---
>
> Compared to the other seek results in this test, the values are not
> that far off.
>
>  libavformat/mov.c|  6 --
>  tests/ref/seek/extra-mp4 | 16 
>  2 files changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 2ee67561e4..60a0f4ccf4 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -6882,10 +6882,12 @@ static int mov_seek_fragment(AVFormatContext *s,
> AVStream *st, int64_t timestamp
>  static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t
> timestamp, int flags)
>  {
>  MOVStreamContext *sc = st->priv_data;
> -int sample, time_sample;
> +int sample, time_sample, ret;
>  unsigned int i;
>
> -int ret = mov_seek_fragment(s, st, timestamp);
> +timestamp -= sc->time_offset;
> +
> +ret = mov_seek_fragment(s, st, timestamp);
>  if (ret < 0)
>  return ret;
>
> diff --git a/tests/ref/seek/extra-mp4 b/tests/ref/seek/extra-mp4
> index c25544c095..c17ce4003c 100644
> --- a/tests/ref/seek/extra-mp4
> +++ b/tests/ref/seek/extra-mp4
> @@ -28,10 +28,10 @@ ret: 0 st: 0 flags:0 dts: 50.63 pts:
> 50.73 pos:5926157 size:  13
>  ret: 0 st: 0 flags:0 dts: 50.67 pts: 50.67 pos:5927464
> size:   150
>  ret: 0 st: 0 flags:0 dts: 50.70 pts: 50.70 pos:5927614
> size:   176
>  ret: 0 st:-1 flags:1  ts: 153.470835
> -ret: 0 st: 0 flags:1 dts: 153.47 pts: 153.50 pos:15867700
> size: 96169
> -ret: 0 st: 0 flags:0 dts: 153.50 pts: 153.53 pos:15963869
> size:   785
> -ret: 0 st: 0 flags:0 dts: 153.53 pts: 153.63 pos:15964654
> size:  3135
> -ret: 0 st: 0 flags:0 dts: 153.57 pts: 153.57 pos:15967789
> size:   859
> +ret: 0 st: 0 flags:1 dts: 151.97 pts: 152.00 pos:15705355
> size:146924
> +ret: 0 st: 0 flags:0 dts: 152.00 pts: 152.10 pos:15852279
> size:  1355
> +ret: 0 st: 0 flags:0 dts: 152.03 pts: 152.03 pos:15853634
> size:   211
> +ret: 0 st: 0 flags:0 dts: 152.07 pts: 152.07 pos:15853845
> size:   217
>  ret: 0 st: 0 flags:0  ts: 76.365000
>  ret: 0 st: 0 flags:1 dts: 77.83 pts: 77.87 pos:8659657
> size: 41182
>  ret: 0 st: 0 flags:0 dts: 77.87 pts: 77.97 pos:8700839
> size:  4197
> @@ -83,10 +83,10 @@ ret: 0 st: 0 flags:0 dts: 101.33 pts:
> 101.43 pos:11049548 size:
>  ret: 0 st: 0 flags:0 dts: 101.37 pts: 101.37 pos:11053072
> size:   562
>  ret: 0 st: 0 flags:0 dts: 101.40 pts: 101.40 pos:11053634
> size:   599
>  ret: 0 st:-1 flags:0  ts: 25.306672
> -ret: 0 st: 0 flags:1 dts: 27.40 pts: 27.43 pos:2674605
> size:127383
> -ret: 0 st: 0 flags:0 dts: 27.43 pts: 27.47 pos:2801988
> size:68
> -ret: 0 st: 0 flags:0 dts: 27.47 pts: 27.50 pos:2802268
> size:  1754
> -ret: 0 st: 0 flags:0 dts: 27.50 pts: 27.53 pos:2804022
> size:  4071
> +ret: 0 st: 0 flags:1 dts: 25.30 pts: 25.33 pos:2607246
> size: 40273
> +ret: 0 st: 0 flags:0 dts: 25.33 pts: 25.43 pos:2647519
> size:  2959
> +ret: 0 st: 0 flags:0 dts: 25.37 pts: 25.37 pos:2650478
> size:   197
> +ret: 0 st: 0 flags:0 dts: 

Re: [FFmpeg-devel] [PATCH 5/6] lavf/mov: fix disposable flags in mov_fix_index

2018-02-12 Thread Sasi Inguva
This will increase memory requirement, since we are storing one CTTS for
each sample. Please see my comments on your previous patch.

On Sun, Nov 19, 2017 at 1:00 PM, John Stebbins 
wrote:

> Merges ctts_data into mov_index_entries.  This allows a considerable
> amount of code simplification.
> ---
>  libavformat/isom.h |   1 +
>  libavformat/mov.c  | 254 +++---
> ---
>  2 files changed, 93 insertions(+), 162 deletions(-)
>
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index 646b31ccc7..8fee8f4f53 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -138,6 +138,7 @@ typedef struct MOVIndexRange {
>  } MOVIndexRange;
>
>  typedef struct MOVIndexEntry {
> +int ctts;
>  #define MOVINDEX_DISPOSABLE 0x01
>  int8_t  flags;
>  } MOVIndexEntry;
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index b064708ced..d1284a2d43 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -74,8 +74,7 @@ typedef struct MOVParseTableEntry {
>
>  static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
>  static int mov_read_mfra(MOVContext *c, AVIOContext *f);
> -static int64_t add_ctts_entry(MOVStts** ctts_data, unsigned int*
> ctts_count, unsigned int* allocated_size,
> -  int count, int duration);
> +static int64_t add_ctts_entry(MOVStreamContext *sc, int ctts, uint8_t
> flags);
>
>  static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext
> *pb,
>   unsigned len, const char
> *key)
> @@ -2930,7 +2929,7 @@ static int mov_read_ctts(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
>  {
>  AVStream *st;
>  MOVStreamContext *sc;
> -unsigned int i, j, entries, ctts_count = 0;
> +unsigned int i, j, entries;
>
>  if (c->fc->nb_streams < 1)
>  return 0;
> @@ -2945,11 +2944,12 @@ static int mov_read_ctts(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
>
>  if (!entries)
>  return 0;
> -if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
> +if (entries >= UINT_MAX / sizeof(*sc->mov_index_entries))
>  return AVERROR_INVALIDDATA;
> -av_freep(>ctts_data);
> -sc->ctts_data = av_fast_realloc(NULL, >ctts_allocated_size,
> entries * sizeof(*sc->ctts_data));
> -if (!sc->ctts_data)
> +av_freep(>mov_index_entries);
> +sc->mov_index_entries = av_fast_realloc(NULL,
> >mov_index_allocated_size,
> +entries *
> sizeof(*sc->mov_index_entries));
> +if (!sc->mov_index_entries)
>  return AVERROR(ENOMEM);
>
>  for (i = 0; i < entries && !pb->eof_reached; i++) {
> @@ -2965,15 +2965,15 @@ static int mov_read_ctts(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
>
>  /* Expand entries such that we have a 1-1 mapping with samples. */
>  for (j = 0; j < count; j++)
> -add_ctts_entry(>ctts_data, _count,
> >ctts_allocated_size, 1, duration);
> +add_ctts_entry(sc, duration, 0);
>
>  av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",
>  count, duration);
>
>  if (FFNABS(duration) < -(1<<28) && i+2  av_log(c->fc, AV_LOG_WARNING, "CTTS invalid\n");
> -av_freep(>ctts_data);
> -sc->ctts_count = 0;
> +av_freep(>mov_index_entries);
> +sc->nb_mov_index_entries = 0;
>  return 0;
>  }
>
> @@ -2981,8 +2981,6 @@ static int mov_read_ctts(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
>  mov_update_dts_shift(sc, duration);
>  }
>
> -sc->ctts_count = ctts_count;
> -
>  if (pb->eof_reached)
>  return AVERROR_EOF;
>
> @@ -3063,9 +3061,9 @@ static int get_edit_list_entry(MOVContext *mov,
>   * Find the closest previous frame to the timestamp_pts, in e_old index
>   * entries. Searching for just any frame / just key frames can be
> controlled by
>   * last argument 'flag'.
> - * Note that if ctts_data is not NULL, we will always search for a key
> frame
> - * irrespective of the value of 'flag'. If we don't find any keyframe, we
> will
> - * return the first frame of the video.
> + * Note that if mov_index_entries is not NULL, we will always search for a
> + * key frame irrespective of the value of 'flag'. If we don't find any
> + * keyframe, we will return the first frame of the video.
>   *
>   * Here the timestamp_pts is considered to be a presentation timestamp and
>   * the timestamp of index entries are considered to be decoding
> timestamps.
> @@ -3073,27 +3071,23 @@ static int get_edit_list_entry(MOVContext *mov,
>   * Returns 0 if successful in finding a frame, else returns -1.
>   * Places the found index corresponding output arg.
>   *
> - * If ctts_old is not NULL, then refines the searched entry by searching
> - * backwards from the found timestamp, to find the frame with correct PTS.
> - *
> - * Places the found ctts_index 

Re: [FFmpeg-devel] [PATCH 4/6] lavf/mov: set AV_PKT_FLAG_DISPOSABLE from sdtp box

2018-02-12 Thread Sasi Inguva
On Sun, Nov 19, 2017 at 12:46 PM, John Stebbins 
wrote:

> ---
>  libavformat/isom.h  | 10 ++
>  libavformat/mov.c   | 92 ++
> ---
>  libavformat/utils.c |  3 +-
>  3 files changed, 99 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index 65676fb0f5..646b31ccc7 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -137,11 +137,19 @@ typedef struct MOVIndexRange {
>  int64_t end;
>  } MOVIndexRange;
>
> +typedef struct MOVIndexEntry {
> +#define MOVINDEX_DISPOSABLE 0x01
> +int8_t  flags;
> +} MOVIndexEntry;
> +
>  typedef struct MOVStreamContext {
>  AVIOContext *pb;
>  int pb_is_copied;
>  int ffindex;  ///< AVStream index
>  int next_chunk;
> +MOVIndexEntry * mov_index_entries;
> +int nb_mov_index_entries;
> +unsigned int mov_index_allocated_size;
>  unsigned int chunk_count;
>  int64_t *chunk_offsets;
>  unsigned int stts_count;
> @@ -166,6 +174,8 @@ typedef struct MOVStreamContext {
>  int keyframe_absent;
>  unsigned int keyframe_count;
>  int *keyframes;
> +unsigned int frame_deps_count;
> +int *frame_deps;
>
should this be uint8_t ?
Also this will increase the memory requirement quite a bit, since we are
storing for 2 int's for every sample . If we are doing this only to find
the disposable samples then, can we just store the sample indices of the
samples which are disposable while parsing sdtp instead of having one entry
for each sample.

>  int time_scale;
>  int64_t time_offset;  ///< time offset of the edit list entries
>  int current_sample;
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 5c9f926bce..b064708ced 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -2680,6 +2680,43 @@ static int mov_read_stps(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
>  return 0;
>  }
>
> +static int mov_read_sdtp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> +{
> +AVStream *st;
> +MOVStreamContext *sc;
> +unsigned int i, entries;
> +
> +if (c->fc->nb_streams < 1)
> +return 0;
> +st = c->fc->streams[c->fc->nb_streams-1];
> +sc = st->priv_data;
> +
> +if (atom.size < 8)
> +return 0;
> +
> +avio_r8(pb); /* version */
> +avio_rb24(pb); /* flags */
> +
> +entries = atom.size - 4;
> +sc->frame_deps_count = 0;
> +sc->frame_deps = av_malloc_array(entries, sizeof(*sc->frame_deps));
> +
> +if (!sc->frame_deps)
> +return AVERROR(ENOMEM);
> +
> +for (i = 0; i < entries && !pb->eof_reached; i++) {
> +sc->frame_deps[i] = avio_r8(pb);
> +}
> +
> +sc->frame_deps_count = i;
> +
> +if (pb->eof_reached)
> +return AVERROR_EOF;
> +
> +
> +return 0;
> +}
> +
>  static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>  {
>  AVStream *st;
> @@ -3635,15 +3672,40 @@ static void mov_build_index(MOVContext *mov,
> AVStream *st)
>
>  if (!sc->sample_count || st->nb_index_entries)
>  return;
> -if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) -
> st->nb_index_entries)
> +if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries))
>  return;
> -if (av_reallocp_array(>index_entries,
> -  st->nb_index_entries + sc->sample_count,
> +if (av_reallocp_array(>index_entries, sc->sample_count,
>sizeof(*st->index_entries)) < 0) {
>  st->nb_index_entries = 0;
>  return;
>  }
> -st->index_entries_allocated_size = (st->nb_index_entries +
> sc->sample_count) * sizeof(*st->index_entries);
> +st->index_entries_allocated_size = sc->sample_count *
> +   sizeof(*st->index_entries);
> +
> +// realloc mov_index_entries if needed for frame dependencies
> +// or if it already exists for ctts
> +if (sc->frame_deps || sc->mov_index_entries) {
> +// make mov_index_entries the same number of entries as
> +// index_entries
> +if (av_reallocp_array(>mov_index_entries,
> +  sc->sample_count,
> +  sizeof(*sc->mov_index_entries)) < 0) {
> +sc->nb_mov_index_entries = 0;
> +return;
> +}
> +sc->mov_index_allocated_size = sc->sample_count *
> +   sizeof(*sc->mov_index_
> entries);
> +
> +if (sc->sample_count > sc->nb_mov_index_entries)
> +// In case there were samples without ctts entries,
> ensure they
> +// get zero valued entries. This ensures clips which mix
> boxes
> +// with and without ctts entries don't pickup
> uninitialized
> +// data.
> +

Re: [FFmpeg-devel] Fix ctts_index calculation

2018-02-09 Thread Sasi Inguva
The new patch looks good to me.

On Fri, Feb 9, 2018 at 1:34 PM, Xiaohan Wang (王消寒) <xhw...@chromium.org>
wrote:

> I uploaded a new patch. Is this what you meant?
>
> I am confused with the code though. In the case *ctts_index == ctts_count,
> this while loop will do nothing. Is this what we want? Also, the "wrong"
> |ctts_index| will be available outside of this function. How do we make
> sure it won't cause trouble later?
>
> On Fri, Feb 9, 2018 at 12:26 PM, Sasi Inguva <isasi-at-google.com@ffmpeg.
> org
> > wrote:
>
> > >
> > > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > > index 5adba52e08..f0bd3e3623 100644
> > > --- a/libavformat/mov.c
> > > +++ b/libavformat/mov.c
> > > @@ -3148,7 +3148,7 @@ static int find_prev_closest_index(AVStream *st,
> > >  *ctts_index = 0;
> > >  *ctts_sample = 0;
> > >  for (index_ctts_count = 0; index_ctts_count < *index;
> > > index_ctts_count++) {
> > > -if (*ctts_index < ctts_count) {
> >
> > +if (*ctts_index < ctts_count - 1) {
> > >
> > If you do this, then we are skipping, looking at ctts_samples in the last
> > ctts entry where (*ctts_index == ctts_count -1), which is not desired.
> >
> >  (*ctts_sample)++;
> > >  if (ctts_data[*ctts_index].count == *ctts_sample) {
> > >  (*ctts_index)++;
> > >
> >
> > Here *ctts_index == ctts_count  only iff   the *ctts_index is the last
> CTTS
> > entry, and we still didn't reach   *index. That means that it's file with
> > CTTS truncated i.e. no corresponding CTTS entries for some STTS entries.
> > This issue can be fixed by checking for  *ctts_index <  ctts_count, in
> the
> > line after this loop.
> > while (*index
> > <https://cs.corp.google.com/piper///depot/google3/third_
> > party/ffmpeg/next/libavformat/mov.c?l=3123=xref_jump_to_
> > def=index=184932376>
> > >= 0 && (*ctts_index
> > <https://cs.corp.google.com/piper///depot/google3/third_
> > party/ffmpeg/next/libavformat/mov.c?l=3124=xref_jump_to_
> > def=ctts_index=184932376>)
> > >= 0) {
> > we already check for (*ctts_index) >=0 so we can check for the upper
> bound
> > too.
> >
> > On Sat, Feb 3, 2018 at 12:36 PM, Michael Niedermayer
> > <mich...@niedermayer.cc
> > > wrote:
> >
> > > On Fri, Feb 02, 2018 at 05:55:38PM -0800, Xiaohan Wang (王消寒) wrote:
> > > >
> > >
> > > >  mov.c |2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 87157b4053de0e044e78db72ef13e8058075c235
> > 0001-Fix-ctts_index-calculatio
> > > n.patch
> > > > From bb376fd2de5da5f9ecdef41621a579252b899d7d Mon Sep 17 00:00:00
> 2001
> > > > From: Xiaohan Wang <xhw...@chromium.org>
> > > > Date: Fri, 2 Feb 2018 17:33:56 -0800
> > > > Subject: [PATCH] Fix ctts_index calculation
> > > >
> > > > An index should never be equal to the count. Hence we must make sure
> > > > *ctts_index < ctts_count.
> > > > ---
> > > >  libavformat/mov.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > should be reviewed by sasi idealy, he wrote this
> > >
> > > thx
> > >
> > >
> > > [...]
> > >
> > > --
> > > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC7
> 87040B0FAB
> > >
> > > Democracy is the form of government in which you can choose your
> dictator
> > >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Fix ctts_index calculation

2018-02-09 Thread Sasi Inguva
On Fri, Feb 9, 2018 at 1:34 PM, Xiaohan Wang (王消寒) <xhw...@chromium.org>
wrote:

> I uploaded a new patch. Is this what you meant?
>
> I am confused with the code though. In the case *ctts_index == ctts_count,
>
The problem is when *ctts_index == (ctts_count -1) .
 if ( (ctts_count- 1) < ctts_count) {
while ( ctts_sample <   ctts_data[ctts_count - 1].count ) {
  increment(ctts_sample )
}
}

But if you check   for  (ctts_count - 1) <  (ctts_count -1) , the above
iterations won't take place.

> this while loop will do nothing. Is this what we want? Also, the "wrong"
> |ctts_index| will be available outside of this function. How do we make
> sure it won't cause trouble later?
>
> On Fri, Feb 9, 2018 at 12:26 PM, Sasi Inguva <isasi-at-google.com@ffmpeg.
> org
> > wrote:
>
> > >
> > > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > > index 5adba52e08..f0bd3e3623 100644
> > > --- a/libavformat/mov.c
> > > +++ b/libavformat/mov.c
> > > @@ -3148,7 +3148,7 @@ static int find_prev_closest_index(AVStream *st,
> > >  *ctts_index = 0;
> > >  *ctts_sample = 0;
> > >  for (index_ctts_count = 0; index_ctts_count < *index;
> > > index_ctts_count++) {
> > > -if (*ctts_index < ctts_count) {
> >
> > +if (*ctts_index < ctts_count - 1) {
> > >
> > If you do this, then we are skipping, looking at ctts_samples in the last
> > ctts entry where (*ctts_index == ctts_count -1), which is not desired.
> >
> >  (*ctts_sample)++;
> > >  if (ctts_data[*ctts_index].count == *ctts_sample) {
> > >  (*ctts_index)++;
> > >
> >
> > Here *ctts_index == ctts_count  only iff   the *ctts_index is the last
> CTTS
> > entry, and we still didn't reach   *index. That means that it's file with
> > CTTS truncated i.e. no corresponding CTTS entries for some STTS entries.
> > This issue can be fixed by checking for  *ctts_index <  ctts_count, in
> the
> > line after this loop.
> > while (*index
> > <https://cs.corp.google.com/piper///depot/google3/third_
> > party/ffmpeg/next/libavformat/mov.c?l=3123=xref_jump_to_
> > def=index=184932376>
> > >= 0 && (*ctts_index
> > <https://cs.corp.google.com/piper///depot/google3/third_
> > party/ffmpeg/next/libavformat/mov.c?l=3124=xref_jump_to_
> > def=ctts_index=184932376>)
> > >= 0) {
> > we already check for (*ctts_index) >=0 so we can check for the upper
> bound
> > too.
> >
> > On Sat, Feb 3, 2018 at 12:36 PM, Michael Niedermayer
> > <mich...@niedermayer.cc
> > > wrote:
> >
> > > On Fri, Feb 02, 2018 at 05:55:38PM -0800, Xiaohan Wang (王消寒) wrote:
> > > >
> > >
> > > >  mov.c |2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 87157b4053de0e044e78db72ef13e8058075c235
> > 0001-Fix-ctts_index-calculatio
> > > n.patch
> > > > From bb376fd2de5da5f9ecdef41621a579252b899d7d Mon Sep 17 00:00:00
> 2001
> > > > From: Xiaohan Wang <xhw...@chromium.org>
> > > > Date: Fri, 2 Feb 2018 17:33:56 -0800
> > > > Subject: [PATCH] Fix ctts_index calculation
> > > >
> > > > An index should never be equal to the count. Hence we must make sure
> > > > *ctts_index < ctts_count.
> > > > ---
> > > >  libavformat/mov.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > should be reviewed by sasi idealy, he wrote this
> > >
> > > thx
> > >
> > >
> > > [...]
> > >
> > > --
> > > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC7
> 87040B0FAB
> > >
> > > Democracy is the form of government in which you can choose your
> dictator
> > >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Fix ctts_index calculation

2018-02-09 Thread Sasi Inguva
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 5adba52e08..f0bd3e3623 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3148,7 +3148,7 @@ static int find_prev_closest_index(AVStream *st,
>  *ctts_index = 0;
>  *ctts_sample = 0;
>  for (index_ctts_count = 0; index_ctts_count < *index;
> index_ctts_count++) {
> -if (*ctts_index < ctts_count) {

+if (*ctts_index < ctts_count - 1) {
>
If you do this, then we are skipping, looking at ctts_samples in the last
ctts entry where (*ctts_index == ctts_count -1), which is not desired.

 (*ctts_sample)++;
>  if (ctts_data[*ctts_index].count == *ctts_sample) {
>  (*ctts_index)++;
>

Here *ctts_index == ctts_count  only iff   the *ctts_index is the last CTTS
entry, and we still didn't reach   *index. That means that it's file with
CTTS truncated i.e. no corresponding CTTS entries for some STTS entries.
This issue can be fixed by checking for  *ctts_index <  ctts_count, in the
line after this loop.
while (*index

>= 0 && (*ctts_index
)
>= 0) {
we already check for (*ctts_index) >=0 so we can check for the upper bound
too.

On Sat, Feb 3, 2018 at 12:36 PM, Michael Niedermayer  wrote:

> On Fri, Feb 02, 2018 at 05:55:38PM -0800, Xiaohan Wang (王消寒) wrote:
> >
>
> >  mov.c |2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 87157b4053de0e044e78db72ef13e8058075c235  0001-Fix-ctts_index-calculatio
> n.patch
> > From bb376fd2de5da5f9ecdef41621a579252b899d7d Mon Sep 17 00:00:00 2001
> > From: Xiaohan Wang 
> > Date: Fri, 2 Feb 2018 17:33:56 -0800
> > Subject: [PATCH] Fix ctts_index calculation
> >
> > An index should never be equal to the count. Hence we must make sure
> > *ctts_index < ctts_count.
> > ---
> >  libavformat/mov.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
>
> should be reviewed by sasi idealy, he wrote this
>
> thx
>
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Democracy is the form of government in which you can choose your dictator
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] tests/fate/mov: Disable fate-mov-invalid-elst-entry-count, the test does not work reliable currently

2017-12-18 Thread Sasi Inguva
i was on vacation so I missed this. sorry for the trouble and thanks for
fixing the test. This test was fixed once before
http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=4ccc1ef2a3b1a22d849861423df830e110c9a4ab
.  I've no idea why only this test needs to have the "-flags +bitexact
-idct simple" while the other tests are fine.  I've used the same file as
the other tests, but just changed the Entry count atom using an Atom editor.

On Tue, Dec 5, 2017 at 4:12 PM, Michael Niedermayer 
wrote:

> On Tue, Dec 05, 2017 at 08:17:14PM +, Derek Buitenhuis wrote:
> > >> The commit that broke it should be reverted until the author
> > >> of that commit can explain why it changed, or fix it.
> > >
> > > The commit that added the test was the one that broke fate. It never
> > > worked.
> > > So this "sort of" reverts what caused the issue.
> >
> > Wasn't the code it tests added directly before the commit that added this
> > test? That's the code that is broken.
> >
> > The way I see it, the code is  workaround for broken files, but it
> doesn't
> > actually work. It should either be fixed, or the workaround removed if
> > nobody (especially the author) is willing to fix it.
>
> The test produces different output on qemu arm and x86-64.
> From this we know there is a bug, but not where the bug is.
> It can be in the test, the newly added code tested or code that was
> there before.
>
> My guess was, its the test, i cannot logically explain why.
>
> ive looked into this now and its missing -idct, adding that makes it
> produce the same result here
>
> ill push a fix for this
>
> thanks
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> There will always be a question for which you do not know the correct
> answer.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-12-18 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 56 
 tests/fate/mov.mak   |  7 +
 tests/ref/fate/mov-guess-delay-1 |  3 +++
 tests/ref/fate/mov-guess-delay-2 |  3 +++
 tests/ref/fate/mov-guess-delay-3 |  3 +++
 5 files changed, 72 insertions(+)
 create mode 100644 tests/ref/fate/mov-guess-delay-1
 create mode 100644 tests/ref/fate/mov-guess-delay-2
 create mode 100644 tests/ref/fate/mov-guess-delay-3

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 28d60289aa..480e506370 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3241,6 +3241,60 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 return *ctts_count;
 }
 
+#define MAX_REORDER_DELAY 16
+static void mov_estimate_video_delay(MOVContext *c, AVStream* st) {
+MOVStreamContext *msc = st->priv_data;
+int ind;
+int ctts_ind = 0;
+int ctts_sample = 0;
+int64_t pts_buf[MAX_REORDER_DELAY + 1]; // Circular buffer to sort pts.
+int buf_start = 0;
+int buf_size = 0;
+int j, r, num_swaps;
+
+if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
+st->codecpar->codec_id == AV_CODEC_ID_H264) {
+st->codecpar->video_delay = 0;
+for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; 
++ind) {
+if (buf_size == (MAX_REORDER_DELAY + 1)) {
+// If circular buffer is full, then move the first element 
forward.
+buf_start = (buf_start + 1) % buf_size;
+} else {
+++buf_size;
+}
+
+// Point j to the last elem of the buffer and insert the current 
pts there.
+j = (buf_start + buf_size - 1) % buf_size;
+pts_buf[j] = st->index_entries[ind].timestamp + 
msc->ctts_data[ctts_ind].duration;
+
+// The timestamps that are already in the sorted buffer, and are 
greater than the
+// current pts, are exactly the timestamps that need to be 
buffered to output PTS
+// in correct sorted order.
+// Hence the video delay (which is the buffer size used to sort 
DTS and output PTS),
+// can be computed as the maximum no. of swaps any particular 
timestamp needs to
+// go through, to keep this buffer in sorted order.
+num_swaps = 0;
+while (j != buf_start) {
+r = (j - 1 + buf_size) % buf_size;
+if (pts_buf[j] < pts_buf[r]) {
+FFSWAP(int64_t, pts_buf[j], pts_buf[r]);
+++num_swaps;
+}
+j = r;
+}
+st->codecpar->video_delay = FFMAX(st->codecpar->video_delay, 
num_swaps);
+
+ctts_sample++;
+if (ctts_sample == msc->ctts_data[ctts_ind].count) {
+ctts_ind++;
+ctts_sample = 0;
+}
+}
+av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for stream 
st: %d\n",
+   st->codecpar->video_delay, st->index);
+}
+}
+
 static void mov_current_sample_inc(MOVStreamContext *sc)
 {
 sc->current_sample++;
@@ -3897,6 +3951,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 // Fix index according to edit lists.
 mov_fix_index(mov, st);
 }
+
+mov_estimate_video_delay(mov, st);
 }
 
 static int test_same_origin(const char *src, const char *ref) {
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 19b01304fb..b37ba0e3aa 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -13,6 +13,9 @@ FATE_MOV = fate-mov-3elist \
fate-mov-elst-ends-betn-b-and-i \
fate-mov-frag-overlap \
fate-mov-bbi-elst-starts-b \
+   fate-mov-guess-delay-1 \
+   fate-mov-guess-delay-2 \
+   fate-mov-guess-delay-3 \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -82,3 +85,7 @@ fate-mov-spherical-mono: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
 fate-mov-gpmf-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags 
+bitexact -f mp4
 fate-mov-gpmf-remux: CMP = oneline
 fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
+
+fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
+fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
+fate-mov-guess-delay-3: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_4bf_pyramid_nobsrestriction.mp4
\ No new

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-12-18 Thread Sasi Inguva
Sorry for getting back so late as I was on vacation. Submitting the patch
again. This time I compute the delay exactly using a 17 element circular
buffer to sort the timestamps. PTAL.

On Wed, Nov 22, 2017 at 4:43 AM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Wed, Nov 22, 2017 at 01:21:45PM +0530, Sasi Inguva wrote:
> > I was just shooting for a heuristic which works for most of the cases.
>
> I do not think a heuristic is a good idea. Its not very hard to
> compute this exactly. You just reorder using a 16 entry buffer and
> keep track of what the largest size was that was actually needed.
>
> Or a buffer that is increased in size whenever it would lead to
> out of order output
>
>
>
> [...]
>
> > I can build a better heuristic by finding the  frame with next min. PTS
> > after Pmin and computing the distance between that frame and Pmin.
> However
> > that will still fail for this example,
> >  0, 3, 5, 1, 4, 2 . The delay computed will be 2 (because 2 frames
> between
> > 0 and 1 ) but we need a buffer size of 3 .
> >
> > On Wed, Nov 22, 2017 at 8:29 AM, Michael Niedermayer
> <mich...@niedermayer.cc
> > > wrote:
> >
> > > On Mon, Nov 20, 2017 at 08:27:05PM -0800, Sasi Inguva wrote:
> > > > Signed-off-by: Sasi Inguva <is...@google.com>
> > > > ---
> > > >  libavformat/mov.c| 50 ++
> > > ++
> > > >  tests/fate/mov.mak   |  7 ++
> > > >  tests/ref/fate/mov-guess-delay-1 |  3 +++
> > > >  tests/ref/fate/mov-guess-delay-2 |  3 +++
> > > >  tests/ref/fate/mov-guess-delay-3 |  3 +++
> > > >  5 files changed, 66 insertions(+)
> > > >  create mode 100644 tests/ref/fate/mov-guess-delay-1
> > > >  create mode 100644 tests/ref/fate/mov-guess-delay-2
> > > >  create mode 100644 tests/ref/fate/mov-guess-delay-3
> > > >
> > > > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > > > index fd170baa57..afb0d4ca5c 100644
> > > > --- a/libavformat/mov.c
> > > > +++ b/libavformat/mov.c
> > > > @@ -3213,6 +3213,54 @@ static int64_t add_ctts_entry(MOVStts**
> > > ctts_data, unsigned int* ctts_count, uns
> > > >  return *ctts_count;
> > > >  }
> > > >
> > > > +static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
> > > > +MOVStreamContext *msc = st->priv_data;
> > > > +int ind;
> > > > +int ctts_ind = 0;
> > > > +int ctts_sample = 0;
> > > > +int64_t curr_pts = AV_NOPTS_VALUE;
> > > > +int64_t min_prev_pts = AV_NOPTS_VALUE;
> > > > +int64_t prev_max_pts = AV_NOPTS_VALUE;
> > > > +int num_steps = 0;
> > > > +
> > > > +if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
> > > > +st->codecpar->codec_id == AV_CODEC_ID_H264) {
> > > > +st->codecpar->video_delay = 0;
> > > > +for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> > > msc->ctts_count; ++ind) {
> > > > +curr_pts = st->index_entries[ind].timestamp +
> > > msc->ctts_data[ctts_ind].duration;
> > > > +
> > > > +// Everytime we encounter a new max_pts we reset
> num_steps
> > > and compute again.
> > > > +if (curr_pts > prev_max_pts) {
> > > > +st->codecpar->video_delay =
> FFMIN(FFMAX(st->codecpar->video_delay,
> > > num_steps), 16);
> > > > +num_steps = 0;
> > > > +prev_max_pts = curr_pts;
> > > > +min_prev_pts = curr_pts;
> > > > +} else {
> > > > +// Compute delay as the length of the path from max
> PTS
> > > to min PTS.
> > > > +// Frames: I0 I1 B0 B1 B2
> > > > +// PTS: 0  4  1  2  3 -> num_steps = delay = 1
> > > (4->1)
> > > > +//
> > > > +// Frames: I0 I1 B1 B0 B2
> > > > +// PTS: 0  4  2  1  3 -> num_steps = delay = 2
> > > (4->2, 2->1)
> > > > +if (min_prev_pts != AV_NOPTS_VALUE) {
> > > > +if (curr_pts < min_prev_pts) {
> > > > +++num_steps;
> > > > +min_p

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-22 Thread Sasi Inguva
I was just shooting for a heuristic which works for most of the cases.
Most GOP structures are like this in decoding order
PTS:  Pmin ,  Pmax , (Pmin + k) , (Pmin + k -1) ... (Pmin + 1)
,  (Pmin + 2k) , (Pmin + 2k -1) ... (Pmin + k + 1)  (Pmax + 1)
PICT_TYPE: I0 I1   Bk   Bk-1
B0  B2k B2k-1  Bk+1
   I2

The min. buffer size is actually the number of frames that came in between
Pmin and Pmin + 1 ,since the buffer should be able to hold all those frames
(and sort them) , before Pmin + 1 comes along and is output. So here, the
buffer size is "k".

The algo computes the number of decreasing steps from Pmax ->  (Pmin + 1)
=  k . Hence the algo works for this case.

However I realize now that my algo will break,
when Pmin and Pmax are not adjacent
Pmin , *(Pmin + k -1)* , Pmax , (Pmin + k) ,  ... (Pmin + 1) , ...   - The
buffer size is still k but the algo will compute as (k - 1) . e.g.  0, 2,
4, 1, 3

or the path from Pmax -> (Pmin + 1) not strictly decreasing .
Pmin ,  Pmax , (Pmin + k) , (Pmin + k -1), *(Pmin + k +1)*   ... (Pmin +
1)  - The buffer size is now (k + 1) but the algo will still compute as  k
e.g. 0, 4, 2, 3, 1

I can build a better heuristic by finding the  frame with next min. PTS
after Pmin and computing the distance between that frame and Pmin.  However
that will still fail for this example,
 0, 3, 5, 1, 4, 2 . The delay computed will be 2 (because 2 frames between
0 and 1 ) but we need a buffer size of 3 .

On Wed, Nov 22, 2017 at 8:29 AM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Mon, Nov 20, 2017 at 08:27:05PM -0800, Sasi Inguva wrote:
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/mov.c| 50 ++
> ++
> >  tests/fate/mov.mak   |  7 ++
> >  tests/ref/fate/mov-guess-delay-1 |  3 +++
> >  tests/ref/fate/mov-guess-delay-2 |  3 +++
> >  tests/ref/fate/mov-guess-delay-3 |  3 +++
> >  5 files changed, 66 insertions(+)
> >  create mode 100644 tests/ref/fate/mov-guess-delay-1
> >  create mode 100644 tests/ref/fate/mov-guess-delay-2
> >  create mode 100644 tests/ref/fate/mov-guess-delay-3
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index fd170baa57..afb0d4ca5c 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -3213,6 +3213,54 @@ static int64_t add_ctts_entry(MOVStts**
> ctts_data, unsigned int* ctts_count, uns
> >  return *ctts_count;
> >  }
> >
> > +static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
> > +MOVStreamContext *msc = st->priv_data;
> > +int ind;
> > +int ctts_ind = 0;
> > +int ctts_sample = 0;
> > +int64_t curr_pts = AV_NOPTS_VALUE;
> > +int64_t min_prev_pts = AV_NOPTS_VALUE;
> > +int64_t prev_max_pts = AV_NOPTS_VALUE;
> > +int num_steps = 0;
> > +
> > +if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
> > +st->codecpar->codec_id == AV_CODEC_ID_H264) {
> > +st->codecpar->video_delay = 0;
> > +for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
> > +curr_pts = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
> > +
> > +// Everytime we encounter a new max_pts we reset num_steps
> and compute again.
> > +if (curr_pts > prev_max_pts) {
> > +st->codecpar->video_delay = 
> > FFMIN(FFMAX(st->codecpar->video_delay,
> num_steps), 16);
> > +num_steps = 0;
> > +prev_max_pts = curr_pts;
> > +min_prev_pts = curr_pts;
> > +} else {
> > +// Compute delay as the length of the path from max PTS
> to min PTS.
> > +// Frames: I0 I1 B0 B1 B2
> > +// PTS: 0  4  1  2  3 -> num_steps = delay = 1
> (4->1)
> > +//
> > +// Frames: I0 I1 B1 B0 B2
> > +// PTS: 0  4  2  1  3 -> num_steps = delay = 2
> (4->2, 2->1)
> > +if (min_prev_pts != AV_NOPTS_VALUE) {
> > +if (curr_pts < min_prev_pts) {
> > +++num_steps;
> > +min_prev_pts = curr_pts;
> > +}
> > +}
> > +}
>
> Can you explain why this algorithm is correct ?
> (iam asking as i suspect it is not correct, 

[FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-20 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 50 
 tests/fate/mov.mak   |  7 ++
 tests/ref/fate/mov-guess-delay-1 |  3 +++
 tests/ref/fate/mov-guess-delay-2 |  3 +++
 tests/ref/fate/mov-guess-delay-3 |  3 +++
 5 files changed, 66 insertions(+)
 create mode 100644 tests/ref/fate/mov-guess-delay-1
 create mode 100644 tests/ref/fate/mov-guess-delay-2
 create mode 100644 tests/ref/fate/mov-guess-delay-3

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..afb0d4ca5c 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3213,6 +3213,54 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 return *ctts_count;
 }
 
+static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
+MOVStreamContext *msc = st->priv_data;
+int ind;
+int ctts_ind = 0;
+int ctts_sample = 0;
+int64_t curr_pts = AV_NOPTS_VALUE;
+int64_t min_prev_pts = AV_NOPTS_VALUE;
+int64_t prev_max_pts = AV_NOPTS_VALUE;
+int num_steps = 0;
+
+if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
+st->codecpar->codec_id == AV_CODEC_ID_H264) {
+st->codecpar->video_delay = 0;
+for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; 
++ind) {
+curr_pts = st->index_entries[ind].timestamp + 
msc->ctts_data[ctts_ind].duration;
+
+// Everytime we encounter a new max_pts we reset num_steps and 
compute again.
+if (curr_pts > prev_max_pts) {
+st->codecpar->video_delay = 
FFMIN(FFMAX(st->codecpar->video_delay, num_steps), 16);
+num_steps = 0;
+prev_max_pts = curr_pts;
+min_prev_pts = curr_pts;
+} else {
+// Compute delay as the length of the path from max PTS to min 
PTS.
+// Frames: I0 I1 B0 B1 B2
+// PTS: 0  4  1  2  3 -> num_steps = delay = 1 (4->1)
+//
+// Frames: I0 I1 B1 B0 B2
+// PTS: 0  4  2  1  3 -> num_steps = delay = 2 (4->2, 2->1)
+if (min_prev_pts != AV_NOPTS_VALUE) {
+if (curr_pts < min_prev_pts) {
+++num_steps;
+min_prev_pts = curr_pts;
+}
+}
+}
+
+ctts_sample++;
+if (ctts_sample == msc->ctts_data[ctts_ind].count) {
+ctts_ind++;
+ctts_sample = 0;
+}
+}
+av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for stream 
st: %d\n",
+   st->codecpar->video_delay, st->index);
+}
+}
+
 static void mov_current_sample_inc(MOVStreamContext *sc)
 {
 sc->current_sample++;
@@ -3846,6 +3894,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 // Fix index according to edit lists.
 mov_fix_index(mov, st);
 }
+
+mov_guess_video_delay(mov, st);
 }
 
 static int test_same_origin(const char *src, const char *ref) {
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..6e79f0aba8 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,9 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-guess-delay-1 \
+   fate-mov-guess-delay-2 \
+   fate-mov-guess-delay-3 \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -72,3 +75,7 @@ fate-mov-spherical-mono: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
 fate-mov-gpmf-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags 
+bitexact -f mp4
 fate-mov-gpmf-remux: CMP = oneline
 fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
+
+fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
+fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
+fate-mov-guess-delay-3: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_4bf_pyramid_nobsrestriction.mp4
\ No newline at end of file
diff --git a/tests/ref/fate/mov-guess-delay-1 b/tests/ref/fate/mov-guess-delay-1
new file mode 100644
index 00..96cb67be0c
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-1
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=1
+[/STREAM]
diff --git a/tests/ref/fate/mov-guess-delay-2 b/tests/ref/fate/mov-guess-delay-2
new file mode 1

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-20 Thread Sasi Inguva
Reattaching Fate sample.


On Tue, Nov 21, 2017 at 9:57 AM, Sasi Inguva <is...@google.com> wrote:

> Signed-off-by: Sasi Inguva <is...@google.com>
> ---
>  libavformat/mov.c| 50 ++
> ++
>  tests/fate/mov.mak   |  7 ++
>  tests/ref/fate/mov-guess-delay-1 |  3 +++
>  tests/ref/fate/mov-guess-delay-2 |  3 +++
>  tests/ref/fate/mov-guess-delay-3 |  3 +++
>  5 files changed, 66 insertions(+)
>  create mode 100644 tests/ref/fate/mov-guess-delay-1
>  create mode 100644 tests/ref/fate/mov-guess-delay-2
>  create mode 100644 tests/ref/fate/mov-guess-delay-3
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index fd170baa57..afb0d4ca5c 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3213,6 +3213,54 @@ static int64_t add_ctts_entry(MOVStts** ctts_data,
> unsigned int* ctts_count, uns
>  return *ctts_count;
>  }
>
> +static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
> +MOVStreamContext *msc = st->priv_data;
> +int ind;
> +int ctts_ind = 0;
> +int ctts_sample = 0;
> +int64_t curr_pts = AV_NOPTS_VALUE;
> +int64_t min_prev_pts = AV_NOPTS_VALUE;
> +int64_t prev_max_pts = AV_NOPTS_VALUE;
> +int num_steps = 0;
> +
> +if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
> +st->codecpar->codec_id == AV_CODEC_ID_H264) {
> +st->codecpar->video_delay = 0;
> +for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
> +curr_pts = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
> +
> +// Everytime we encounter a new max_pts we reset num_steps
> and compute again.
> +if (curr_pts > prev_max_pts) {
> +st->codecpar->video_delay = 
> FFMIN(FFMAX(st->codecpar->video_delay,
> num_steps), 16);
> +num_steps = 0;
> +prev_max_pts = curr_pts;
> +min_prev_pts = curr_pts;
> +} else {
> +// Compute delay as the length of the path from max PTS
> to min PTS.
> +// Frames: I0 I1 B0 B1 B2
> +// PTS: 0  4  1  2  3 -> num_steps = delay = 1 (4->1)
> +//
> +// Frames: I0 I1 B1 B0 B2
> +// PTS: 0  4  2  1  3 -> num_steps = delay = 2 (4->2,
> 2->1)
> +if (min_prev_pts != AV_NOPTS_VALUE) {
> +if (curr_pts < min_prev_pts) {
> +++num_steps;
> +min_prev_pts = curr_pts;
> +}
> +}
> +}
> +
> +ctts_sample++;
> +if (ctts_sample == msc->ctts_data[ctts_ind].count) {
> +ctts_ind++;
> +ctts_sample = 0;
> +}
> +}
> +av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for
> stream st: %d\n",
> +   st->codecpar->video_delay, st->index);
> +}
> +}
> +
>  static void mov_current_sample_inc(MOVStreamContext *sc)
>  {
>  sc->current_sample++;
> @@ -3846,6 +3894,8 @@ static void mov_build_index(MOVContext *mov,
> AVStream *st)
>  // Fix index according to edit lists.
>  mov_fix_index(mov, st);
>  }
> +
> +mov_guess_video_delay(mov, st);
>  }
>
>  static int test_same_origin(const char *src, const char *ref) {
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 76f66ff498..6e79f0aba8 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -11,6 +11,9 @@ FATE_MOV = fate-mov-3elist \
> fate-mov-440hz-10ms \
> fate-mov-ibi-elst-starts-b \
> fate-mov-elst-ends-betn-b-and-i \
> +   fate-mov-guess-delay-1 \
> +   fate-mov-guess-delay-2 \
> +   fate-mov-guess-delay-3 \
>
>  FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
> fate-mov-zombie \
> @@ -72,3 +75,7 @@ fate-mov-spherical-mono: CMD = run
> ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
>  fate-mov-gpmf-remux: CMD = md5 -i 
> $(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4
> -map 0 -c copy -fflags +bitexact -f mp4
>  fate-mov-gpmf-remux: CMP = oneline
>  fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
> +
> +fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF)
> -show_entries stream=has_b_frames -select_streams v
> $(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
> +fate-mov-guess-delay-2: CMD = run ffprobe$(

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-20 Thread Sasi Inguva
Ok. Just restricting this to H264 .

On Tue, Nov 21, 2017 at 3:56 AM, Hendrik Leppkes <h.lepp...@gmail.com>
wrote:

> On Mon, Nov 20, 2017 at 11:06 PM, Michael Niedermayer
> <mich...@niedermayer.cc> wrote:
> > On Mon, Nov 20, 2017 at 09:58:05PM +0530, Sasi Inguva wrote:
> >> On Sun, Nov 19, 2017 at 1:17 AM, Michael Niedermayer
> <mich...@niedermayer.cc
> >> > wrote:
> >>
> >> > On Sat, Nov 18, 2017 at 11:12:17AM -0800, Sasi Inguva wrote:
> >> > > Signed-off-by: Sasi Inguva <is...@google.com>
> >> > > ---
> >> > >  libavformat/mov.c| 54
> ++
> >> > ++
> >> > >  tests/fate/mov.mak   |  5 
> >> > >  tests/ref/fate/mov-guess-delay-1 |  3 +++
> >> > >  tests/ref/fate/mov-guess-delay-2 |  3 +++
> >> > >  4 files changed, 65 insertions(+)
> >> > >  create mode 100644 tests/ref/fate/mov-guess-delay-1
> >> > >  create mode 100644 tests/ref/fate/mov-guess-delay-2
> >> > >
> >> > > diff --git a/libavformat/mov.c b/libavformat/mov.c
> >> > > index fd170baa57..7354652c6e 100644
> >> > > --- a/libavformat/mov.c
> >> > > +++ b/libavformat/mov.c
> >> > > @@ -3213,6 +3213,58 @@ static int64_t add_ctts_entry(MOVStts**
> >> > ctts_data, unsigned int* ctts_count, uns
> >> > >  return *ctts_count;
> >> > >  }
> >> > >
> >> > > +static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
> >> > > +MOVStreamContext *msc = st->priv_data;
> >> > > +int ind;
> >> > > +int ctts_ind = 0;
> >> > > +int ctts_sample = 0;
> >> > > +int64_t curr_pts = AV_NOPTS_VALUE;
> >> > > +int64_t prev_pts = AV_NOPTS_VALUE;
> >> > > +int64_t prev_max_pts = AV_NOPTS_VALUE;
> >> > > +int num_swaps = 0;
> >> > > +
> >> > > +if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
> >> > > +(st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
> >> > > + st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
> >> > > + st->codecpar->codec_id == AV_CODEC_ID_VC1 ||
> >> > > + st->codecpar->codec_id == AV_CODEC_ID_H263 ||
> >> > > + st->codecpar->codec_id == AV_CODEC_ID_H264 ||
> >> > > + st->codecpar->codec_id == AV_CODEC_ID_HEVC)) {
> >> >
> >> > Do all these cases really need this ?
> >> >
> >> > I just wanted to list all codecs with B-frames. H264, HEVC need it in
> >> case, the bitstream_restriction_flag is not set in the bitstream. Other
> >> codecs might need it only if the bitstream has been written incorrectly
> >> i.e. writing 0 for the delay bit when there are B-frames etc. I can
> >> restrict to H264 , HEVC if needed.
> >
> > yes, please restrict this.
> > I very much doubt that the mov/mp4 demuxer has more correct data
> > about the codec than the codec itself when such data is needed to
> > decode and cannot be ommited.
> >
> > I kind of find it a poor design choice that this can be ommited in
> > h264 & hevc, but theres nothing we can do about this
> >
>
> I don't belive hevc needs this value to be set, our decoder certainly
> doesn't. It seems to fill it straight from the SPS, without conditions
> (and the decoding logic never actually reads it).
> Our h264 decoder is the only one that actually needs this value to not
> drop frames, most other decoders just set it (potentially for the
> generic timestamp stuff?)
>
> - Hendrik
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-20 Thread Sasi Inguva
Attaching the fate sample

On Mon, Nov 20, 2017 at 8:28 AM, Sasi Inguva <is...@google.com> wrote:

> Signed-off-by: Sasi Inguva <is...@google.com>
> ---
>  libavformat/mov.c| 55 ++
> ++
>  tests/fate/mov.mak   |  7 +
>  tests/ref/fate/mov-guess-delay-1 |  3 +++
>  tests/ref/fate/mov-guess-delay-2 |  3 +++
>  tests/ref/fate/mov-guess-delay-3 |  3 +++
>  5 files changed, 71 insertions(+)
>  create mode 100644 tests/ref/fate/mov-guess-delay-1
>  create mode 100644 tests/ref/fate/mov-guess-delay-2
>  create mode 100644 tests/ref/fate/mov-guess-delay-3
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index fd170baa57..d1bd0c4f29 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3213,6 +3213,59 @@ static int64_t add_ctts_entry(MOVStts** ctts_data,
> unsigned int* ctts_count, uns
>  return *ctts_count;
>  }
>
> +static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
> +MOVStreamContext *msc = st->priv_data;
> +int ind;
> +int ctts_ind = 0;
> +int ctts_sample = 0;
> +int64_t curr_pts = AV_NOPTS_VALUE;
> +int64_t min_prev_pts = AV_NOPTS_VALUE;
> +int64_t prev_max_pts = AV_NOPTS_VALUE;
> +int num_steps = 0;
> +
> +if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
> +(st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
> + st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
> + st->codecpar->codec_id == AV_CODEC_ID_VC1 ||
> + st->codecpar->codec_id == AV_CODEC_ID_H263 ||
> + st->codecpar->codec_id == AV_CODEC_ID_H264 ||
> + st->codecpar->codec_id == AV_CODEC_ID_HEVC)) {
> +st->codecpar->video_delay = 0;
> +for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
> +curr_pts = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
> +
> +// Everytime we encounter a new max_pts we reset num_steps
> and compute again.
> +if (curr_pts > prev_max_pts) {
> +st->codecpar->video_delay = 
> FFMIN(FFMAX(st->codecpar->video_delay,
> num_steps), 16);
> +num_steps = 0;
> +prev_max_pts = curr_pts;
> +min_prev_pts = curr_pts;
> +} else {
> +// Compute delay as the length of the path from max PTS
> to min PTS.
> +// Frames: I0 I1 B0 B1 B2
> +// PTS: 0  4  1  2  3 -> num_steps = delay = 1 (4->1)
> +//
> +// Frames: I0 I1 B1 B0 B2
> +// PTS: 0  4  2  1  3 -> num_steps = delay = 2 (4->2,
> 2->1)
> +if (min_prev_pts != AV_NOPTS_VALUE) {
> +if (curr_pts < min_prev_pts) {
> +++num_steps;
> +min_prev_pts = curr_pts;
> +}
> +}
> +}
> +
> +ctts_sample++;
> +if (ctts_sample == msc->ctts_data[ctts_ind].count) {
> +ctts_ind++;
> +ctts_sample = 0;
> +}
> +}
> +av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for
> stream st: %d\n",
> +   st->codecpar->video_delay, st->index);
> +}
> +}
> +
>  static void mov_current_sample_inc(MOVStreamContext *sc)
>  {
>  sc->current_sample++;
> @@ -3846,6 +3899,8 @@ static void mov_build_index(MOVContext *mov,
> AVStream *st)
>  // Fix index according to edit lists.
>  mov_fix_index(mov, st);
>  }
> +
> +mov_guess_video_delay(mov, st);
>  }
>
>  static int test_same_origin(const char *src, const char *ref) {
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 76f66ff498..6e79f0aba8 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -11,6 +11,9 @@ FATE_MOV = fate-mov-3elist \
> fate-mov-440hz-10ms \
> fate-mov-ibi-elst-starts-b \
> fate-mov-elst-ends-betn-b-and-i \
> +   fate-mov-guess-delay-1 \
> +   fate-mov-guess-delay-2 \
> +   fate-mov-guess-delay-3 \
>
>  FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
> fate-mov-zombie \
> @@ -72,3 +75,7 @@ fate-mov-spherical-mono: CMD = run
> ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
>  fate-mov-gpmf-remux: CMD = md5 -i 
> $(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4
> -map 0 -c copy -fflags +bitexact -f mp4
>  fate-m

[FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-20 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 55 
 tests/fate/mov.mak   |  7 +
 tests/ref/fate/mov-guess-delay-1 |  3 +++
 tests/ref/fate/mov-guess-delay-2 |  3 +++
 tests/ref/fate/mov-guess-delay-3 |  3 +++
 5 files changed, 71 insertions(+)
 create mode 100644 tests/ref/fate/mov-guess-delay-1
 create mode 100644 tests/ref/fate/mov-guess-delay-2
 create mode 100644 tests/ref/fate/mov-guess-delay-3

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..d1bd0c4f29 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3213,6 +3213,59 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 return *ctts_count;
 }
 
+static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
+MOVStreamContext *msc = st->priv_data;
+int ind;
+int ctts_ind = 0;
+int ctts_sample = 0;
+int64_t curr_pts = AV_NOPTS_VALUE;
+int64_t min_prev_pts = AV_NOPTS_VALUE;
+int64_t prev_max_pts = AV_NOPTS_VALUE;
+int num_steps = 0;
+
+if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
+(st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
+ st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
+ st->codecpar->codec_id == AV_CODEC_ID_VC1 ||
+ st->codecpar->codec_id == AV_CODEC_ID_H263 ||
+ st->codecpar->codec_id == AV_CODEC_ID_H264 ||
+ st->codecpar->codec_id == AV_CODEC_ID_HEVC)) {
+st->codecpar->video_delay = 0;
+for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; 
++ind) {
+curr_pts = st->index_entries[ind].timestamp + 
msc->ctts_data[ctts_ind].duration;
+
+// Everytime we encounter a new max_pts we reset num_steps and 
compute again.
+if (curr_pts > prev_max_pts) {
+st->codecpar->video_delay = 
FFMIN(FFMAX(st->codecpar->video_delay, num_steps), 16);
+num_steps = 0;
+prev_max_pts = curr_pts;
+min_prev_pts = curr_pts;
+} else {
+// Compute delay as the length of the path from max PTS to min 
PTS.
+// Frames: I0 I1 B0 B1 B2
+// PTS: 0  4  1  2  3 -> num_steps = delay = 1 (4->1)
+//
+// Frames: I0 I1 B1 B0 B2
+// PTS: 0  4  2  1  3 -> num_steps = delay = 2 (4->2, 2->1)
+if (min_prev_pts != AV_NOPTS_VALUE) {
+if (curr_pts < min_prev_pts) {
+++num_steps;
+min_prev_pts = curr_pts;
+}
+}
+}
+
+ctts_sample++;
+if (ctts_sample == msc->ctts_data[ctts_ind].count) {
+ctts_ind++;
+ctts_sample = 0;
+}
+}
+av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for stream 
st: %d\n",
+   st->codecpar->video_delay, st->index);
+}
+}
+
 static void mov_current_sample_inc(MOVStreamContext *sc)
 {
 sc->current_sample++;
@@ -3846,6 +3899,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 // Fix index according to edit lists.
 mov_fix_index(mov, st);
 }
+
+mov_guess_video_delay(mov, st);
 }
 
 static int test_same_origin(const char *src, const char *ref) {
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..6e79f0aba8 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,9 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-guess-delay-1 \
+   fate-mov-guess-delay-2 \
+   fate-mov-guess-delay-3 \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -72,3 +75,7 @@ fate-mov-spherical-mono: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
 fate-mov-gpmf-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags 
+bitexact -f mp4
 fate-mov-gpmf-remux: CMP = oneline
 fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
+
+fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
+fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
+fate-mov-guess-delay-3: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_4bf_pyramid_nobsrestriction.mp4
\ No newline at end of file
diff --git a/t

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-20 Thread Sasi Inguva
On Sun, Nov 19, 2017 at 1:17 AM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Sat, Nov 18, 2017 at 11:12:17AM -0800, Sasi Inguva wrote:
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/mov.c| 54 ++
> ++
> >  tests/fate/mov.mak   |  5 
> >  tests/ref/fate/mov-guess-delay-1 |  3 +++
> >  tests/ref/fate/mov-guess-delay-2 |  3 +++
> >  4 files changed, 65 insertions(+)
> >  create mode 100644 tests/ref/fate/mov-guess-delay-1
> >  create mode 100644 tests/ref/fate/mov-guess-delay-2
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index fd170baa57..7354652c6e 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -3213,6 +3213,58 @@ static int64_t add_ctts_entry(MOVStts**
> ctts_data, unsigned int* ctts_count, uns
> >  return *ctts_count;
> >  }
> >
> > +static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
> > +MOVStreamContext *msc = st->priv_data;
> > +int ind;
> > +int ctts_ind = 0;
> > +int ctts_sample = 0;
> > +int64_t curr_pts = AV_NOPTS_VALUE;
> > +int64_t prev_pts = AV_NOPTS_VALUE;
> > +int64_t prev_max_pts = AV_NOPTS_VALUE;
> > +int num_swaps = 0;
> > +
> > +if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
> > +(st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
> > + st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
> > + st->codecpar->codec_id == AV_CODEC_ID_VC1 ||
> > + st->codecpar->codec_id == AV_CODEC_ID_H263 ||
> > + st->codecpar->codec_id == AV_CODEC_ID_H264 ||
> > + st->codecpar->codec_id == AV_CODEC_ID_HEVC)) {
>
> Do all these cases really need this ?
>
> I just wanted to list all codecs with B-frames. H264, HEVC need it in
case, the bitstream_restriction_flag is not set in the bitstream. Other
codecs might need it only if the bitstream has been written incorrectly
i.e. writing 0 for the delay bit when there are B-frames etc. I can
restrict to H264 , HEVC if needed.

video_delay = 0 is also a valid value so it can be set to 0 already

intentionally
>
> I just want to avoid the case where the code incorrectly estimates a
video_delay that is lesser than what is written in the bitstream, because
that would be a fatal error resulting in incorrect timestamps. The other
case where the code estimates non-zero video_delay when it is zero in the
bitstream is benign.

>
> > +st->codecpar->video_delay = 0;
> > +for(ind = 0; ind < st->nb_index_entries && ctts_ind <
> msc->ctts_count; ++ind) {
> > +curr_pts = st->index_entries[ind].timestamp +
> msc->ctts_data[ctts_ind].duration;
> > +
>
> > +// This is used as an indication that the previous GOP has
> ended and a
> > +// new GOP has started.
>
> this is not neccesary a GOP uless i misread the code
>
> Corrected the comment.

>
> > +if (curr_pts > prev_max_pts) {
> > +st->codecpar->video_delay = 
> > FFMIN(FFMAX(st->codecpar->video_delay,
> num_swaps), 16);
> > +num_swaps = 0;
> > +prev_max_pts = curr_pts;
> > +}
> > +
> > +// Compute delay as the no. of "drop"s in PTS inside a GOP.
> > +// Frames: I0 I1 B0 B1 B2
> > +// PTS: 0  4  1  2  3 -> num_swaps = delay = 1 (4->1)
> > +//
> > +// Frames: I0 I1 B1 B0 B2
> > +// PTS: 0  4  2  1  3 -> num_swaps = delay = 2 (4->2,
> 2->1)
>
> This may be incorret
>
> consider
> PTS0  5  2  1  4  3
> BUFFER 0  05 25 25 45 45 5
> OUT  0  1  2  3  4  5
>
> So this is a delay = 2 but your code would set 3 i think
>
> True. Thanks for catching it. The issue will only get worse, with more no.
of B-frames in-between ( 0 7 2 1 4 3 6 4 -> would have delay 4 ) . I have
changed the code to estimate the delay as the length of the patch from max.
PTS to min. PTS . (So only 5->2->1 will be counted). Sending the new
patch.  PTAL. Thanks.

>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Those who are best at talking, realize last or never when they are wrong.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-18 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 54 
 tests/fate/mov.mak   |  5 
 tests/ref/fate/mov-guess-delay-1 |  3 +++
 tests/ref/fate/mov-guess-delay-2 |  3 +++
 4 files changed, 65 insertions(+)
 create mode 100644 tests/ref/fate/mov-guess-delay-1
 create mode 100644 tests/ref/fate/mov-guess-delay-2

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..7354652c6e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3213,6 +3213,58 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 return *ctts_count;
 }
 
+static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
+MOVStreamContext *msc = st->priv_data;
+int ind;
+int ctts_ind = 0;
+int ctts_sample = 0;
+int64_t curr_pts = AV_NOPTS_VALUE;
+int64_t prev_pts = AV_NOPTS_VALUE;
+int64_t prev_max_pts = AV_NOPTS_VALUE;
+int num_swaps = 0;
+
+if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
+(st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
+ st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
+ st->codecpar->codec_id == AV_CODEC_ID_VC1 ||
+ st->codecpar->codec_id == AV_CODEC_ID_H263 ||
+ st->codecpar->codec_id == AV_CODEC_ID_H264 ||
+ st->codecpar->codec_id == AV_CODEC_ID_HEVC)) {
+st->codecpar->video_delay = 0;
+for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; 
++ind) {
+curr_pts = st->index_entries[ind].timestamp + 
msc->ctts_data[ctts_ind].duration;
+
+// This is used as an indication that the previous GOP has ended 
and a
+// new GOP has started.
+if (curr_pts > prev_max_pts) {
+st->codecpar->video_delay = 
FFMIN(FFMAX(st->codecpar->video_delay, num_swaps), 16);
+num_swaps = 0;
+prev_max_pts = curr_pts;
+}
+
+// Compute delay as the no. of "drop"s in PTS inside a GOP.
+// Frames: I0 I1 B0 B1 B2
+// PTS: 0  4  1  2  3 -> num_swaps = delay = 1 (4->1)
+//
+// Frames: I0 I1 B1 B0 B2
+// PTS: 0  4  2  1  3 -> num_swaps = delay = 2 (4->2, 2->1)
+if (prev_pts != AV_NOPTS_VALUE) {
+if (curr_pts < prev_pts)
+++num_swaps;
+}
+
+prev_pts = curr_pts;
+ctts_sample++;
+if (ctts_sample == msc->ctts_data[ctts_ind].count) {
+ctts_ind++;
+ctts_sample = 0;
+}
+}
+av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for stream 
st: %d\n",
+   st->codecpar->video_delay, st->index);
+}
+}
+
 static void mov_current_sample_inc(MOVStreamContext *sc)
 {
 sc->current_sample++;
@@ -3846,6 +3898,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 // Fix index according to edit lists.
 mov_fix_index(mov, st);
 }
+
+mov_guess_video_delay(mov, st);
 }
 
 static int test_same_origin(const char *src, const char *ref) {
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..ef89e62096 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,8 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-guess-delay-1 \
+   fate-mov-guess-delay-2 \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -72,3 +74,6 @@ fate-mov-spherical-mono: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
 fate-mov-gpmf-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags 
+bitexact -f mp4
 fate-mov-gpmf-remux: CMP = oneline
 fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
+
+fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
+fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
\ No newline at end of file
diff --git a/tests/ref/fate/mov-guess-delay-1 b/tests/ref/fate/mov-guess-delay-1
new file mode 100644
index 00..96cb67be0c
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-1
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=1
+[/STREAM]
diff --git a/tests/ref/fate/mov-guess-delay-2 b/tests/ref/fate/mov-guess-delay-2
new file mode 100644
index 00..248de1c3ea
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-2
@@ -0,0 +1,3 @@
+[STREAM]
+has

[FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-18 Thread Sasi Inguva
Done. is there a better way to identify codecs that might need 
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 52 
 tests/fate/mov.mak   |  5 
 tests/ref/fate/mov-guess-delay-1 |  3 +++
 tests/ref/fate/mov-guess-delay-2 |  3 +++
 4 files changed, 63 insertions(+)
 create mode 100644 tests/ref/fate/mov-guess-delay-1
 create mode 100644 tests/ref/fate/mov-guess-delay-2

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..687297be33 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3213,6 +3213,56 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 return *ctts_count;
 }
 
+static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
+MOVStreamContext *msc = st->priv_data;
+int ind;
+int ctts_ind = 0;
+int ctts_sample = 0;
+int64_t curr_pts = AV_NOPTS_VALUE;
+int64_t prev_pts = AV_NOPTS_VALUE;
+int64_t prev_max_pts = AV_NOPTS_VALUE;
+int num_swaps = 0;
+
+if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
+(st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
+ st->codecpar->codec_id == AV_CODEC_ID_H263 ||
+ st->codecpar->codec_id == AV_CODEC_ID_H264 ||
+ st->codecpar->codec_id == AV_CODEC_ID_HEVC)) {
+st->codecpar->video_delay = 0;
+for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; 
++ind) {
+curr_pts = st->index_entries[ind].timestamp + 
msc->ctts_data[ctts_ind].duration;
+
+// This is used as an indication that the previous GOP has ended 
and a
+// new GOP has started.
+if (curr_pts > prev_max_pts) {
+st->codecpar->video_delay = 
FFMIN(FFMAX(st->codecpar->video_delay, num_swaps), 16);
+num_swaps = 0;
+prev_max_pts = curr_pts;
+}
+
+// Compute delay as the no. of "drop"s in PTS inside a GOP.
+// Frames: I0 I1 B0 B1 B2
+// PTS: 0  4  1  2  3 -> num_swaps = delay = 1 (4->1)
+//
+// Frames: I0 I1 B1 B0 B2
+// PTS: 0  4  2  1  3 -> num_swaps = delay = 2 (4->2, 2->1)
+if (prev_pts != AV_NOPTS_VALUE) {
+if (curr_pts < prev_pts)
+++num_swaps;
+}
+
+prev_pts = curr_pts;
+ctts_sample++;
+if (ctts_sample == msc->ctts_data[ctts_ind].count) {
+ctts_ind++;
+ctts_sample = 0;
+}
+}
+av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for stream 
st: %d\n",
+   st->codecpar->video_delay, st->index);
+}
+}
+
 static void mov_current_sample_inc(MOVStreamContext *sc)
 {
 sc->current_sample++;
@@ -3846,6 +3896,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 // Fix index according to edit lists.
 mov_fix_index(mov, st);
 }
+
+mov_guess_video_delay(mov, st);
 }
 
 static int test_same_origin(const char *src, const char *ref) {
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..ef89e62096 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,8 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-guess-delay-1 \
+   fate-mov-guess-delay-2 \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -72,3 +74,6 @@ fate-mov-spherical-mono: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
 fate-mov-gpmf-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags 
+bitexact -f mp4
 fate-mov-gpmf-remux: CMP = oneline
 fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
+
+fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
+fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
\ No newline at end of file
diff --git a/tests/ref/fate/mov-guess-delay-1 b/tests/ref/fate/mov-guess-delay-1
new file mode 100644
index 00..96cb67be0c
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-1
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=1
+[/STREAM]
diff --git a/tests/ref/fate/mov-guess-delay-2 b/tests/ref/fate/mov-guess-delay-2
new file mode 100644
index 00..248de1c3ea
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-2
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=2
+[/STREAM]
-- 
2.15.0.448.gf294e3d99a-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [mov] Fix leak of frame_duration_buffer in mov_fix_index().

2017-11-18 Thread Sasi Inguva
LGTM. Thanks for the fix.

On Sat, Nov 18, 2017 at 4:24 AM, Dale Curtis 
wrote:

> Should be unconditionally freed at the end of mov_fix_index() in case it
> hasn't been used during the fix up.
>
> Signed-off-by: Dale Curtis 
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-17 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 52 
 tests/fate/mov.mak   |  5 
 tests/ref/fate/mov-guess-delay-1 |  3 +++
 tests/ref/fate/mov-guess-delay-2 |  3 +++
 4 files changed, 63 insertions(+)
 create mode 100644 tests/ref/fate/mov-guess-delay-1
 create mode 100644 tests/ref/fate/mov-guess-delay-2

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..687297be33 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3213,6 +3213,56 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 return *ctts_count;
 }
 
+static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
+MOVStreamContext *msc = st->priv_data;
+int ind;
+int ctts_ind = 0;
+int ctts_sample = 0;
+int64_t curr_pts = AV_NOPTS_VALUE;
+int64_t prev_pts = AV_NOPTS_VALUE;
+int64_t prev_max_pts = AV_NOPTS_VALUE;
+int num_swaps = 0;
+
+if (st->codecpar->video_delay <= 0 && msc->ctts_data &&
+(st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
+ st->codecpar->codec_id == AV_CODEC_ID_H263 ||
+ st->codecpar->codec_id == AV_CODEC_ID_H264 ||
+ st->codecpar->codec_id == AV_CODEC_ID_HEVC)) {
+st->codecpar->video_delay = 0;
+for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; 
++ind) {
+curr_pts = st->index_entries[ind].timestamp + 
msc->ctts_data[ctts_ind].duration;
+
+// This is used as an indication that the previous GOP has ended 
and a
+// new GOP has started.
+if (curr_pts > prev_max_pts) {
+st->codecpar->video_delay = 
FFMIN(FFMAX(st->codecpar->video_delay, num_swaps), 16);
+num_swaps = 0;
+prev_max_pts = curr_pts;
+}
+
+// Compute delay as the no. of "drop"s in PTS inside a GOP.
+// Frames: I0 I1 B0 B1 B2
+// PTS: 0  4  1  2  3 -> num_swaps = delay = 1 (4->1)
+//
+// Frames: I0 I1 B1 B0 B2
+// PTS: 0  4  2  1  3 -> num_swaps = delay = 2 (4->2, 2->1)
+if (prev_pts != AV_NOPTS_VALUE) {
+if (curr_pts < prev_pts)
+++num_swaps;
+}
+
+prev_pts = curr_pts;
+ctts_sample++;
+if (ctts_sample == msc->ctts_data[ctts_ind].count) {
+ctts_ind++;
+ctts_sample = 0;
+}
+}
+av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for stream 
st: %d\n",
+   st->codecpar->video_delay, st->index);
+}
+}
+
 static void mov_current_sample_inc(MOVStreamContext *sc)
 {
 sc->current_sample++;
@@ -3846,6 +3896,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 // Fix index according to edit lists.
 mov_fix_index(mov, st);
 }
+
+mov_guess_video_delay(mov, st);
 }
 
 static int test_same_origin(const char *src, const char *ref) {
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..ef89e62096 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,8 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-guess-delay-1 \
+   fate-mov-guess-delay-2 \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -72,3 +74,6 @@ fate-mov-spherical-mono: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
 fate-mov-gpmf-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags 
+bitexact -f mp4
 fate-mov-gpmf-remux: CMP = oneline
 fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
+
+fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
+fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
\ No newline at end of file
diff --git a/tests/ref/fate/mov-guess-delay-1 b/tests/ref/fate/mov-guess-delay-1
new file mode 100644
index 00..96cb67be0c
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-1
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=1
+[/STREAM]
diff --git a/tests/ref/fate/mov-guess-delay-2 b/tests/ref/fate/mov-guess-delay-2
new file mode 100644
index 00..248de1c3ea
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-2
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=2
+[/STREAM]
-- 
2.15.0.448.gf294e3d99a-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-17 Thread Sasi Inguva
restricted the patch to MPEG based codecs. Also, setting the delay only if
it's not set already and capping the max. value to 16.

On Wed, Nov 15, 2017 at 5:55 AM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Tue, Nov 14, 2017 at 03:36:49PM -0800, Thierry Foucu wrote:
> > On Tue, Nov 14, 2017 at 3:23 PM, Derek Buitenhuis <
> > derek.buitenh...@gmail.com> wrote:
> >
> > > On 11/14/2017 10:11 PM, Sasi Inguva wrote:
> > > > I don't know if the patch can be made more generic to work for all
> > > > demuxers, because this patch requires that PTS of all packets be
> > > available
> > > > in the header.  The other route is to make it very specific to codecs
> > > with
> > > > B-frames.
> > >
> > > All PTS may not be available in MP4 either, in the live profile
> fragmented
> > > MP4 case, no? I am not familiar enough with the fragmented MP4 demuxing
> > > code
> > > say whether we seek to each fragment and make it available or not. I
> assume
> > > you've tested such a case, or can (or know the fragment code)?
> > >
> > > It's feasible to restrict it to codecs, I suppose.
> > >
> > > >> You do not appear to be restricting this to one specific codec, or
> even
> > > >> codecs
> > > >> with B-frames.
> > > >>
> > > >> I can make it specific to only H264 / H265.
> > >
> > > The GOP structure should be applicable to most MPEG codecs, I think.
> > >
> > > > It is true that the patch will fail to compute the correct delay in
> lots
> > > of
> > > > cases. However the consequence of wrongly computing the has_b_frames
> is
> > > > pretty benign. It only increases the buffer size held for PTS
> > > reordering.
> > > > I can put a max-value check on the computed video_delay here. So in
> my
> > > > opinion, we won't see fatal regressions where a file is not able to
> be
> > > > decoded / played.
> > >
> > > It's true it's likely benign, but it's not exactly a "fix" either...
> > >
> > > From a user perspective, it's kinda possible to work around it
> "properly"
> > > (I use that term loosely here) by decoding enough frames to fill the
> max
> > > DPB for a given codec (e.g. 16 for H.264) in avformat_find_stream_info
> > > (or in a user's code if they don't use that function), isn't it?
> Though,
> > > I feel that particular fix won't be welcomed with open arms, due to a
> > > ~16x 'slow down' in probing.
> > >
> > >
> > One option i asked on IRC was to use the spec for max DPB when the
> bitstream
> > restriction flag was not set.
> > But people were worry about low latency usage.
> > Normally, if the  bitstream restriction flag is not set, the DPB should
> be
> > set based on the spec, even if there is no B frames.
> > But in some case, it will be 16 frame and this could increase then the
> low
> > latency.
>
> it could also increase memory requirements substantially
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Avoid a single point of failure, be that a person or equipment.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-14 Thread Sasi Inguva
I don't know if the patch can be made more generic to work for all
demuxers, because this patch requires that PTS of all packets be available
in the header.  The other route is to make it very specific to codecs with
B-frames.

On Tue, Nov 14, 2017 at 12:40 PM, Derek Buitenhuis <
derek.buitenh...@gmail.com> wrote:

> On 11/14/2017 8:28 PM, Sasi Inguva wrote:
> > For H264 files with no bitstream restriction flag, we aren't able to
> guess
> > the delay correctly. Especially if it's MOV container, because for MOV
> > container we just probe the 1st frame and stop in
> avformat_find_streaminfo .
>
> You do not appear to be restricting this to one specific codec, or even
> codecs
> with B-frames.
>
> I can make it specific to only H264 / H265.


> > When we are decoding , we increase the has_b_frames value from zero to 1
> or
> > 2, when we eventually encounter B-frames in H264 decoder, but that is too
> > late and we have already dropped 1 or 2 frames. Lot of other fields in
> > codecpar are being set from the demuxer like channel_layout, sample_rate
> > etc.
>
> I am aware of the intend, however...
>
> The difference between filling those fields in and this patch, is that we
> can
> read those values directly, generally. This is a guess; a heuristic. A
> heuristic
> based on the GOP structure of a single codec. Where we guess where a GOP
> even
> starts. Nor does it seem to take into account non-friendly files, with
> oddly
> ordered and/or invalid timestamps (which it can't, based solely on PTS).
>
> I'm pretty tired of hitting insane edge cases in other types of files due
> to
> hacks added for some other specific set of file, but used for *everything*.
> This is a recurring theme in FFmpeg, so I'm trying to fight hard to keep
> more out...
>
It is true that the patch will fail to compute the correct delay in lots of
cases. However the consequence of wrongly computing the has_b_frames is
pretty benign. It only increases the buffer size held for PTS  reordering.
I can put a max-value check on the computed video_delay here. So in my
opinion, we won't see fatal regressions where a file is not able to be
decoded / played.


>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-14 Thread Sasi Inguva
For H264 files with no bitstream restriction flag, we aren't able to guess
the delay correctly. Especially if it's MOV container, because for MOV
container we just probe the 1st frame and stop in avformat_find_streaminfo .

When we are decoding , we increase the has_b_frames value from zero to 1 or
2, when we eventually encounter B-frames in H264 decoder, but that is too
late and we have already dropped 1 or 2 frames. Lot of other fields in
codecpar are being set from the demuxer like channel_layout, sample_rate
etc.

On Tue, Nov 14, 2017 at 10:06 AM, Derek Buitenhuis <
derek.buitenh...@gmail.com> wrote:

> On 11/14/2017 2:15 AM, Sasi Inguva wrote:
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/mov.c| 48 ++
> ++
> >  tests/fate/mov.mak   |  5 +
> >  tests/ref/fate/mov-guess-delay-1 |  3 +++
> >  tests/ref/fate/mov-guess-delay-2 |  3 +++
> >  4 files changed, 59 insertions(+)
> >  create mode 100644 tests/ref/fate/mov-guess-delay-1
> >  create mode 100644 tests/ref/fate/mov-guess-delay-2
>
> Going to play the part of wm4 here.
>
> This seems like one giant hack to me (and potentially yet more slowness
> during init/index).
>
> Should we *really* be populating codecpar with a heuristic guess and
> should we *really* be putting this in one specific demuxer?
>
> Seems pretty gross to me.
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Don't correct edit list start to zero, when we can't find a frame before edit list start. After c2a8f0fcbe57ea9ccaa864130f078af10516c3c1 this can happen on normal ed

2017-11-13 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c|   4 +-
 tests/fate/mov.mak   |   6 +
 tests/ref/fate/mov-bbi-elst-starts-b | 391 +++
 3 files changed, 398 insertions(+), 3 deletions(-)
 create mode 100644 tests/ref/fate/mov-bbi-elst-starts-b

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..79023ef369 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3380,13 +3380,11 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 if (find_prev_closest_index(st, e_old, nb_old, ctts_data_old, 
ctts_count_old, search_timestamp, AVSEEK_FLAG_ANY,
 , _index_old, 
_sample_old) < 0) {
 av_log(mov->fc, AV_LOG_WARNING,
-   "st: %d edit list %"PRId64" Cannot find an index entry 
before timestamp: %"PRId64".\n"
-   "Rounding edit list media time to zero.\n",
+   "st: %d edit list %"PRId64" Cannot find an index entry 
before timestamp: %"PRId64".\n",
st->index, edit_list_index, search_timestamp);
 index = 0;
 ctts_index_old = 0;
 ctts_sample_old = 0;
-edit_list_media_time = 0;
 }
 }
 current = e_old + index;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..c1a3d154e0 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-bbi-elst-starts-b \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -59,6 +60,11 @@ fate-mov-invalid-elst-entry-count: CMD = framemd5 -flags 
+bitexact -i $(TARGET_S
 # i.e.  Pts Order: I-B-I
 fate-mov-ibi-elst-starts-b: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/mov/mov_ibi_elst_starts_b.mov
 
+# Makes sure that we pick the right frames according to edit list when there 
is no keyframe with PTS < edit list start.
+# For example, when video starts on a B-frame, and edit list starts on that 
B-frame too.
+# GOP structure : B B I in presentation order.
+fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/h264/twofields_packet.mp4
+
 fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets 
-print_format compact $(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
 fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams 
-show_packets -show_frames -bitexact -print_format compact 
$(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
diff --git a/tests/ref/fate/mov-bbi-elst-starts-b 
b/tests/ref/fate/mov-bbi-elst-starts-b
new file mode 100644
index 00..d3ede1a86c
--- /dev/null
+++ b/tests/ref/fate/mov-bbi-elst-starts-b
@@ -0,0 +1,391 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1001/3
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1920x1080
+#sar 0: 1/1
+#tb 1: 1/48000
+#media_type 1: audio
+#codec_id 1: pcm_s16le
+#sample_rate 1: 48000
+#channel_layout 1: 3
+#channel_layout_name 1: stereo
+#stream#, dts,pts, duration, size, hash
+0,  0,  0,1,  3110400, e9454409af76038dbe56e834921d2fa8
+1,  0,  0, 1024, 4096, 620f0b67a91f7f74151bc5be745b7110
+1,   1024,   1024, 1024, 4096, 8ab1a8e40b154f577914e43ec6cdc674
+0,  1,  1,1,  3110400, 37aa620e494d22ba248feea9a5a869a0
+1,   2048,   2048, 1024, 4096, 41f09b125271955596ef56436e5ae7b3
+1,   3072,   3072, 1024, 4096, e4934aa9fbaf7dcd578fe9f404bfdd39
+0,  2,  2,1,  3110400, 7b8be9619e4e1d618ab1ed85aff3957b
+1,   4096,   4096, 1024, 4096, 5321f9a453ff71e420b592c9188560f4
+0,  3,  3,1,  3110400, 756a4551420853bc3ae444e6b86169f3
+1,   5120,   5120, 1024, 4096, fa45be5ec01b9c0ae78f876f290602e2
+1,   6144,   6144, 1024, 4096, bce7b47534cf6ae5db1fa27805fd52a6
+0,  4,  4,1,  3110400, 94a93c1669a96ebf41a7258177849396
+1,   7168,   7168, 1024, 4096, 15f899020d6e186b2f2a15b60034fa26
+0,  5,  5,1,  3110400, 5d1c49d3f43cd472683e4a039e376af5
+1,   8192,   8192, 1024, 4096, 9038d943078707eac0eff9126911b9d0
+1,   9216,   9216, 1024, 4096, 40dced7d76db2c011be7b04f1c6e9236
+0,  6,  6,1,  3110400, e0e88cc34b0a9d7963cddf554a3909f0
+1,  10240,  10240, 1024, 4096, eadb875a43a9b7b89c371af7ca8da51d
+0,  7,  7,1,  3110400, 1f464f2427aa3842224803b6d67154f8
+1,  11264,  11264, 1024,  

[FFmpeg-devel] [PATCH] lavf/mov.c: Guess video codec delay based on PTS while parsing MOV header.

2017-11-13 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 48 
 tests/fate/mov.mak   |  5 +
 tests/ref/fate/mov-guess-delay-1 |  3 +++
 tests/ref/fate/mov-guess-delay-2 |  3 +++
 4 files changed, 59 insertions(+)
 create mode 100644 tests/ref/fate/mov-guess-delay-1
 create mode 100644 tests/ref/fate/mov-guess-delay-2

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..91c6987a96 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3213,6 +3213,52 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 return *ctts_count;
 }
 
+static void mov_guess_video_delay(MOVContext *c, AVStream* st) {
+MOVStreamContext *msc = st->priv_data;
+int ind;
+int ctts_ind = 0;
+int ctts_sample = 0;
+int64_t curr_pts = AV_NOPTS_VALUE;
+int64_t prev_pts = AV_NOPTS_VALUE;
+int64_t prev_max_pts = AV_NOPTS_VALUE;
+int num_swaps = 0;
+
+if (msc->ctts_data) {
+st->codecpar->video_delay = 0;
+for(ind = 0; ind < st->nb_index_entries && ctts_ind < msc->ctts_count; 
++ind) {
+curr_pts = st->index_entries[ind].timestamp + 
msc->ctts_data[ctts_ind].duration;
+
+// This is used as an indication that the previous GOP has ended 
and a
+// new GOP has started.
+if (curr_pts > prev_max_pts) {
+st->codecpar->video_delay = FFMAX(st->codecpar->video_delay, 
num_swaps);
+num_swaps = 0;
+prev_max_pts = curr_pts;
+}
+
+// Compute delay as the no. of "drop"s in PTS inside a GOP.
+// Frames: I0 I1 B0 B1 B2
+// PTS: 0  4  1  2  3 -> num_swaps = delay = 1 (4->1)
+//
+// Frames: I0 I1 B1 B0 B2
+// PTS: 0  4  2  1  3 -> num_swaps = delay = 2 (4->2, 2->1)
+if (prev_pts != AV_NOPTS_VALUE) {
+if (curr_pts < prev_pts)
+++num_swaps;
+}
+
+prev_pts = curr_pts;
+ctts_sample++;
+if (ctts_sample == msc->ctts_data[ctts_ind].count) {
+ctts_ind++;
+ctts_sample = 0;
+}
+}
+av_log(c->fc, AV_LOG_DEBUG, "Setting codecpar->delay to %d for stream 
st: %d\n",
+   st->codecpar->video_delay, st->index);
+}
+}
+
 static void mov_current_sample_inc(MOVStreamContext *sc)
 {
 sc->current_sample++;
@@ -3846,6 +3892,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 // Fix index according to edit lists.
 mov_fix_index(mov, st);
 }
+
+mov_guess_video_delay(mov, st);
 }
 
 static int test_same_origin(const char *src, const char *ref) {
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..ef89e62096 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,8 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-guess-delay-1 \
+   fate-mov-guess-delay-2 \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -72,3 +74,6 @@ fate-mov-spherical-mono: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_entries str
 fate-mov-gpmf-remux: CMD = md5 -i 
$(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags 
+bitexact -f mp4
 fate-mov-gpmf-remux: CMP = oneline
 fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
+
+fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
+fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
\ No newline at end of file
diff --git a/tests/ref/fate/mov-guess-delay-1 b/tests/ref/fate/mov-guess-delay-1
new file mode 100644
index 00..96cb67be0c
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-1
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=1
+[/STREAM]
diff --git a/tests/ref/fate/mov-guess-delay-2 b/tests/ref/fate/mov-guess-delay-2
new file mode 100644
index 00..248de1c3ea
--- /dev/null
+++ b/tests/ref/fate/mov-guess-delay-2
@@ -0,0 +1,3 @@
+[STREAM]
+has_b_frames=2
+[/STREAM]
-- 
2.15.0.448.gf294e3d99a-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Don't correct edit list start to zero, when we can't find a frame before edit list start. After c2a8f0fcbe57ea9ccaa864130f078af10516c3c1 this can happen on norma

2017-11-13 Thread Sasi Inguva
Forgot the fate REF file. Sending the full patch again.

On Mon, Nov 13, 2017 at 4:15 PM, Sasi Inguva <is...@google.com> wrote:

> Signed-off-by: Sasi Inguva <is...@google.com>
> ---
>  libavformat/mov.c  | 4 +---
>  tests/fate/mov.mak | 6 ++
>  2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index fd170baa57..79023ef369 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3380,13 +3380,11 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
>  if (find_prev_closest_index(st, e_old, nb_old, ctts_data_old,
> ctts_count_old, search_timestamp, AVSEEK_FLAG_ANY,
>  , _index_old,
> _sample_old) < 0) {
>  av_log(mov->fc, AV_LOG_WARNING,
> -   "st: %d edit list %"PRId64" Cannot find an index
> entry before timestamp: %"PRId64".\n"
> -   "Rounding edit list media time to zero.\n",
> +   "st: %d edit list %"PRId64" Cannot find an index
> entry before timestamp: %"PRId64".\n",
> st->index, edit_list_index, search_timestamp);
>  index = 0;
>  ctts_index_old = 0;
>  ctts_sample_old = 0;
> -edit_list_media_time = 0;
>  }
>  }
>  current = e_old + index;
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 76f66ff498..c1a3d154e0 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -11,6 +11,7 @@ FATE_MOV = fate-mov-3elist \
> fate-mov-440hz-10ms \
> fate-mov-ibi-elst-starts-b \
> fate-mov-elst-ends-betn-b-and-i \
> +   fate-mov-bbi-elst-starts-b \
>
>  FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
> fate-mov-zombie \
> @@ -59,6 +60,11 @@ fate-mov-invalid-elst-entry-count: CMD = framemd5
> -flags +bitexact -i $(TARGET_S
>  # i.e.  Pts Order: I-B-I
>  fate-mov-ibi-elst-starts-b: CMD = framemd5 -flags +bitexact -i
> $(TARGET_SAMPLES)/mov/mov_ibi_elst_starts_b.mov
>
> +# Makes sure that we pick the right frames according to edit list when
> there is no keyframe with PTS < edit list start.
> +# For example, when video starts on a B-frame, and edit list starts on
> that B-frame too.
> +# GOP structure : B B I in presentation order.
> +fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -i
> $(TARGET_SAMPLES)/h264/twofields_packet.mp4
> +
>  fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF)
> -show_packets -print_format compact $(TARGET_SAMPLES)/mov/aac-
> 2048-priming.mov
>
>  fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams
> -show_packets -show_frames -bitexact -print_format compact
> $(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
> --
> 2.15.0.448.gf294e3d99a-goog
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Don't correct edit list start to zero, when we can't find a frame before edit list start. After c2a8f0fcbe57ea9ccaa864130f078af10516c3c1 this can happen on normal ed

2017-11-13 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c  | 4 +---
 tests/fate/mov.mak | 6 ++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index fd170baa57..79023ef369 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3380,13 +3380,11 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 if (find_prev_closest_index(st, e_old, nb_old, ctts_data_old, 
ctts_count_old, search_timestamp, AVSEEK_FLAG_ANY,
 , _index_old, 
_sample_old) < 0) {
 av_log(mov->fc, AV_LOG_WARNING,
-   "st: %d edit list %"PRId64" Cannot find an index entry 
before timestamp: %"PRId64".\n"
-   "Rounding edit list media time to zero.\n",
+   "st: %d edit list %"PRId64" Cannot find an index entry 
before timestamp: %"PRId64".\n",
st->index, edit_list_index, search_timestamp);
 index = 0;
 ctts_index_old = 0;
 ctts_sample_old = 0;
-edit_list_media_time = 0;
 }
 }
 current = e_old + index;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 76f66ff498..c1a3d154e0 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -11,6 +11,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
fate-mov-elst-ends-betn-b-and-i \
+   fate-mov-bbi-elst-starts-b \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -59,6 +60,11 @@ fate-mov-invalid-elst-entry-count: CMD = framemd5 -flags 
+bitexact -i $(TARGET_S
 # i.e.  Pts Order: I-B-I
 fate-mov-ibi-elst-starts-b: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/mov/mov_ibi_elst_starts_b.mov
 
+# Makes sure that we pick the right frames according to edit list when there 
is no keyframe with PTS < edit list start.
+# For example, when video starts on a B-frame, and edit list starts on that 
B-frame too.
+# GOP structure : B B I in presentation order.
+fate-mov-bbi-elst-starts-b: CMD = framemd5 -flags +bitexact -i 
$(TARGET_SAMPLES)/h264/twofields_packet.mp4
+
 fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets 
-print_format compact $(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
 fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams 
-show_packets -show_frames -bitexact -print_format compact 
$(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
-- 
2.15.0.448.gf294e3d99a-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-09 Thread Sasi Inguva
Partially fixes t/6699.
---
 libavformat/mov.c | 32 +++---
 tests/fate/mov.mak|  4 
 tests/ref/fate/mov-elst-ends-betn-b-and-i | 33 +++
 3 files changed, 58 insertions(+), 11 deletions(-)
 create mode 100644 tests/ref/fate/mov-elst-ends-betn-b-and-i

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 7954db6e47..436ae42cbb 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3295,6 +3295,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int packet_skip_samples = 0;
 MOVIndexRange *current_index_range;
 int i;
+int found_keyframe_after_edit = 0;
 
 if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
 return;
@@ -3390,6 +3391,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // Iterate over index and arrange it according to edit list
 edit_list_start_encountered = 0;
+found_keyframe_after_edit = 0;
 for (; current < e_old_end; current++, index++) {
 // check  if frame outside edit list mark it for discard
 frame_duration = (current + 1 <  e_old_end) ?
@@ -3502,18 +3504,26 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 
 // Break when found first key frame after edit entry completion
-if (((curr_cts + frame_duration) >= (edit_list_duration + 
edit_list_media_time)) &&
+if ((curr_cts + frame_duration >= (edit_list_duration + 
edit_list_media_time)) &&
 ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type == 
AVMEDIA_TYPE_AUDIO {
-
-if (ctts_data_old && ctts_sample_old != 0) {
-if (add_ctts_entry(>ctts_data, >ctts_count,
-   >ctts_allocated_size,
-   ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration) 
== -1) {
-av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry 
%"PRId64" - {%"PRId64", %d}\n",
-   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration);
-break;
+if (ctts_data_old) {
+// If we have CTTS and this is the the first keyframe 
after edit elist,
+// wait for one more, because there might be trailing 
B-frames after this I-frame
+// that do belong to the edit.
+if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && 
found_keyframe_after_edit == 0) {
+found_keyframe_after_edit = 1;
+continue;
+}
+if (ctts_sample_old != 0) {
+if (add_ctts_entry(>ctts_data, >ctts_count,
+   >ctts_allocated_size,
+   ctts_sample_old - 
edit_list_start_ctts_sample,
+   
ctts_data_old[ctts_index_old].duration) == -1) {
+av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS 
entry %"PRId64" - {%"PRId64", %d}\n",
+   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
+   ctts_data_old[ctts_index_old].duration);
+break;
+}
 }
 }
 break;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 01893a0767..76f66ff498 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -10,6 +10,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-gpmf-remux \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
+   fate-mov-elst-ends-betn-b-and-i \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -42,6 +43,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-1e
 # Makes sure that we handle timestamps of packets in case of multiple edit 
lists with one of them ending on a B-frame correctly.
 fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-2elist-elist1-ends-bframe.mov
 
+# Makes sure that if edit list ends on a B-frame but before the I-frame, then 
we output the B-frame but discard the I-frame.
+fate-mov-elst-ends-betn-b-and-i: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/elst_ends_betn_b_and_i.mp4
+
 # Makes sure that we handle edit lists and start padding correctly.
 fate-mov-440hz-10ms: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/440hz-10ms.m4a
 
diff --git a/tests/ref/fate/mov-elst-ends-betn-b-and-i 
b/tests/ref/fate/mov-elst-ends-betn-b-and-i
new file mode 100644
index 00..d6f325bba2
--- /dev/null
+++ 

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-09 Thread Sasi Inguva
Sorry, about this. i had uncommitted changes. Attaching the patch.

On Thu, Nov 9, 2017 at 12:22 PM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Wed, Nov 08, 2017 at 04:13:46PM -0800, Sasi Inguva wrote:
> > Partially fixes t/6699.
> > ---
> >  libavformat/mov.c | 32
> ---
> >  tests/fate/mov.mak|  4 
> >  tests/ref/fate/mov-elst-ends-betn-b-and-i | 31
> ++
> >  3 files changed, 56 insertions(+), 11 deletions(-)
> >  create mode 100644 tests/ref/fate/mov-elst-ends-betn-b-and-i
>
> seems not passing fate here or i did something silly
>
> --- ./tests/ref/fate/mov-elst-ends-betn-b-and-i 2017-11-09 21:14:
> 14.425558802 +0100
> +++ tests/data/fate/mov-elst-ends-betn-b-and-i  2017-11-09
> 21:21:15.957563829 +0100
> @@ -7,25 +7,27 @@
>  #dimensions 0: 320x240
>  #sar 0: 1/1
>  #stream#, dts,pts, duration, size, hash
> -0,  0,  0,1,   115200,
> 4e5dc2b806e394cd666c968f736fecd0
> -0,  1,  1,1,   115200,
> 7a3c7473d44c5f60c07655f6fc0c2ac3
> -0,  2,  2,1,   115200,
> 038254422a603a3270c09cdcd149707b
> -0,  3,  3,1,   115200,
> 7553b6b4547cb23ef8f0392ed5a5d4b0
> -0,  4,  4,1,   115200,
> 6d017ede7f446124af7308667cb0dc41
> -0,  5,  5,1,   115200,
> 77752f0288ae64f857732b8e62e47457
> -0,  6,  6,1,   115200,
> d656833951af99330625f7c6de7685c4
> -0,  7,  7,1,   115200,
> 14338b833e431e566ac98da841600bfe
> -0,  8,  8,1,   115200,
> 07ea95d1659f3c4424a470a546d0df6e
> -0,  9,  9,1,   115200,
> fd05b8cc83072f813e89d394d1f6efc6
> -0, 10, 10,1,   115200,
> 750b82ca5c7e901545e7b1aa69692426
> -0, 11, 11,1,   115200,
> 7347679ab09bc936047368b8caebcaff
> -0, 12, 12,1,   115200,
> 63a23fdd57ac8462b9ffbcb12ab717b3
> -0, 13, 13,1,   115200,
> 705257a1c99693db233e2a3ee027adcf
> -0, 14, 14,1,   115200,
> df861a2ec7a4ef70e82b1c28025e5a48
> -0, 15, 15,1,   115200,
> 2a8b403c077b6b43aa71eaf7d1537713
> -0, 16, 16,1,   115200,
> 973b5cd3ce473e3970dfa96045553172
> -0, 17, 17,1,   115200,
> fc612c0afeae3b6576b5ee2f3f119832
> -0, 18, 18,1,   115200,
> 97074fe5a0b6e7e8470729654092e56c
> -0, 19, 19,1,   115200,
> 8cf9337201065335b3aa4da21dc9b37a
> -0, 20, 20,1,   115200,
> 93ff3589294cc0673af3daee1e7fe42a
> -0, 21, 21,1,   115200,
> c0b6fd870a022f374f9d6c697e8e293d
> +0,  0,  0,1,   115200,
> e10741e5457e9326d5e992e6c05c3e32
> +0,  1,  1,1,   115200,
> 7e20f8729b6b53dc11791927bf4a5aec
> +0,  2,  2,1,   115200,
> 4e5dc2b806e394cd666c968f736fecd0
> +0,  3,  3,1,   115200,
> 7a3c7473d44c5f60c07655f6fc0c2ac3
> +0,  4,  4,1,   115200,
> 038254422a603a3270c09cdcd149707b
> +0,  5,  5,1,   115200,
> 7553b6b4547cb23ef8f0392ed5a5d4b0
> +0,  6,  6,1,   115200,
> 6d017ede7f446124af7308667cb0dc41
> +0,  7,  7,1,   115200,
> 77752f0288ae64f857732b8e62e47457
> +0,  8,  8,1,   115200,
> d656833951af99330625f7c6de7685c4
> +0,  9,  9,1,   115200,
> 14338b833e431e566ac98da841600bfe
> +0, 10, 10,1,   115200,
> 07ea95d1659f3c4424a470a546d0df6e
> +0, 11, 11,1,   115200,
> fd05b8cc83072f813e89d394d1f6efc6
> +0, 12, 12,1,   115200,
> 750b82ca5c7e901545e7b1aa69692426
> +0, 13, 13,1,   115200,
> 7347679ab09bc936047368b8caebcaff
> +0, 14, 14,1,   115200,
> 63a23fdd57ac8462b9ffbcb12ab717b3
> +0, 15, 15,1,   115200,
> 705257a1c99693db233e2a3ee027adcf
> +0, 16, 16,1,   115200,
> df861a2ec7a4ef70e82b1c28025e5a48
> +0, 17, 17,1,   115200,
> 2a8b403c077b6b43aa71eaf7d1537713
> +0, 18, 18,1,   115200,
> 973b5cd3ce473e3970dfa96045553172
> +0, 19, 19,1,   115200,
> fc612c0afeae3b6576b5ee2f3f119832
> +0, 20, 20,1,   115200,
> 97074fe5a0b6e7e8470729654092e56c
> +0, 21, 21,

[FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-08 Thread Sasi Inguva
Partially fixes t/6699.
---
 libavformat/mov.c | 32 ---
 tests/fate/mov.mak|  4 
 tests/ref/fate/mov-elst-ends-betn-b-and-i | 31 ++
 3 files changed, 56 insertions(+), 11 deletions(-)
 create mode 100644 tests/ref/fate/mov-elst-ends-betn-b-and-i

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 7954db6e47..436ae42cbb 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3295,6 +3295,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int packet_skip_samples = 0;
 MOVIndexRange *current_index_range;
 int i;
+int found_keyframe_after_edit = 0;
 
 if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
 return;
@@ -3390,6 +3391,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // Iterate over index and arrange it according to edit list
 edit_list_start_encountered = 0;
+found_keyframe_after_edit = 0;
 for (; current < e_old_end; current++, index++) {
 // check  if frame outside edit list mark it for discard
 frame_duration = (current + 1 <  e_old_end) ?
@@ -3502,18 +3504,26 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 
 // Break when found first key frame after edit entry completion
-if (((curr_cts + frame_duration) >= (edit_list_duration + 
edit_list_media_time)) &&
+if ((curr_cts + frame_duration >= (edit_list_duration + 
edit_list_media_time)) &&
 ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type == 
AVMEDIA_TYPE_AUDIO {
-
-if (ctts_data_old && ctts_sample_old != 0) {
-if (add_ctts_entry(>ctts_data, >ctts_count,
-   >ctts_allocated_size,
-   ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration) 
== -1) {
-av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry 
%"PRId64" - {%"PRId64", %d}\n",
-   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration);
-break;
+if (ctts_data_old) {
+// If we have CTTS and this is the the first keyframe 
after edit elist,
+// wait for one more, because there might be trailing 
B-frames after this I-frame
+// that do belong to the edit.
+if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && 
found_keyframe_after_edit == 0) {
+found_keyframe_after_edit = 1;
+continue;
+}
+if (ctts_sample_old != 0) {
+if (add_ctts_entry(>ctts_data, >ctts_count,
+   >ctts_allocated_size,
+   ctts_sample_old - 
edit_list_start_ctts_sample,
+   
ctts_data_old[ctts_index_old].duration) == -1) {
+av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS 
entry %"PRId64" - {%"PRId64", %d}\n",
+   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
+   ctts_data_old[ctts_index_old].duration);
+break;
+}
 }
 }
 break;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 01893a0767..76f66ff498 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -10,6 +10,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-gpmf-remux \
fate-mov-440hz-10ms \
fate-mov-ibi-elst-starts-b \
+   fate-mov-elst-ends-betn-b-and-i \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -42,6 +43,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-1e
 # Makes sure that we handle timestamps of packets in case of multiple edit 
lists with one of them ending on a B-frame correctly.
 fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-2elist-elist1-ends-bframe.mov
 
+# Makes sure that if edit list ends on a B-frame but before the I-frame, then 
we output the B-frame but discard the I-frame.
+fate-mov-elst-ends-betn-b-and-i: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/elst_ends_betn_b_and_i.mp4
+
 # Makes sure that we handle edit lists and start padding correctly.
 fate-mov-440hz-10ms: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/440hz-10ms.m4a
 
diff --git a/tests/ref/fate/mov-elst-ends-betn-b-and-i 
b/tests/ref/fate/mov-elst-ends-betn-b-and-i
new file mode 100644
index 00..ee7c6389ad
--- /dev/null
+++ 

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-08 Thread Sasi Inguva
Updated the fate test after
http://git.videolan.org/?p=ffmpeg.git;a=commit;h=c2a8f0fcbe57ea9ccaa864130f078af10516c3c1
. Sending the updated patch.

On Thu, Nov 2, 2017 at 4:23 PM, Michael Niedermayer <mich...@niedermayer.cc>
wrote:

> On Wed, Nov 01, 2017 at 02:27:50PM -0700, Sasi Inguva wrote:
> > Pls find attached, the FATE sample.
>
> uplaoded
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> There will always be a question for which you do not know the correct
> answer.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Refine edit list start seek, based on PTS computed from CTTS.

2017-11-02 Thread Sasi Inguva
Modified the comment for find_prev_index function. Thx.

On Thu, Nov 2, 2017 at 4:22 PM, Michael Niedermayer <mich...@niedermayer.cc>
wrote:

> On Tue, Oct 31, 2017 at 04:45:00PM -0700, Sasi Inguva wrote:
> > Attaching the fate sample.
>
> uploaded
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Refine edit list start seek, based on PTS computed from CTTS.

2017-11-02 Thread Sasi Inguva
Partially fixes t/6699.
---
 libavformat/mov.c| 129 +++
 tests/fate/mov.mak   |   8 +++
 tests/ref/fate/mov-ibi-elst-starts-b |  33 +
 3 files changed, 127 insertions(+), 43 deletions(-)
 create mode 100644 tests/ref/fate/mov-ibi-elst-starts-b

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 60f0228e2d..7954db6e47 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3014,34 +3014,99 @@ static int get_edit_list_entry(MOVContext *mov,
 }
 
 /**
- * Find the closest previous frame to the timestamp, in e_old index
+ * Find the closest previous frame to the timestamp_pts, in e_old index
  * entries. Searching for just any frame / just key frames can be controlled by
  * last argument 'flag'.
- * Returns the index of the entry in st->index_entries if successful,
- * else returns -1.
+ * Note that if ctts_data is not NULL, we will always search for a key frame
+ * irrespective of the value of 'flag'. If we don't find any keyframe, we will
+ * return the first frame of the video.
+ *
+ * Here the timestamp_pts is considered to be a presentation timestamp and
+ * the timestamp of index entries are considered to be decoding timestamps.
+ *
+ * Returns 0 if successful in finding a frame, else returns -1.
+ * Places the found index corresponding output arg.
+ *
+ * If ctts_old is not NULL, then refines the searched entry by searching
+ * backwards from the found timestamp, to find the frame with correct PTS.
+ *
+ * Places the found ctts_index and ctts_sample in corresponding output args.
  */
-static int64_t find_prev_closest_index(AVStream *st,
-   AVIndexEntry *e_old,
-   int nb_old,
-   int64_t timestamp,
-   int flag)
+static int find_prev_closest_index(AVStream *st,
+   AVIndexEntry *e_old,
+   int nb_old,
+   MOVStts* ctts_data,
+   int64_t ctts_count,
+   int64_t timestamp_pts,
+   int flag,
+   int64_t* index,
+   int64_t* ctts_index,
+   int64_t* ctts_sample)
 {
+MOVStreamContext *msc = st->priv_data;
 AVIndexEntry *e_keep = st->index_entries;
 int nb_keep = st->nb_index_entries;
-int64_t found = -1;
 int64_t i = 0;
+int64_t index_ctts_count;
+
+av_assert0(index);
+
+// If dts_shift > 0, then all the index timestamps will have to be offset 
by
+// at least dts_shift amount to obtain PTS.
+// Hence we decrement the searched timestamp_pts by dts_shift to find the 
closest index element.
+if (msc->dts_shift > 0) {
+timestamp_pts -= msc->dts_shift;
+}
 
 st->index_entries = e_old;
 st->nb_index_entries = nb_old;
-found = av_index_search_timestamp(st, timestamp, flag | 
AVSEEK_FLAG_BACKWARD);
+*index = av_index_search_timestamp(st, timestamp_pts, flag | 
AVSEEK_FLAG_BACKWARD);
 
 // Keep going backwards in the index entries until the timestamp is the 
same.
-if (found >= 0) {
-for (i = found; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
+if (*index >= 0) {
+for (i = *index; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
  i--) {
 if ((flag & AVSEEK_FLAG_ANY) ||
 (e_old[i - 1].flags & AVINDEX_KEYFRAME)) {
-found = i - 1;
+*index = i - 1;
+}
+}
+}
+
+// If we have CTTS then refine the search, by searching backwards over PTS
+// computed by adding corresponding CTTS durations to index timestamps.
+if (ctts_data && *index >= 0) {
+av_assert0(ctts_index);
+av_assert0(ctts_sample);
+// Find out the ctts_index for the found frame.
+*ctts_index = 0;
+*ctts_sample = 0;
+for (index_ctts_count = 0; index_ctts_count < *index; 
index_ctts_count++) {
+if (*ctts_index < ctts_count) {
+(*ctts_sample)++;
+if (ctts_data[*ctts_index].count == *ctts_sample) {
+(*ctts_index)++;
+*ctts_sample = 0;
+}
+}
+}
+
+while (*index >= 0 && (*ctts_index) >= 0) {
+// Find a "key frame" with PTS <= timestamp_pts (So that we can 
decode B-frames correctly).
+// No need to add dts_shift to the timestamp here becase 
timestamp_pts has already been
+// compensated by dts_shift above.
+if ((e_old[*index].timestamp + ctts_data[*ctts_index].duration) <= 
timestamp_pts &&
+(e_old[*index].flags & AVINDEX_KEYFRAME)) {
+break;
+}
+
+(*index)--;
+  

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-01 Thread Sasi Inguva
This patch is not an alternative. Both patches are required to fix
t/6699 . Once
one of the patches is submitted, i will update the fate tests in the other
patch.

On Wed, Nov 1, 2017 at 5:11 PM, Michael Niedermayer <mich...@niedermayer.cc>
wrote:

> On Wed, Nov 01, 2017 at 02:26:45PM -0700, Sasi Inguva wrote:
> > Partially fixes t/6699.
> > ---
> >  libavformat/mov.c | 32
> ---
> >  tests/fate/mov.mak|  4 
> >  tests/ref/fate/mov-elst-ends-betn-b-and-i | 31
> ++
> >  3 files changed, 56 insertions(+), 11 deletions(-)
> >  create mode 100644 tests/ref/fate/mov-elst-ends-betn-b-and-i
>
> Is this inteded as an alternaive to your other patch ?
> both together fail fate:
>
> [...]
> --- ./tests/ref/fate/mov-elst-ends-betn-b-and-i 2017-11-02
> 00:56:36.199196931 +0100
> +++ tests/data/fate/mov-elst-ends-betn-b-and-i  2017-11-02
> 01:03:01.739201528 +0100
> @@ -7,25 +7,27 @@
>  #dimensions 0: 320x240
>  #sar 0: 1/1
>  #stream#, dts,pts, duration, size, hash
> -0,  0,  0,1,   115200,
> 4e5dc2b806e394cd666c968f736fecd0
> -0,  1,  1,1,   115200,
> 7a3c7473d44c5f60c07655f6fc0c2ac3
> -0,  2,  2,1,   115200,
> 038254422a603a3270c09cdcd149707b
> -0,  3,  3,1,   115200,
> 7553b6b4547cb23ef8f0392ed5a5d4b0
> -0,  4,  4,1,   115200,
> 6d017ede7f446124af7308667cb0dc41
> -0,  5,  5,1,   115200,
> 77752f0288ae64f857732b8e62e47457
> -0,  6,  6,1,   115200,
> d656833951af99330625f7c6de7685c4
> -0,  7,  7,1,   115200,
> 14338b833e431e566ac98da841600bfe
> -0,  8,  8,1,   115200,
> 07ea95d1659f3c4424a470a546d0df6e
> -0,  9,  9,1,   115200,
> fd05b8cc83072f813e89d394d1f6efc6
> -0, 10, 10,1,   115200,
> 750b82ca5c7e901545e7b1aa69692426
> -0, 11, 11,1,   115200,
> 7347679ab09bc936047368b8caebcaff
> -0, 12, 12,1,   115200,
> 63a23fdd57ac8462b9ffbcb12ab717b3
> -0, 13, 13,1,   115200,
> 705257a1c99693db233e2a3ee027adcf
> -0, 14, 14,1,   115200,
> df861a2ec7a4ef70e82b1c28025e5a48
> -0, 15, 15,1,   115200,
> 2a8b403c077b6b43aa71eaf7d1537713
> -0, 16, 16,1,   115200,
> 973b5cd3ce473e3970dfa96045553172
> -0, 17, 17,1,   115200,
> fc612c0afeae3b6576b5ee2f3f119832
> -0, 18, 18,1,   115200,
> 97074fe5a0b6e7e8470729654092e56c
> -0, 19, 19,1,   115200,
> 8cf9337201065335b3aa4da21dc9b37a
> -0, 20, 20,1,   115200,
> 93ff3589294cc0673af3daee1e7fe42a
> -0, 21, 21,1,   115200,
> c0b6fd870a022f374f9d6c697e8e293d
> +0,  0,  0,1,   115200,
> e10741e5457e9326d5e992e6c05c3e32
> +0,  1,  1,1,   115200,
> 7e20f8729b6b53dc11791927bf4a5aec
> +0,  2,  2,1,   115200,
> 4e5dc2b806e394cd666c968f736fecd0
> +0,  3,  3,1,   115200,
> 7a3c7473d44c5f60c07655f6fc0c2ac3
> +0,  4,  4,1,   115200,
> 038254422a603a3270c09cdcd149707b
> +0,  5,  5,1,   115200,
> 7553b6b4547cb23ef8f0392ed5a5d4b0
> +0,  6,  6,1,   115200,
> 6d017ede7f446124af7308667cb0dc41
> +0,  7,  7,1,   115200,
> 77752f0288ae64f857732b8e62e47457
> +0,  8,  8,1,   115200,
> d656833951af99330625f7c6de7685c4
> +0,  9,  9,1,   115200,
> 14338b833e431e566ac98da841600bfe
> +0, 10, 10,1,   115200,
> 07ea95d1659f3c4424a470a546d0df6e
> +0, 11, 11,1,   115200,
> fd05b8cc83072f813e89d394d1f6efc6
> +0, 12, 12,1,   115200,
> 750b82ca5c7e901545e7b1aa69692426
> +0, 13, 13,1,   115200,
> 7347679ab09bc936047368b8caebcaff
> +0, 14, 14,1,   115200,
> 63a23fdd57ac8462b9ffbcb12ab717b3
> +0, 15, 15,1,   115200,
> 705257a1c99693db233e2a3ee027adcf
> +0, 16, 16,1,   115200,
> df861a2ec7a4ef70e82b1c28025e5a48
> +0, 17, 17,1,   115200,
> 2a8b403c077b6b43aa71eaf7d1537713
> +0, 18, 18,1,   115200,
> 973b5cd3ce473e3970dfa96045553172
> +0, 19, 19,1,   115200,
> fc612c0afeae3b6576b5ee2f

[FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-01 Thread Sasi Inguva
Partially fixes t/6699.
---
 libavformat/mov.c  | 32 +---
 tests/fate/mov.mak |  4 
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 60f0228e2d..e716e5ba9e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3232,6 +3232,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int packet_skip_samples = 0;
 MOVIndexRange *current_index_range;
 int i;
+int found_keyframe_after_edit = 0;
 
 if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
 return;
@@ -3347,6 +3348,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // Iterate over index and arrange it according to edit list
 edit_list_start_encountered = 0;
+found_keyframe_after_edit = 0;
 for (; current < e_old_end; current++, index++) {
 // check  if frame outside edit list mark it for discard
 frame_duration = (current + 1 <  e_old_end) ?
@@ -3459,18 +3461,26 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 
 // Break when found first key frame after edit entry completion
-if (((curr_cts + frame_duration) >= (edit_list_duration + 
edit_list_media_time)) &&
+if ((curr_cts + frame_duration >= (edit_list_duration + 
edit_list_media_time)) &&
 ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type == 
AVMEDIA_TYPE_AUDIO {
-
-if (ctts_data_old && ctts_sample_old != 0) {
-if (add_ctts_entry(>ctts_data, >ctts_count,
-   >ctts_allocated_size,
-   ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration) 
== -1) {
-av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry 
%"PRId64" - {%"PRId64", %d}\n",
-   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration);
-break;
+if (ctts_data_old) {
+// If we have CTTS and this is the the first keyframe 
after edit elist,
+// wait for one more, because there might be trailing 
B-frames after this I-frame
+// that do belong to the edit.
+if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && 
found_keyframe_after_edit == 0) {
+found_keyframe_after_edit = 1;
+continue;
+}
+if (ctts_sample_old != 0) {
+if (add_ctts_entry(>ctts_data, >ctts_count,
+   >ctts_allocated_size,
+   ctts_sample_old - 
edit_list_start_ctts_sample,
+   
ctts_data_old[ctts_index_old].duration) == -1) {
+av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS 
entry %"PRId64" - {%"PRId64", %d}\n",
+   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
+   ctts_data_old[ctts_index_old].duration);
+break;
+}
 }
 }
 break;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 6815e4feca..e444b1459d 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -9,6 +9,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-invalid-elst-entry-count \
fate-mov-gpmf-remux \
fate-mov-440hz-10ms \
+   fate-mov-elst-ends-betn-b-and-i \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -41,6 +42,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-1e
 # Makes sure that we handle timestamps of packets in case of multiple edit 
lists with one of them ending on a B-frame correctly.
 fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-2elist-elist1-ends-bframe.mov
 
+# Makes sure that if edit list ends on a B-frame but before the I-frame, then 
we output the B-frame but discard the I-frame.
+fate-mov-elst-ends-betn-b-and-i: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/elst_ends_betn_b_and_i.mp4
+
 # Makes sure that we handle edit lists and start padding correctly.
 fate-mov-440hz-10ms: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/440hz-10ms.m4a
 
-- 
2.15.0.403.gc27cc4dac6-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-01 Thread Sasi Inguva
Pls find attached, the FATE sample.


On Wed, Nov 1, 2017 at 2:26 PM, Sasi Inguva <is...@google.com> wrote:

> Partially fixes t/6699.
> ---
>  libavformat/mov.c | 32
> ---
>  tests/fate/mov.mak|  4 
>  tests/ref/fate/mov-elst-ends-betn-b-and-i | 31
> ++
>  3 files changed, 56 insertions(+), 11 deletions(-)
>  create mode 100644 tests/ref/fate/mov-elst-ends-betn-b-and-i
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 60f0228e2d..e716e5ba9e 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3232,6 +3232,7 @@ static void mov_fix_index(MOVContext *mov, AVStream
> *st)
>  int packet_skip_samples = 0;
>  MOVIndexRange *current_index_range;
>  int i;
> +int found_keyframe_after_edit = 0;
>
>  if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
>  return;
> @@ -3347,6 +3348,7 @@ static void mov_fix_index(MOVContext *mov, AVStream
> *st)
>
>  // Iterate over index and arrange it according to edit list
>  edit_list_start_encountered = 0;
> +found_keyframe_after_edit = 0;
>  for (; current < e_old_end; current++, index++) {
>  // check  if frame outside edit list mark it for discard
>  frame_duration = (current + 1 <  e_old_end) ?
> @@ -3459,18 +3461,26 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
>  }
>
>  // Break when found first key frame after edit entry
> completion
> -if (((curr_cts + frame_duration) >= (edit_list_duration +
> edit_list_media_time)) &&
> +if ((curr_cts + frame_duration >= (edit_list_duration +
> edit_list_media_time)) &&
>  ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type
> == AVMEDIA_TYPE_AUDIO {
> -
> -if (ctts_data_old && ctts_sample_old != 0) {
> -if (add_ctts_entry(>ctts_data, >ctts_count,
> -   >ctts_allocated_size,
> -   ctts_sample_old -
> edit_list_start_ctts_sample,
> -   
> ctts_data_old[ctts_index_old].duration)
> == -1) {
> -av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS
> entry %"PRId64" - {%"PRId64", %d}\n",
> -   ctts_index_old, ctts_sample_old -
> edit_list_start_ctts_sample,
> -   ctts_data_old[ctts_index_old].duration);
> -break;
> +if (ctts_data_old) {
> +// If we have CTTS and this is the the first keyframe
> after edit elist,
> +// wait for one more, because there might be trailing
> B-frames after this I-frame
> +// that do belong to the edit.
> +if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
> found_keyframe_after_edit == 0) {
> +found_keyframe_after_edit = 1;
> +continue;
> +}
> +if (ctts_sample_old != 0) {
> +if (add_ctts_entry(>ctts_data,
> >ctts_count,
> +   >ctts_allocated_size,
> +   ctts_sample_old -
> edit_list_start_ctts_sample,
> +   
> ctts_data_old[ctts_index_old].duration)
> == -1) {
> +av_log(mov->fc, AV_LOG_ERROR, "Cannot add
> CTTS entry %"PRId64" - {%"PRId64", %d}\n",
> +   ctts_index_old, ctts_sample_old -
> edit_list_start_ctts_sample,
> +   ctts_data_old[ctts_index_old].
> duration);
> +break;
> +}
>  }
>  }
>  break;
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 6815e4feca..e444b1459d 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -9,6 +9,7 @@ FATE_MOV = fate-mov-3elist \
> fate-mov-invalid-elst-entry-count \
> fate-mov-gpmf-remux \
> fate-mov-440hz-10ms \
> +   fate-mov-elst-ends-betn-b-and-i \
>
>  FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
> fate-mov-zombie \
> @@ -41,6 +42,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i
> $(TARGET_SAMPLES)/mov/mov-1e
>  # Makes sure that we hand

[FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-01 Thread Sasi Inguva
Partially fixes t/6699.
---
 libavformat/mov.c | 32 ---
 tests/fate/mov.mak|  4 
 tests/ref/fate/mov-elst-ends-betn-b-and-i | 31 ++
 3 files changed, 56 insertions(+), 11 deletions(-)
 create mode 100644 tests/ref/fate/mov-elst-ends-betn-b-and-i

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 60f0228e2d..e716e5ba9e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3232,6 +3232,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int packet_skip_samples = 0;
 MOVIndexRange *current_index_range;
 int i;
+int found_keyframe_after_edit = 0;
 
 if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
 return;
@@ -3347,6 +3348,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // Iterate over index and arrange it according to edit list
 edit_list_start_encountered = 0;
+found_keyframe_after_edit = 0;
 for (; current < e_old_end; current++, index++) {
 // check  if frame outside edit list mark it for discard
 frame_duration = (current + 1 <  e_old_end) ?
@@ -3459,18 +3461,26 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 
 // Break when found first key frame after edit entry completion
-if (((curr_cts + frame_duration) >= (edit_list_duration + 
edit_list_media_time)) &&
+if ((curr_cts + frame_duration >= (edit_list_duration + 
edit_list_media_time)) &&
 ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type == 
AVMEDIA_TYPE_AUDIO {
-
-if (ctts_data_old && ctts_sample_old != 0) {
-if (add_ctts_entry(>ctts_data, >ctts_count,
-   >ctts_allocated_size,
-   ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration) 
== -1) {
-av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry 
%"PRId64" - {%"PRId64", %d}\n",
-   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
-   ctts_data_old[ctts_index_old].duration);
-break;
+if (ctts_data_old) {
+// If we have CTTS and this is the the first keyframe 
after edit elist,
+// wait for one more, because there might be trailing 
B-frames after this I-frame
+// that do belong to the edit.
+if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && 
found_keyframe_after_edit == 0) {
+found_keyframe_after_edit = 1;
+continue;
+}
+if (ctts_sample_old != 0) {
+if (add_ctts_entry(>ctts_data, >ctts_count,
+   >ctts_allocated_size,
+   ctts_sample_old - 
edit_list_start_ctts_sample,
+   
ctts_data_old[ctts_index_old].duration) == -1) {
+av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS 
entry %"PRId64" - {%"PRId64", %d}\n",
+   ctts_index_old, ctts_sample_old - 
edit_list_start_ctts_sample,
+   ctts_data_old[ctts_index_old].duration);
+break;
+}
 }
 }
 break;
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 6815e4feca..e444b1459d 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -9,6 +9,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-invalid-elst-entry-count \
fate-mov-gpmf-remux \
fate-mov-440hz-10ms \
+   fate-mov-elst-ends-betn-b-and-i \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -41,6 +42,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-1e
 # Makes sure that we handle timestamps of packets in case of multiple edit 
lists with one of them ending on a B-frame correctly.
 fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-2elist-elist1-ends-bframe.mov
 
+# Makes sure that if edit list ends on a B-frame but before the I-frame, then 
we output the B-frame but discard the I-frame.
+fate-mov-elst-ends-betn-b-and-i: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/elst_ends_betn_b_and_i.mp4
+
 # Makes sure that we handle edit lists and start padding correctly.
 fate-mov-440hz-10ms: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/440hz-10ms.m4a
 
diff --git a/tests/ref/fate/mov-elst-ends-betn-b-and-i 
b/tests/ref/fate/mov-elst-ends-betn-b-and-i
new file mode 100644
index 00..ee7c6389ad
--- /dev/null
+++ 

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index.

2017-11-01 Thread Sasi Inguva
Forgot to attach the FATE ref file. sending the patch again.

On Wed, Nov 1, 2017 at 2:23 PM, Sasi Inguva <is...@google.com> wrote:

> Partially fixes t/6699.
> ---
>  libavformat/mov.c  | 32 +---
>  tests/fate/mov.mak |  4 
>  2 files changed, 25 insertions(+), 11 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 60f0228e2d..e716e5ba9e 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3232,6 +3232,7 @@ static void mov_fix_index(MOVContext *mov, AVStream
> *st)
>  int packet_skip_samples = 0;
>  MOVIndexRange *current_index_range;
>  int i;
> +int found_keyframe_after_edit = 0;
>
>  if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
>  return;
> @@ -3347,6 +3348,7 @@ static void mov_fix_index(MOVContext *mov, AVStream
> *st)
>
>  // Iterate over index and arrange it according to edit list
>  edit_list_start_encountered = 0;
> +found_keyframe_after_edit = 0;
>  for (; current < e_old_end; current++, index++) {
>  // check  if frame outside edit list mark it for discard
>  frame_duration = (current + 1 <  e_old_end) ?
> @@ -3459,18 +3461,26 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
>  }
>
>  // Break when found first key frame after edit entry
> completion
> -if (((curr_cts + frame_duration) >= (edit_list_duration +
> edit_list_media_time)) &&
> +if ((curr_cts + frame_duration >= (edit_list_duration +
> edit_list_media_time)) &&
>  ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type
> == AVMEDIA_TYPE_AUDIO {
> -
> -if (ctts_data_old && ctts_sample_old != 0) {
> -if (add_ctts_entry(>ctts_data, >ctts_count,
> -   >ctts_allocated_size,
> -   ctts_sample_old -
> edit_list_start_ctts_sample,
> -   
> ctts_data_old[ctts_index_old].duration)
> == -1) {
> -av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS
> entry %"PRId64" - {%"PRId64", %d}\n",
> -   ctts_index_old, ctts_sample_old -
> edit_list_start_ctts_sample,
> -   ctts_data_old[ctts_index_old].duration);
> -break;
> +if (ctts_data_old) {
> +// If we have CTTS and this is the the first keyframe
> after edit elist,
> +// wait for one more, because there might be trailing
> B-frames after this I-frame
> +// that do belong to the edit.
> +if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
> found_keyframe_after_edit == 0) {
> +found_keyframe_after_edit = 1;
> +continue;
> +}
> +if (ctts_sample_old != 0) {
> +if (add_ctts_entry(>ctts_data,
> >ctts_count,
> +   >ctts_allocated_size,
> +   ctts_sample_old -
> edit_list_start_ctts_sample,
> +   
> ctts_data_old[ctts_index_old].duration)
> == -1) {
> +av_log(mov->fc, AV_LOG_ERROR, "Cannot add
> CTTS entry %"PRId64" - {%"PRId64", %d}\n",
> +   ctts_index_old, ctts_sample_old -
> edit_list_start_ctts_sample,
> +   ctts_data_old[ctts_index_old].
> duration);
> +break;
> +}
>  }
>  }
>  break;
> diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
> index 6815e4feca..e444b1459d 100644
> --- a/tests/fate/mov.mak
> +++ b/tests/fate/mov.mak
> @@ -9,6 +9,7 @@ FATE_MOV = fate-mov-3elist \
> fate-mov-invalid-elst-entry-count \
> fate-mov-gpmf-remux \
> fate-mov-440hz-10ms \
> +   fate-mov-elst-ends-betn-b-and-i \
>
>  FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
> fate-mov-zombie \
> @@ -41,6 +42,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i
> $(TARGET_SAMPLES)/mov/mov-1e
>  # Makes sure that we handle timestamps of packets in case of multiple
> edit lists with one of them ending on a B-frame correctly.
>  fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i
> $(TARGET_SAM

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Refine edit list start seek, based on PTS computed from CTTS.

2017-10-31 Thread Sasi Inguva
Thanks. Sent the corrected patch.

On Tue, Oct 31, 2017 at 7:14 PM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Tue, Oct 31, 2017 at 04:42:56PM -0700, Sasi Inguva wrote:
> > Partially fixes t/6699.
> > ---
> >  libavformat/mov.c  | 125 ++
> +--
> >  tests/fate/mov.mak |   8 
> >  2 files changed, 90 insertions(+), 43 deletions(-)
>
> Missing: ./tests/ref/fate/mov-ibi-elst-starts-b
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Awnsering whenever a program halts or runs forever is
> On a turing machine, in general impossible (turings halting problem).
> On any real computer, always possible as a real computer has a finite
> number
> of states N, and will either halt in less than N cycles or never halt.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Refine edit list start seek, based on PTS computed from CTTS.

2017-10-31 Thread Sasi Inguva
Partially fixes t/6699.
---
 libavformat/mov.c| 125 +++
 tests/fate/mov.mak   |   8 +++
 tests/ref/fate/mov-ibi-elst-starts-b |  33 +
 3 files changed, 123 insertions(+), 43 deletions(-)
 create mode 100644 tests/ref/fate/mov-ibi-elst-starts-b

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 60f0228e2d..a295445651 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3014,34 +3014,95 @@ static int get_edit_list_entry(MOVContext *mov,
 }
 
 /**
- * Find the closest previous frame to the timestamp, in e_old index
+ * Find the closest previous frame to the timestamp_pts, in e_old index
  * entries. Searching for just any frame / just key frames can be controlled by
  * last argument 'flag'.
- * Returns the index of the entry in st->index_entries if successful,
- * else returns -1.
+ * Here the timestamp_pts is considered to be a presentation timestamp and
+ * the timestamp of index entries are considered to be decoding timestamps.
+ *
+ * Returns 0 if successful in finding a frame, else returns -1.
+ * Places the found index corresponding output arg.
+ *
+ * If ctts_old is not NULL, then refines the searched entry by searching
+ * backwards from the found timestamp, to find the frame with correct PTS.
+ *
+ * Places the found ctts_index and ctts_sample in corresponding output args.
  */
-static int64_t find_prev_closest_index(AVStream *st,
-   AVIndexEntry *e_old,
-   int nb_old,
-   int64_t timestamp,
-   int flag)
+static int find_prev_closest_index(AVStream *st,
+   AVIndexEntry *e_old,
+   int nb_old,
+   MOVStts* ctts_data,
+   int64_t ctts_count,
+   int64_t timestamp_pts,
+   int flag,
+   int64_t* index,
+   int64_t* ctts_index,
+   int64_t* ctts_sample)
 {
+MOVStreamContext *msc = st->priv_data;
 AVIndexEntry *e_keep = st->index_entries;
 int nb_keep = st->nb_index_entries;
-int64_t found = -1;
 int64_t i = 0;
+int64_t index_ctts_count;
+
+av_assert0(index);
+
+// If dts_shift > 0, then all the index timestamps will have to be offset 
by
+// at least dts_shift amount to obtain PTS.
+// Hence we decrement the searched timestamp_pts by dts_shift to find the 
closest index element.
+if (msc->dts_shift > 0) {
+timestamp_pts -= msc->dts_shift;
+}
 
 st->index_entries = e_old;
 st->nb_index_entries = nb_old;
-found = av_index_search_timestamp(st, timestamp, flag | 
AVSEEK_FLAG_BACKWARD);
+*index = av_index_search_timestamp(st, timestamp_pts, flag | 
AVSEEK_FLAG_BACKWARD);
 
 // Keep going backwards in the index entries until the timestamp is the 
same.
-if (found >= 0) {
-for (i = found; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
+if (*index >= 0) {
+for (i = *index; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
  i--) {
 if ((flag & AVSEEK_FLAG_ANY) ||
 (e_old[i - 1].flags & AVINDEX_KEYFRAME)) {
-found = i - 1;
+*index = i - 1;
+}
+}
+}
+
+// If we have CTTS then refine the search, by searching backwards over PTS
+// computed by adding corresponding CTTS durations to index timestamps.
+if (ctts_data && *index >= 0) {
+av_assert0(ctts_index);
+av_assert0(ctts_sample);
+// Find out the ctts_index for the found frame.
+*ctts_index = 0;
+*ctts_sample = 0;
+for (index_ctts_count = 0; index_ctts_count < *index; 
index_ctts_count++) {
+if (*ctts_index < ctts_count) {
+(*ctts_sample)++;
+if (ctts_data[*ctts_index].count == *ctts_sample) {
+(*ctts_index)++;
+*ctts_sample = 0;
+}
+}
+}
+
+while (*index >= 0 && (*ctts_index) >= 0) {
+// Find a "key frame" with PTS <= timestamp_pts (So that we can 
decode B-frames correctly).
+// No need to add dts_shift to the timestamp here becase 
timestamp_pts has already been
+// compensated by dts_shift above.
+if ((e_old[*index].timestamp + ctts_data[*ctts_index].duration) <= 
timestamp_pts &&
+(e_old[*index].flags & AVINDEX_KEYFRAME)) {
+break;
+}
+
+(*index)--;
+if (*ctts_sample == 0) {
+(*ctts_index)--;
+if (*ctts_index >= 0)
+  *ctts_sample = ctts_data[*ctts_index].count - 1;
+} else {
+

[FFmpeg-devel] (no subject)

2017-10-31 Thread Sasi Inguva
Added the fate ref file to the commit. Thx.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Refine edit list start seek, based on PTS computed from CTTS.

2017-10-31 Thread Sasi Inguva
Attaching the fate sample.

On Tue, Oct 31, 2017 at 4:42 PM, Sasi Inguva <is...@google.com> wrote:

> Partially fixes t/6699.
> ---
>  libavformat/mov.c  | 125 ++
> +--
>  tests/fate/mov.mak |   8 
>  2 files changed, 90 insertions(+), 43 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 60f0228e2d..a295445651 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -3014,34 +3014,95 @@ static int get_edit_list_entry(MOVContext *mov,
>  }
>
>  /**
> - * Find the closest previous frame to the timestamp, in e_old index
> + * Find the closest previous frame to the timestamp_pts, in e_old index
>   * entries. Searching for just any frame / just key frames can be
> controlled by
>   * last argument 'flag'.
> - * Returns the index of the entry in st->index_entries if successful,
> - * else returns -1.
> + * Here the timestamp_pts is considered to be a presentation timestamp and
> + * the timestamp of index entries are considered to be decoding
> timestamps.
> + *
> + * Returns 0 if successful in finding a frame, else returns -1.
> + * Places the found index corresponding output arg.
> + *
> + * If ctts_old is not NULL, then refines the searched entry by searching
> + * backwards from the found timestamp, to find the frame with correct PTS.
> + *
> + * Places the found ctts_index and ctts_sample in corresponding output
> args.
>   */
> -static int64_t find_prev_closest_index(AVStream *st,
> -   AVIndexEntry *e_old,
> -   int nb_old,
> -   int64_t timestamp,
> -   int flag)
> +static int find_prev_closest_index(AVStream *st,
> +   AVIndexEntry *e_old,
> +   int nb_old,
> +   MOVStts* ctts_data,
> +   int64_t ctts_count,
> +   int64_t timestamp_pts,
> +   int flag,
> +   int64_t* index,
> +   int64_t* ctts_index,
> +   int64_t* ctts_sample)
>  {
> +MOVStreamContext *msc = st->priv_data;
>  AVIndexEntry *e_keep = st->index_entries;
>  int nb_keep = st->nb_index_entries;
> -int64_t found = -1;
>  int64_t i = 0;
> +int64_t index_ctts_count;
> +
> +av_assert0(index);
> +
> +// If dts_shift > 0, then all the index timestamps will have to be
> offset by
> +// at least dts_shift amount to obtain PTS.
> +// Hence we decrement the searched timestamp_pts by dts_shift to find
> the closest index element.
> +if (msc->dts_shift > 0) {
> +timestamp_pts -= msc->dts_shift;
> +}
>
>  st->index_entries = e_old;
>  st->nb_index_entries = nb_old;
> -found = av_index_search_timestamp(st, timestamp, flag |
> AVSEEK_FLAG_BACKWARD);
> +*index = av_index_search_timestamp(st, timestamp_pts, flag |
> AVSEEK_FLAG_BACKWARD);
>
>  // Keep going backwards in the index entries until the timestamp is
> the same.
> -if (found >= 0) {
> -for (i = found; i > 0 && e_old[i].timestamp == e_old[i -
> 1].timestamp;
> +if (*index >= 0) {
> +for (i = *index; i > 0 && e_old[i].timestamp == e_old[i -
> 1].timestamp;
>   i--) {
>  if ((flag & AVSEEK_FLAG_ANY) ||
>  (e_old[i - 1].flags & AVINDEX_KEYFRAME)) {
> -found = i - 1;
> +*index = i - 1;
> +}
> +}
> +}
> +
> +// If we have CTTS then refine the search, by searching backwards
> over PTS
> +// computed by adding corresponding CTTS durations to index
> timestamps.
> +if (ctts_data && *index >= 0) {
> +av_assert0(ctts_index);
> +av_assert0(ctts_sample);
> +// Find out the ctts_index for the found frame.
> +*ctts_index = 0;
> +*ctts_sample = 0;
> +for (index_ctts_count = 0; index_ctts_count < *index;
> index_ctts_count++) {
> +if (*ctts_index < ctts_count) {
> +(*ctts_sample)++;
> +if (ctts_data[*ctts_index].count == *ctts_sample) {
> +(*ctts_index)++;
> +*ctts_sample = 0;
> +}
> +}
> +}
> +
> +while (*index >= 0 && (*ctts_index) >= 0) {
> +// Find a "key frame"

[FFmpeg-devel] [PATCH] lavf/mov.c: Refine edit list start seek, based on PTS computed from CTTS.

2017-10-31 Thread Sasi Inguva
Partially fixes t/6699.
---
 libavformat/mov.c  | 125 +++--
 tests/fate/mov.mak |   8 
 2 files changed, 90 insertions(+), 43 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 60f0228e2d..a295445651 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3014,34 +3014,95 @@ static int get_edit_list_entry(MOVContext *mov,
 }
 
 /**
- * Find the closest previous frame to the timestamp, in e_old index
+ * Find the closest previous frame to the timestamp_pts, in e_old index
  * entries. Searching for just any frame / just key frames can be controlled by
  * last argument 'flag'.
- * Returns the index of the entry in st->index_entries if successful,
- * else returns -1.
+ * Here the timestamp_pts is considered to be a presentation timestamp and
+ * the timestamp of index entries are considered to be decoding timestamps.
+ *
+ * Returns 0 if successful in finding a frame, else returns -1.
+ * Places the found index corresponding output arg.
+ *
+ * If ctts_old is not NULL, then refines the searched entry by searching
+ * backwards from the found timestamp, to find the frame with correct PTS.
+ *
+ * Places the found ctts_index and ctts_sample in corresponding output args.
  */
-static int64_t find_prev_closest_index(AVStream *st,
-   AVIndexEntry *e_old,
-   int nb_old,
-   int64_t timestamp,
-   int flag)
+static int find_prev_closest_index(AVStream *st,
+   AVIndexEntry *e_old,
+   int nb_old,
+   MOVStts* ctts_data,
+   int64_t ctts_count,
+   int64_t timestamp_pts,
+   int flag,
+   int64_t* index,
+   int64_t* ctts_index,
+   int64_t* ctts_sample)
 {
+MOVStreamContext *msc = st->priv_data;
 AVIndexEntry *e_keep = st->index_entries;
 int nb_keep = st->nb_index_entries;
-int64_t found = -1;
 int64_t i = 0;
+int64_t index_ctts_count;
+
+av_assert0(index);
+
+// If dts_shift > 0, then all the index timestamps will have to be offset 
by
+// at least dts_shift amount to obtain PTS.
+// Hence we decrement the searched timestamp_pts by dts_shift to find the 
closest index element.
+if (msc->dts_shift > 0) {
+timestamp_pts -= msc->dts_shift;
+}
 
 st->index_entries = e_old;
 st->nb_index_entries = nb_old;
-found = av_index_search_timestamp(st, timestamp, flag | 
AVSEEK_FLAG_BACKWARD);
+*index = av_index_search_timestamp(st, timestamp_pts, flag | 
AVSEEK_FLAG_BACKWARD);
 
 // Keep going backwards in the index entries until the timestamp is the 
same.
-if (found >= 0) {
-for (i = found; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
+if (*index >= 0) {
+for (i = *index; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
  i--) {
 if ((flag & AVSEEK_FLAG_ANY) ||
 (e_old[i - 1].flags & AVINDEX_KEYFRAME)) {
-found = i - 1;
+*index = i - 1;
+}
+}
+}
+
+// If we have CTTS then refine the search, by searching backwards over PTS
+// computed by adding corresponding CTTS durations to index timestamps.
+if (ctts_data && *index >= 0) {
+av_assert0(ctts_index);
+av_assert0(ctts_sample);
+// Find out the ctts_index for the found frame.
+*ctts_index = 0;
+*ctts_sample = 0;
+for (index_ctts_count = 0; index_ctts_count < *index; 
index_ctts_count++) {
+if (*ctts_index < ctts_count) {
+(*ctts_sample)++;
+if (ctts_data[*ctts_index].count == *ctts_sample) {
+(*ctts_index)++;
+*ctts_sample = 0;
+}
+}
+}
+
+while (*index >= 0 && (*ctts_index) >= 0) {
+// Find a "key frame" with PTS <= timestamp_pts (So that we can 
decode B-frames correctly).
+// No need to add dts_shift to the timestamp here becase 
timestamp_pts has already been
+// compensated by dts_shift above.
+if ((e_old[*index].timestamp + ctts_data[*ctts_index].duration) <= 
timestamp_pts &&
+(e_old[*index].flags & AVINDEX_KEYFRAME)) {
+break;
+}
+
+(*index)--;
+if (*ctts_sample == 0) {
+(*ctts_index)--;
+if (*ctts_index >= 0)
+  *ctts_sample = ctts_data[*ctts_index].count - 1;
+} else {
+(*ctts_sample)--;
 }
 }
 }
@@ -3049,7 +3110,7 @@ static int64_t 

Re: [FFmpeg-devel] [PATCH]fate: Add bitexact and idct simple to the mov-invalid-edst test

2017-10-29 Thread Sasi Inguva
looks good to me. Thanks for the fix.

On Sun, Oct 29, 2017 at 2:11 PM, Carl Eugen Hoyos 
wrote:

> 2017-10-29 22:03 GMT+01:00 Carl Eugen Hoyos :
> > Hi!
> >
> > Attached patch fixes a fate test here on a ppc system.
>
> The following is sufficient: -flags +bitexact
> The idct option is not necessary.
>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Fix parsing of edit list atoms with invalid elst entry count.

2017-10-26 Thread Sasi Inguva
On Tue, Oct 24, 2017 at 2:48 PM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Mon, Oct 23, 2017 at 04:18:28PM -0700, Sasi Inguva wrote:
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/mov.c   | 15 +++-
> >  tests/fate/mov.mak  |  4 ++
> >  tests/ref/fate/mov-invalid-elst-entry-count | 57
> +
> >  3 files changed, 75 insertions(+), 1 deletion(-)
> >  create mode 100644 tests/ref/fate/mov-invalid-elst-entry-count
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index b22a116140..424293ad93 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -4597,6 +4597,7 @@ static int mov_read_elst(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
> >  {
> >  MOVStreamContext *sc;
> >  int i, edit_count, version;
> > +int64_t elst_entry_size;
> >
> >  if (c->fc->nb_streams < 1 || c->ignore_editlist)
> >  return 0;
> > @@ -4605,6 +4606,15 @@ static int mov_read_elst(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
> >  version = avio_r8(pb); /* version */
> >  avio_rb24(pb); /* flags */
> >  edit_count = avio_rb32(pb); /* entries */
> > +atom.size -= 8;
> > +
> > +elst_entry_size = version == 1 ? 20 : 12;
> > +if (atom.size != edit_count * elst_entry_size &&
> > +c->fc->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
> > +av_log(c->fc, AV_LOG_ERROR, "Invalid edit list entry_count: %d
> for elst atom of size: %"PRId64" bytes.\n",
> > +   edit_count, atom.size + 8);
> > +return AVERROR_INVALIDDATA;
> > +}
> >
> >  if (!edit_count)
> >  return 0;
> > @@ -4617,17 +4627,20 @@ static int mov_read_elst(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
> >  return AVERROR(ENOMEM);
> >
> >  av_log(c->fc, AV_LOG_TRACE, "track[%u].edit_count = %i\n",
> c->fc->nb_streams - 1, edit_count);
> > -for (i = 0; i < edit_count && !pb->eof_reached; i++) {
> > +for (i = 0; i < edit_count && atom.size > 0 && !pb->eof_reached;
> i++) {
> >  MOVElst *e = >elst_data[i];
> >
> >  if (version == 1) {
> >  e->duration = avio_rb64(pb);
> >  e->time = avio_rb64(pb);
> > +atom.size -= 16;
> >  } else {
> >  e->duration = avio_rb32(pb); /* segment duration */
> >  e->time = (int32_t)avio_rb32(pb); /* media time */
> > +atom.size -= 8;
> >  }
> >  e->rate = avio_rb32(pb) / 65536.0;
> > +atom.size -= 4;
> >  av_log(c->fc, AV_LOG_TRACE, "duration=%"PRId64" time=%"PRId64"
> rate=%f\n",
> > e->duration, e->time, e->rate);
>
> it would be simpler to adjust edit_count in case of ineqality.
> you already compute the elst_entry_size
> this would also avoid allocating a larger than needed array
>
> Done. Attaching the corrected patch.

>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Many things microsoft did are stupid, but not doing something just because
> microsoft did it is even more stupid. If everything ms did were stupid they
> would be bankrupt already.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
From 188602e662868a79c7f85e9193e9aedc9ba1a170 Mon Sep 17 00:00:00 2001
From: Sasi Inguva <is...@google.com>
Date: Wed, 18 Oct 2017 20:11:16 -0700
Subject: [PATCH] lavf/mov.c: Fix parsing of edit list atoms with invalid elst
 entry count.

Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c   | 21 ++-
 tests/fate/mov.mak  |  4 ++
 tests/ref/fate/mov-invalid-elst-entry-count | 57 +
 3 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/mov-invalid-elst-entry-count

diff --git a/libavformat/mov.c b/libavformat/mov.c
index b22a116140..bd019317bf 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4597,6 +4597,7 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 MOVStreamContext *sc;
 int i, edit_count, version;
+int64_t elst_entry_size;
 
 if (c->fc->nb_streams < 1 || c->ignore_edi

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Fix parsing of edit list atoms with invalid elst entry count.

2017-10-23 Thread Sasi Inguva
On Fri, Oct 20, 2017 at 4:26 PM, Michael Niedermayer <mich...@niedermayer.cc
> wrote:

> On Wed, Oct 18, 2017 at 08:12:50PM -0700, Sasi Inguva wrote:
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/mov.c   | 16 +++-
> >  tests/fate/mov.mak  |  6 ++-
> >  tests/ref/fate/mov-invalid-elst-entry-count | 57
> +
> >  3 files changed, 76 insertions(+), 3 deletions(-)
> >  create mode 100644 tests/ref/fate/mov-invalid-elst-entry-count
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index b22a116140..8d2602c739 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -4596,7 +4596,7 @@ free_and_return:
> >  static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> >  {
> >  MOVStreamContext *sc;
> > -int i, edit_count, version;
> > +int i, edit_count, version, elst_entry_size;
> >
> >  if (c->fc->nb_streams < 1 || c->ignore_editlist)
> >  return 0;
> > @@ -4605,6 +4605,15 @@ static int mov_read_elst(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
> >  version = avio_r8(pb); /* version */
> >  avio_rb24(pb); /* flags */
> >  edit_count = avio_rb32(pb); /* entries */
>
> > +atom.size -= 8;
>
> > +
> > +elst_entry_size = version == 1 ? 20 :  12;
> > +if (atom.size != edit_count * elst_entry_size &&
>
> the edit_count * elst_entry_size can overflow
>
> Thanks. Changed elst_entry_size to int64

>
> > +c->fc->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
> > +av_log(c->fc, AV_LOG_ERROR, "Invalid edit list entry_count: %d
> for elst atom of size: %"PRId64" bytes.\n",
> > +   edit_count, atom.size + 8);
> > +return AVERROR_INVALIDDATA;
> > +}
> >
> >  if (!edit_count)
> >  return 0;
> > @@ -4617,17 +4626,20 @@ static int mov_read_elst(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
> >  return AVERROR(ENOMEM);
> >
> >  av_log(c->fc, AV_LOG_TRACE, "track[%u].edit_count = %i\n",
> c->fc->nb_streams - 1, edit_count);
> > -for (i = 0; i < edit_count && !pb->eof_reached; i++) {
> > +for (i = 0; i < edit_count && atom.size > 0 && !pb->eof_reached;
> i++) {
> >  MOVElst *e = >elst_data[i];
>
> isnt atom.size < 0 an error condition ?
> this could would not error out in that case
> is that intended ?
>
> we are comparing that atom.size is exactly equal to edit_count *
elst_entry_size . The for loop will decrease elst_entry_size bytes from
atom.size in each iteration, so it can only be < 0 iff  it wasn't exactly
equal to edit_count * elst_entry_size .


> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Complexity theory is the science of finding the exact solution to an
> approximation. Benchmarking OTOH is finding an approximation of the exact
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Fix parsing of edit list atoms with invalid elst entry count.

2017-10-23 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c   | 15 +++-
 tests/fate/mov.mak  |  4 ++
 tests/ref/fate/mov-invalid-elst-entry-count | 57 +
 3 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/mov-invalid-elst-entry-count

diff --git a/libavformat/mov.c b/libavformat/mov.c
index b22a116140..424293ad93 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4597,6 +4597,7 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 {
 MOVStreamContext *sc;
 int i, edit_count, version;
+int64_t elst_entry_size;
 
 if (c->fc->nb_streams < 1 || c->ignore_editlist)
 return 0;
@@ -4605,6 +4606,15 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 version = avio_r8(pb); /* version */
 avio_rb24(pb); /* flags */
 edit_count = avio_rb32(pb); /* entries */
+atom.size -= 8;
+
+elst_entry_size = version == 1 ? 20 : 12;
+if (atom.size != edit_count * elst_entry_size &&
+c->fc->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
+av_log(c->fc, AV_LOG_ERROR, "Invalid edit list entry_count: %d for 
elst atom of size: %"PRId64" bytes.\n",
+   edit_count, atom.size + 8);
+return AVERROR_INVALIDDATA;
+}
 
 if (!edit_count)
 return 0;
@@ -4617,17 +4627,20 @@ static int mov_read_elst(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return AVERROR(ENOMEM);
 
 av_log(c->fc, AV_LOG_TRACE, "track[%u].edit_count = %i\n", 
c->fc->nb_streams - 1, edit_count);
-for (i = 0; i < edit_count && !pb->eof_reached; i++) {
+for (i = 0; i < edit_count && atom.size > 0 && !pb->eof_reached; i++) {
 MOVElst *e = >elst_data[i];
 
 if (version == 1) {
 e->duration = avio_rb64(pb);
 e->time = avio_rb64(pb);
+atom.size -= 16;
 } else {
 e->duration = avio_rb32(pb); /* segment duration */
 e->time = (int32_t)avio_rb32(pb); /* media time */
+atom.size -= 8;
 }
 e->rate = avio_rb32(pb) / 65536.0;
+atom.size -= 4;
 av_log(c->fc, AV_LOG_TRACE, "duration=%"PRId64" time=%"PRId64" 
rate=%f\n",
e->duration, e->time, e->rate);
 
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index cfdada7a2e..ef250a12d8 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -6,6 +6,7 @@ FATE_MOV = fate-mov-3elist \
fate-mov-1elist-ends-last-bframe \
fate-mov-2elist-elist1-ends-bframe \
fate-mov-3elist-encrypted \
+   fate-mov-invalid-elst-entry-count \
fate-mov-gpmf-remux \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
@@ -39,6 +40,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-1e
 # Makes sure that we handle timestamps of packets in case of multiple edit 
lists with one of them ending on a B-frame correctly.
 fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-2elist-elist1-ends-bframe.mov
 
+# Makes sure that we handle invalid edit list entry count correctly.
+fate-mov-invalid-elst-entry-count: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/invalid_elst_entry_count.mov
+
 fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets 
-print_format compact $(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
 fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams 
-show_packets -show_frames -bitexact -print_format compact 
$(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
diff --git a/tests/ref/fate/mov-invalid-elst-entry-count 
b/tests/ref/fate/mov-invalid-elst-entry-count
new file mode 100644
index 00..13b575816b
--- /dev/null
+++ b/tests/ref/fate/mov-invalid-elst-entry-count
@@ -0,0 +1,57 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 640x480
+#sar 0: 1/1
+#stream#, dts,pts, duration, size, hash
+0,  0,  0,1,   460800, 549730883a0b56e6accaf021903daecf
+0,  1,  1,1,   460800, 783389b4342d4be925fc5244791e760a
+0,  2,  2,1,   460800, 8384af6426d94a2077930c93013e09ad
+0,  3,  3,1,   460800, 9380a1d9ecacf5b3105383c1c8083188
+0,  4,  4,1,   460800, eb28174acfceb868b9058757bed049c5
+0,  5,  5,1,   460800, 9732bd4a58884dbf2be48d819433130f
+0,  6,  6,1,   460800, 0c553fb530cf042eb84f5b13817a96a6
+0,  7,  7,1,   460800, 621f02aded5e35fa1f373afd3ed283bd
+0,  8,  8,1,   460800, c76167c6bda91f657708c88252ea315d

[FFmpeg-devel] [PATCH] lavf/mov.c: Fix parsing of edit list atoms with invalid elst entry count.

2017-10-18 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c   | 16 +++-
 tests/fate/mov.mak  |  6 ++-
 tests/ref/fate/mov-invalid-elst-entry-count | 57 +
 3 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 tests/ref/fate/mov-invalid-elst-entry-count

diff --git a/libavformat/mov.c b/libavformat/mov.c
index b22a116140..8d2602c739 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4596,7 +4596,7 @@ free_and_return:
 static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 MOVStreamContext *sc;
-int i, edit_count, version;
+int i, edit_count, version, elst_entry_size;
 
 if (c->fc->nb_streams < 1 || c->ignore_editlist)
 return 0;
@@ -4605,6 +4605,15 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 version = avio_r8(pb); /* version */
 avio_rb24(pb); /* flags */
 edit_count = avio_rb32(pb); /* entries */
+atom.size -= 8;
+
+elst_entry_size = version == 1 ? 20 :  12;
+if (atom.size != edit_count * elst_entry_size &&
+c->fc->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
+av_log(c->fc, AV_LOG_ERROR, "Invalid edit list entry_count: %d for 
elst atom of size: %"PRId64" bytes.\n",
+   edit_count, atom.size + 8);
+return AVERROR_INVALIDDATA;
+}
 
 if (!edit_count)
 return 0;
@@ -4617,17 +4626,20 @@ static int mov_read_elst(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return AVERROR(ENOMEM);
 
 av_log(c->fc, AV_LOG_TRACE, "track[%u].edit_count = %i\n", 
c->fc->nb_streams - 1, edit_count);
-for (i = 0; i < edit_count && !pb->eof_reached; i++) {
+for (i = 0; i < edit_count && atom.size > 0 && !pb->eof_reached; i++) {
 MOVElst *e = >elst_data[i];
 
 if (version == 1) {
 e->duration = avio_rb64(pb);
 e->time = avio_rb64(pb);
+atom.size -= 16;
 } else {
 e->duration = avio_rb32(pb); /* segment duration */
 e->time = (int32_t)avio_rb32(pb); /* media time */
+atom.size -= 8;
 }
 e->rate = avio_rb32(pb) / 65536.0;
+atom.size -= 4;
 av_log(c->fc, AV_LOG_TRACE, "duration=%"PRId64" time=%"PRId64" 
rate=%f\n",
e->duration, e->time, e->rate);
 
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index cfdada7a2e..012e6f61b7 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -6,7 +6,8 @@ FATE_MOV = fate-mov-3elist \
fate-mov-1elist-ends-last-bframe \
fate-mov-2elist-elist1-ends-bframe \
fate-mov-3elist-encrypted \
-   fate-mov-gpmf-remux \
+  fate-mov-invalid-elst-entry-count \
+  fate-mov-gpmf-remux \
 
 FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \
fate-mov-zombie \
@@ -39,6 +40,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-1e
 # Makes sure that we handle timestamps of packets in case of multiple edit 
lists with one of them ending on a B-frame correctly.
 fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-2elist-elist1-ends-bframe.mov
 
+# Makes sure that we handle invalid edit list entry count correctly.
+fate-mov-invalid-elst-entry-count: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/invalid_elst_entry_count.mov
+
 fate-mov-aac-2048-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets 
-print_format compact $(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
 fate-mov-zombie: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_streams 
-show_packets -show_frames -bitexact -print_format compact 
$(TARGET_SAMPLES)/mov/white_zombie_scrunch-part.mov
diff --git a/tests/ref/fate/mov-invalid-elst-entry-count 
b/tests/ref/fate/mov-invalid-elst-entry-count
new file mode 100644
index 00..13b575816b
--- /dev/null
+++ b/tests/ref/fate/mov-invalid-elst-entry-count
@@ -0,0 +1,57 @@
+#format: frame checksums
+#version: 2
+#hash: MD5
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 640x480
+#sar 0: 1/1
+#stream#, dts,pts, duration, size, hash
+0,  0,  0,1,   460800, 549730883a0b56e6accaf021903daecf
+0,  1,  1,1,   460800, 783389b4342d4be925fc5244791e760a
+0,  2,  2,1,   460800, 8384af6426d94a2077930c93013e09ad
+0,  3,  3,1,   460800, 9380a1d9ecacf5b3105383c1c8083188
+0,  4,  4,1,   460800, eb28174acfceb868b9058757bed049c5
+0,  5,  5,1,   460800, 9732bd4a58884dbf2be48d819433130f
+0,  6,  6,1,   460800, 0c553fb530cf042eb84f5b13817a96a6
+0,  7,  7, 

Re: [FFmpeg-devel] [mov] When both edit list and start padding present, take maximum.

2017-10-18 Thread Sasi Inguva
Patch LGTM. Thanks.

On Wed, Oct 18, 2017 at 4:14 PM, Dale Curtis <dalecur...@chromium.org>
wrote:

> On Wed, Oct 18, 2017 at 4:00 PM, Sasi Inguva <is...@google.com> wrote:
>
>> Thanks for the patch. The bug is because mov_fix_index updates
>> skip_samples correctly, but not start_pad. Can you instead of taking the
>> max, just update the mov_fix_index function so that start_pad =
>> skip_samples always. Something like this
>>
>
> Thanks this works. Patch attached.
>
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [mov] When both edit list and start padding present, take maximum.

2017-10-18 Thread Sasi Inguva
Thanks for the patch. The bug is because mov_fix_index updates skip_samples
correctly, but not start_pad. Can you instead of taking the max, just
update the mov_fix_index function so that start_pad = skip_samples always.
Something like this
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 899690d920..355e1d09fd 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3249,7 +3249,6 @@ static void mov_fix_index(MOVContext *mov, AVStream
*st)
 // Increment skip_samples for the first non-zero
audio edit list
 if (first_non_zero_audio_edit > 0 &&
st->codecpar->codec_id != AV_CODEC_ID_VORBIS) {
 st->skip_samples += frame_duration;
-msc->start_pad = st->skip_samples;
 }
 }
 }
@@ -3324,6 +3323,8 @@ static void mov_fix_index(MOVContext *mov, AVStream
*st)
 // Update av stream length
 st->duration = edit_list_dts_entry_end - start_dts;

+msc->start_pad = st->skip_samples;
+
 // Free the old index and the old CTTS structures
 av_free(e_old);
 av_free(ctts_data_old);


Thanks.

On Mon, Oct 16, 2017 at 2:25 PM, Dale Curtis 
wrote:

> More details on the issue which uncovered this can be seen here
> https://bugs.chromium.org/p/chromium/issues/detail?id=775042#c13
>
> - dale
>
> On Mon, Oct 16, 2017 at 2:22 PM, Dale Curtis 
> wrote:
>
>> Previously the start padding was used to blindly overwrite any skip
>> samples which may have come from an edit list. Instead take the maximum of
>> the two.
>>
>> A new fate test is added, fate-mov-440hz-10ms, to ensure this is handled
>> correctly.
>>
>> The sample can be downloaded and added to the fate-suite from
>>
>> https://cs.chromium.org/chromium/src/third_party/WebKit/
>> LayoutTests/webaudio/resources/media/440hz-10ms.m4a
>>
>> - dale
>>
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavfi/avfilter.c: Correct guess_status_pts to account for differing link timebases.

2017-10-06 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavfilter/avfilter.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 58917ed445..f0f849b326 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -427,19 +427,19 @@ int ff_request_frame(AVFilterLink *link)
 return 0;
 }
 
-static int64_t guess_status_pts(AVFilterContext *ctx, int status)
+static int64_t guess_status_pts(AVFilterContext *ctx, int status, AVRational 
link_time_base)
 {
 unsigned i;
 int64_t r = INT64_MAX;
 
 for (i = 0; i < ctx->nb_inputs; i++)
 if (ctx->inputs[i]->status_out == status)
-r = FFMIN(r, ctx->inputs[i]->current_pts);
+r = FFMIN(r, av_rescale_q(ctx->inputs[i]->current_pts, 
ctx->inputs[i]->time_base, link_time_base));
 if (r < INT64_MAX)
 return r;
 av_log(ctx, AV_LOG_WARNING, "EOF timestamp not reliable\n");
 for (i = 0; i < ctx->nb_inputs; i++)
-r = FFMIN(r, ctx->inputs[i]->status_in_pts);
+r = FFMIN(r, av_rescale_q(ctx->inputs[i]->status_in_pts, 
ctx->inputs[i]->time_base, link_time_base));
 if (r < INT64_MAX)
 return r;
 return AV_NOPTS_VALUE;
@@ -458,7 +458,7 @@ static int ff_request_frame_to_filter(AVFilterLink *link)
 ret = ff_request_frame(link->src->inputs[0]);
 if (ret < 0) {
 if (ret != AVERROR(EAGAIN) && ret != link->status_in)
-ff_avfilter_link_set_in_status(link, ret, 
guess_status_pts(link->src, ret));
+ff_avfilter_link_set_in_status(link, ret, 
guess_status_pts(link->src, ret, link->time_base));
 if (ret == AVERROR_EOF)
 ret = 0;
 }
-- 
2.14.2.920.gcf0c67979c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/5] ffmpeg: send EOF pts to filters.

2017-10-05 Thread Sasi Inguva
I've encountered the same problem, and tracked it to guess_status_pts
function which tries to take the end timestamp from the input links
however without converting it to correct time base. Sent a patch, PTAL.

On Tue, Oct 3, 2017 at 5:36 PM, Thomas Mundt  wrote:

> Hi Nicolas,
>
> 2017-09-07 10:59 GMT+02:00 Nicolas George :
>
> > Signed-off-by: Nicolas George 
> > ---
> >  ffmpeg.c | 10 +++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/ffmpeg.c b/ffmpeg.c
> > index b95addd277..1d248bc269 100644
> > --- a/ffmpeg.c
> > +++ b/ffmpeg.c
> > @@ -2223,14 +2223,14 @@ static int ifilter_send_frame(InputFilter
> > *ifilter, AVFrame *frame)
> >  return 0;
> >  }
> >
> > -static int ifilter_send_eof(InputFilter *ifilter)
> > +static int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
> >  {
> >  int i, j, ret;
> >
> >  ifilter->eof = 1;
> >
> >  if (ifilter->filter) {
> > -ret = av_buffersrc_add_frame_flags(ifilter->filter, NULL,
> > AV_BUFFERSRC_FLAG_PUSH);
> > +ret = av_buffersrc_close(ifilter->filter, pts,
> > AV_BUFFERSRC_FLAG_PUSH);
> >  if (ret < 0)
> >  return ret;
> >  } else {
> > @@ -2581,8 +2581,12 @@ out:
> >  static int send_filter_eof(InputStream *ist)
> >  {
> >  int i, ret;
> > +/* TODO keep pts also in stream time base to avoid converting back
> */
> > +int64_t pts = av_rescale_q_rnd(ist->pts, AV_TIME_BASE_Q,
> > ist->st->time_base,
> > +   AV_ROUND_NEAR_INF |
> > AV_ROUND_PASS_MINMAX);
> > +
> >  for (i = 0; i < ist->nb_filters; i++) {
> > -ret = ifilter_send_eof(ist->filters[i]);
> > +ret = ifilter_send_eof(ist->filters[i], pts);
> >  if (ret < 0)
> >  return ret;
> >  }
> >
>
> The sended pts always seems to refer to the input time base.
> When a filter changes the time base, the EOF pts becomes wrong for
> subsequent filters in the chain.
> E.g. when using vf_fps behind vf_yadif=1 with interlaced input, the sended
> EOF pts is only half of the expected pts.
>
> I tried to find a solution, but without success.
> Do you have an idea?
>
> Regards,
> Thomas
>
>
>  utm_source=link_campaign=sig-email_content=webmail>
> Virenfrei.
> www.avg.com
>  utm_source=link_campaign=sig-email_content=webmail>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavfi/avfilter.c: Correct guess_status_pts to account for differing link timebases.

2017-10-05 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavfilter/avfilter.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 58917ed445..ec7dfc0bd3 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -427,19 +427,19 @@ int ff_request_frame(AVFilterLink *link)
 return 0;
 }
 
-static int64_t guess_status_pts(AVFilterContext *ctx, int status)
+static int64_t guess_status_pts_from_src(AVFilterLink *link, int status)
 {
 unsigned i;
 int64_t r = INT64_MAX;
 
-for (i = 0; i < ctx->nb_inputs; i++)
-if (ctx->inputs[i]->status_out == status)
-r = FFMIN(r, ctx->inputs[i]->current_pts);
+for (i = 0; i < link->src->nb_inputs; i++)
+if (link->src->inputs[i]->status_out == status)
+  r = FFMIN(r, av_rescale_q(link->src->inputs[i]->current_pts, 
link->src->inputs[i]->time_base, link->time_base));
 if (r < INT64_MAX)
 return r;
-av_log(ctx, AV_LOG_WARNING, "EOF timestamp not reliable\n");
-for (i = 0; i < ctx->nb_inputs; i++)
-r = FFMIN(r, ctx->inputs[i]->status_in_pts);
+av_log(link->src, AV_LOG_WARNING, "EOF timestamp not reliable\n");
+for (i = 0; i < link->src->nb_inputs; i++)
+  r = FFMIN(r, av_rescale_q(link->src->inputs[i]->status_in_pts, 
link->src->inputs[i]->time_base, link->time_base));
 if (r < INT64_MAX)
 return r;
 return AV_NOPTS_VALUE;
@@ -458,7 +458,7 @@ static int ff_request_frame_to_filter(AVFilterLink *link)
 ret = ff_request_frame(link->src->inputs[0]);
 if (ret < 0) {
 if (ret != AVERROR(EAGAIN) && ret != link->status_in)
-ff_avfilter_link_set_in_status(link, ret, 
guess_status_pts(link->src, ret));
+ff_avfilter_link_set_in_status(link, ret, 
guess_status_pts_from_src(link, ret));
 if (ret == AVERROR_EOF)
 ret = 0;
 }
-- 
2.14.2.920.gcf0c67979c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/movenc.c: Set sgpd and sbgp atoms to represent decoder delay for AAC.

2017-08-08 Thread Sasi Inguva
According to 
https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html
 and ISO-IEC-14496-12 Section 10.1.1.1 and 10.1.1.3

Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/movenc.c| 22 +++---
 tests/ref/fate/adtstoasc_ticket3715 |  4 ++--
 tests/ref/fate/copy-psp |  4 ++--
 tests/ref/fate/movenc   | 12 ++--
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 0e5b45d150..5c53ab24e0 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2208,14 +2208,16 @@ static int mov_preroll_write_stbl_atoms(AVIOContext 
*pb, MOVTrack *track)
 (AVRational){1, 1000},
 (AVRational){1, 48000});
 
-if (track->entry) {
-sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries));
-if (!sgpd_entries)
-return AVERROR(ENOMEM);
-}
+if (!track->entry)
+return 0;
 
-av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS);
+sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries));
+if (!sgpd_entries)
+return AVERROR(ENOMEM);
 
+av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS || 
track->par->codec_id == AV_CODEC_ID_AAC);
+
+if (track->par->codec_id == AV_CODEC_ID_OPUS) {
 for (i = 0; i < track->entry; i++) {
 int roll_samples_remaining = roll_samples;
 int distance = 0;
@@ -2242,6 +2244,12 @@ static int mov_preroll_write_stbl_atoms(AVIOContext *pb, 
MOVTrack *track)
 sgpd_entries[entries].group_description_index = distance ? ++group 
: 0;
 }
 }
+} else {
+entries++;
+sgpd_entries[entries].count = track->sample_count;
+sgpd_entries[entries].roll_distance = 1;
+sgpd_entries[entries].group_description_index = ++group;
+}
 entries++;
 
 if (!group) {
@@ -2304,7 +2312,7 @@ static int mov_write_stbl_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContext
 if (track->cenc.aes_ctr) {
 ff_mov_cenc_write_stbl_atoms(>cenc, pb);
 }
-if (track->par->codec_id == AV_CODEC_ID_OPUS) {
+if (track->par->codec_id == AV_CODEC_ID_OPUS || track->par->codec_id == 
AV_CODEC_ID_AAC) {
 mov_preroll_write_stbl_atoms(pb, track);
 }
 return update_size(pb, pos);
diff --git a/tests/ref/fate/adtstoasc_ticket3715 
b/tests/ref/fate/adtstoasc_ticket3715
index 949b565c2f..96795a2ca3 100644
--- a/tests/ref/fate/adtstoasc_ticket3715
+++ b/tests/ref/fate/adtstoasc_ticket3715
@@ -1,5 +1,5 @@
-ef8ce3cbd1d86113e7c991a816086068 *tests/data/fate/adtstoasc_ticket3715.mov
-33270 tests/data/fate/adtstoasc_ticket3715.mov
+0221e04333e6ac432fa42960502f0d5a *tests/data/fate/adtstoasc_ticket3715.mov
+33324 tests/data/fate/adtstoasc_ticket3715.mov
 #extradata 0:2, 0x00340022
 #tb 0: 1/44100
 #media_type 0: audio
diff --git a/tests/ref/fate/copy-psp b/tests/ref/fate/copy-psp
index 6603d3ff26..81eb172549 100644
--- a/tests/ref/fate/copy-psp
+++ b/tests/ref/fate/copy-psp
@@ -1,5 +1,5 @@
-6889223644fc560069c8591984175a62 *tests/data/fate/copy-psp.psp
-2041379 tests/data/fate/copy-psp.psp
+cada61453a2483ef8ba1fb82c8bbff25 *tests/data/fate/copy-psp.psp
+2041433 tests/data/fate/copy-psp.psp
 #extradata 0:   51, 0xaf6d1012
 #extradata 1:2, 0x00b200a1
 #tb 0: 1/9
diff --git a/tests/ref/fate/movenc b/tests/ref/fate/movenc
index 09e603aeb7..47bcf9d515 100644
--- a/tests/ref/fate/movenc
+++ b/tests/ref/fate/movenc
@@ -1,18 +1,18 @@
 write_data len 36, time nopts, type header atom ftyp
-write_data len 2335, time nopts, type header atom -
+write_data len 2389, time nopts, type header atom -
 write_data len 788, time 100, type sync atom moof
 write_data len 110, time nopts, type trailer atom -
-214242e9c7c93171d2f47f5b47776559 3269 non-empty-moov
+17a37691eba8b858cf15e60aa9a7dbf7 3323 non-empty-moov
 write_data len 36, time nopts, type header atom ftyp
-write_data len 2667, time nopts, type header atom -
+write_data len 2721, time nopts, type header atom -
 write_data len 908, time 97, type sync atom moof
 write_data len 110, time nopts, type trailer atom -
-44467d568a3cc38d414fd8ed4b2a968f 3721 non-empty-moov-elst
+0026ffe059c06c592021f972bf2c5e79 3775 non-empty-moov-elst
 write_data len 36, time nopts, type header atom ftyp
-write_data len 2575, time nopts, type header atom -
+write_data len 2629, time nopts, type header atom -
 write_data len 908, time 100, type sync atom moof
 write_data len 110, time nopts, type trailer atom -
-de22b98a3885f9b4b83cdd48ff46aeb9 3629 non-empty-moov-no-elst
+c184e168ac1e5bb3d9c70e580ab6179c 3683 non-empty-moov-no-elst
 write_data len 20, time nopts, type header atom ftyp
 write_data len 1171, time nopts, type header atom -
 writ

Re: [FFmpeg-devel] [PATCH] lavf/movenc.c: Set sgpd and sbgp atoms to represent decoder delay for AAC.

2017-08-08 Thread Sasi Inguva
Ping!

On Aug 5, 2017 10:08 AM, "Sasi Inguva" <is...@google.com> wrote:

> To the best of my knowledge, all fate changes are benign. All of them
> correspond to a size increase of 54 bytes, which is the total size of the
> new atoms added.
>
> On Sat, Aug 5, 2017 at 9:27 AM, Derek Buitenhuis <
> derek.buitenh...@gmail.com> wrote:
>
>> On 8/4/2017 9:35 PM, Sasi Inguva wrote:
>> > According to https://developer.apple.com/li
>> brary/content/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html
>> and ISO-IEC-14496-12 Section 10.1.1.1 and 10.1.1.3
>> >
>> > Signed-off-by: Sasi Inguva <is...@google.com>
>> > ---
>> >  libavformat/movenc.c| 70 +-
>> ---
>> >  tests/ref/fate/adtstoasc_ticket3715 |  4 +--
>> >  tests/ref/fate/copy-psp |  4 +--
>> >  tests/ref/fate/movenc   | 12 +++
>> >  4 files changed, 49 insertions(+), 41 deletions(-)
>>
>> Probably OK, if FATE changes are benign.
>>
>> - Derek
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/movenc.c: Set sgpd and sbgp atoms to represent decoder delay for AAC.

2017-08-05 Thread Sasi Inguva
To the best of my knowledge, all fate changes are benign. All of them
correspond to a size increase of 54 bytes, which is the total size of the
new atoms added.

On Sat, Aug 5, 2017 at 9:27 AM, Derek Buitenhuis <derek.buitenh...@gmail.com
> wrote:

> On 8/4/2017 9:35 PM, Sasi Inguva wrote:
> > According to https://developer.apple.com/library/content/documentation/
> QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html and ISO-IEC-14496-12 Section
> 10.1.1.1 and 10.1.1.3
> >
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/movenc.c| 70 +-
> ---
> >  tests/ref/fate/adtstoasc_ticket3715 |  4 +--
> >  tests/ref/fate/copy-psp |  4 +--
> >  tests/ref/fate/movenc   | 12 +++
> >  4 files changed, 49 insertions(+), 41 deletions(-)
>
> Probably OK, if FATE changes are benign.
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/movenc.c: Set sgpd and sbgp atoms to represent decoder delay for AAC.

2017-08-04 Thread Sasi Inguva
According to 
https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html
 and ISO-IEC-14496-12 Section 10.1.1.1 and 10.1.1.3

Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/movenc.c| 70 +
 tests/ref/fate/adtstoasc_ticket3715 |  4 +--
 tests/ref/fate/copy-psp |  4 +--
 tests/ref/fate/movenc   | 12 +++
 4 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 0e5b45d150..10b959ad02 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2208,39 +2208,47 @@ static int mov_preroll_write_stbl_atoms(AVIOContext 
*pb, MOVTrack *track)
 (AVRational){1, 1000},
 (AVRational){1, 48000});
 
-if (track->entry) {
-sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries));
-if (!sgpd_entries)
-return AVERROR(ENOMEM);
-}
+if (!track->entry)
+return 0;
 
-av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS);
+sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries));
+if (!sgpd_entries)
+return AVERROR(ENOMEM);
 
-for (i = 0; i < track->entry; i++) {
-int roll_samples_remaining = roll_samples;
-int distance = 0;
-for (j = i - 1; j >= 0; j--) {
-roll_samples_remaining -= get_cluster_duration(track, j);
-distance++;
-if (roll_samples_remaining <= 0)
-break;
-}
-/* We don't have enough preceeding samples to compute a valid
-   roll_distance here, so this sample can't be independently
-   decoded. */
-if (roll_samples_remaining > 0)
-distance = 0;
-/* Verify distance is a minimum of 2 (60ms) packets and a maximum of
-   32 (2.5ms) packets. */
-av_assert0(distance == 0 || (distance >= 2 && distance <= 32));
-if (i && distance == sgpd_entries[entries].roll_distance) {
-sgpd_entries[entries].count++;
-} else {
-entries++;
-sgpd_entries[entries].count = 1;
-sgpd_entries[entries].roll_distance = distance;
-sgpd_entries[entries].group_description_index = distance ? ++group 
: 0;
+av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS || 
track->par->codec_id == AV_CODEC_ID_AAC);
+
+if (track->par->codec_id == AV_CODEC_ID_OPUS) {
+for (i = 0; i < track->entry; i++) {
+int roll_samples_remaining = roll_samples;
+int distance = 0;
+for (j = i - 1; j >= 0; j--) {
+roll_samples_remaining -= get_cluster_duration(track, j);
+distance++;
+if (roll_samples_remaining <= 0)
+break;
+}
+/* We don't have enough preceeding samples to compute a valid
+   roll_distance here, so this sample can't be independently
+   decoded. */
+if (roll_samples_remaining > 0)
+distance = 0;
+/* Verify distance is a minimum of 2 (60ms) packets and a maximum 
of
+   32 (2.5ms) packets. */
+av_assert0(distance == 0 || (distance >= 2 && distance <= 32));
+if (i && distance == sgpd_entries[entries].roll_distance) {
+sgpd_entries[entries].count++;
+} else {
+entries++;
+sgpd_entries[entries].count = 1;
+sgpd_entries[entries].roll_distance = distance;
+sgpd_entries[entries].group_description_index = distance ? 
++group : 0;
+}
 }
+} else {
+entries++;
+sgpd_entries[entries].count = track->sample_count;
+sgpd_entries[entries].roll_distance = 1;
+sgpd_entries[entries].group_description_index = ++group;
 }
 entries++;
 
@@ -2304,7 +2312,7 @@ static int mov_write_stbl_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContext
 if (track->cenc.aes_ctr) {
 ff_mov_cenc_write_stbl_atoms(>cenc, pb);
 }
-if (track->par->codec_id == AV_CODEC_ID_OPUS) {
+if (track->par->codec_id == AV_CODEC_ID_OPUS || track->par->codec_id == 
AV_CODEC_ID_AAC) {
 mov_preroll_write_stbl_atoms(pb, track);
 }
 return update_size(pb, pos);
diff --git a/tests/ref/fate/adtstoasc_ticket3715 
b/tests/ref/fate/adtstoasc_ticket3715
index 949b565c2f..96795a2ca3 100644
--- a/tests/ref/fate/adtstoasc_ticket3715
+++ b/tests/ref/fate/adtstoasc_ticket3715
@@ -1,5 +1,5 @@
-ef8ce3cbd1d86113e7c991a816086068 *tests/data/fate/adtstoasc_ticket3715.mov
-33270 tests/data/fate/adtstoasc_ticket3715.mov
+0221e04333e6ac432fa42960502f0d5a *tests/data/fate/adtstoasc_ticket3715.m

Re: [FFmpeg-devel] [PATCH] lavf/movenc.c: Set sgpd and sbgp atoms to represent decoder delay for AAC.

2017-08-04 Thread Sasi Inguva
From ISO-IEC-14496-12
*10 Sample Groups*
*10.1 Random Access Recovery Points*
*10.1.1.1*
*Definition*
*class AudioRollRecoveryEntry() extends AudioSampleGroupEntry (’roll’)*
*{*
*signed int(16) roll_distance;*
*}*


*An AudioRollRecoveryEntry documents the pre‐roll distance required in
audio streams in whichevery sample can be independently decoded, but the
decoder output is only assured to be correct afterpre‐rolling by the
indicated number of samples.*








*10.1.1.3roll_distance is a signed integer that gives the number of samples
that must be decoded inorder for a sample to be decoded correctly. A
positive value indicates the number of samplesafter the sample that is a
group member that must be decoded such that at the last of theserecovery is
complete, i.e. the last sample is correct. A negative value indicates the
number ofsamples before the sample that is a group member that must be
decoded in order for recoveryto be complete at the marked sample. The value
zero must not be used; the sync sample tabledocuments random access points
for which no recovery roll is needed.*


This patch sets the sgpd and sbgp atoms irrespective of whether it's
fragmented or not. So the byte addresses for some atoms will change for all
MP4 files .

On Fri, Aug 4, 2017 at 12:11 PM, Derek Buitenhuis <
derek.buitenh...@gmail.com> wrote:

> On 8/4/2017 7:46 PM, Sasi Inguva wrote:
> > According to https://developer.apple.com/library/content/documentation/
> QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html
> >
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/movenc.c| 70 +-
> ---
> >  tests/ref/fate/adtstoasc_ticket3715 |  4 +--
> >  tests/ref/fate/copy-psp |  4 +--
> >  tests/ref/fate/movenc   | 12 +++
> >  4 files changed, 49 insertions(+), 41 deletions(-)
>
> Is there a reference for ISOBMFF too? Because this changes mp4 output as
> well mov.
>
> > diff --git a/tests/ref/fate/movenc b/tests/ref/fate/movenc
> > index 09e603aeb7..47bcf9d515 100644
> > --- a/tests/ref/fate/movenc
> > +++ b/tests/ref/fate/movenc
> > @@ -1,18 +1,18 @@
> >  write_data len 36, time nopts, type header atom ftyp
> > -write_data len 2335, time nopts, type header atom -
> > +write_data len 2389, time nopts, type header atom -
> >  write_data len 788, time 100, type sync atom moof
> >  write_data len 110, time nopts, type trailer atom -
> > -214242e9c7c93171d2f47f5b47776559 3269 non-empty-moov
> > +17a37691eba8b858cf15e60aa9a7dbf7 3323 non-empty-moov
> >  write_data len 36, time nopts, type header atom ftyp
> > -write_data len 2667, time nopts, type header atom -
> > +write_data len 2721, time nopts, type header atom -
> >  write_data len 908, time 97, type sync atom moof
> >  write_data len 110, time nopts, type trailer atom -
> > -44467d568a3cc38d414fd8ed4b2a968f 3721 non-empty-moov-elst
> > +0026ffe059c06c592021f972bf2c5e79 3775 non-empty-moov-elst
> >  write_data len 36, time nopts, type header atom ftyp
> > -write_data len 2575, time nopts, type header atom -
> > +write_data len 2629, time nopts, type header atom -
> >  write_data len 908, time 100, type sync atom moof
> >  write_data len 110, time nopts, type trailer atom -
> > -de22b98a3885f9b4b83cdd48ff46aeb9 3629 non-empty-moov-no-elst
> > +c184e168ac1e5bb3d9c70e580ab6179c 3683 non-empty-moov-no-elst
> >  write_data len 20, time nopts, type header atom ftyp
> >  write_data len 1171, time nopts, type header atom -
> >  write_data len 728, time 0, type sync atom moof
> >
>
> Can you confirm what exactly changes in these fragmented MP4 API tests?
>
> - Derek
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/movenc.c: Set sgpd and sbgp atoms to represent decoder delay for AAC.

2017-08-04 Thread Sasi Inguva
According to 
https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html

Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/movenc.c| 70 +
 tests/ref/fate/adtstoasc_ticket3715 |  4 +--
 tests/ref/fate/copy-psp |  4 +--
 tests/ref/fate/movenc   | 12 +++
 4 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 0e5b45d150..10b959ad02 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2208,39 +2208,47 @@ static int mov_preroll_write_stbl_atoms(AVIOContext 
*pb, MOVTrack *track)
 (AVRational){1, 1000},
 (AVRational){1, 48000});
 
-if (track->entry) {
-sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries));
-if (!sgpd_entries)
-return AVERROR(ENOMEM);
-}
+if (!track->entry)
+return 0;
 
-av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS);
+sgpd_entries = av_malloc_array(track->entry, sizeof(*sgpd_entries));
+if (!sgpd_entries)
+return AVERROR(ENOMEM);
 
-for (i = 0; i < track->entry; i++) {
-int roll_samples_remaining = roll_samples;
-int distance = 0;
-for (j = i - 1; j >= 0; j--) {
-roll_samples_remaining -= get_cluster_duration(track, j);
-distance++;
-if (roll_samples_remaining <= 0)
-break;
-}
-/* We don't have enough preceeding samples to compute a valid
-   roll_distance here, so this sample can't be independently
-   decoded. */
-if (roll_samples_remaining > 0)
-distance = 0;
-/* Verify distance is a minimum of 2 (60ms) packets and a maximum of
-   32 (2.5ms) packets. */
-av_assert0(distance == 0 || (distance >= 2 && distance <= 32));
-if (i && distance == sgpd_entries[entries].roll_distance) {
-sgpd_entries[entries].count++;
-} else {
-entries++;
-sgpd_entries[entries].count = 1;
-sgpd_entries[entries].roll_distance = distance;
-sgpd_entries[entries].group_description_index = distance ? ++group 
: 0;
+av_assert0(track->par->codec_id == AV_CODEC_ID_OPUS || 
track->par->codec_id == AV_CODEC_ID_AAC);
+
+if (track->par->codec_id == AV_CODEC_ID_OPUS) {
+for (i = 0; i < track->entry; i++) {
+int roll_samples_remaining = roll_samples;
+int distance = 0;
+for (j = i - 1; j >= 0; j--) {
+roll_samples_remaining -= get_cluster_duration(track, j);
+distance++;
+if (roll_samples_remaining <= 0)
+break;
+}
+/* We don't have enough preceeding samples to compute a valid
+   roll_distance here, so this sample can't be independently
+   decoded. */
+if (roll_samples_remaining > 0)
+distance = 0;
+/* Verify distance is a minimum of 2 (60ms) packets and a maximum 
of
+   32 (2.5ms) packets. */
+av_assert0(distance == 0 || (distance >= 2 && distance <= 32));
+if (i && distance == sgpd_entries[entries].roll_distance) {
+sgpd_entries[entries].count++;
+} else {
+entries++;
+sgpd_entries[entries].count = 1;
+sgpd_entries[entries].roll_distance = distance;
+sgpd_entries[entries].group_description_index = distance ? 
++group : 0;
+}
 }
+} else {
+entries++;
+sgpd_entries[entries].count = track->sample_count;
+sgpd_entries[entries].roll_distance = 1;
+sgpd_entries[entries].group_description_index = ++group;
 }
 entries++;
 
@@ -2304,7 +2312,7 @@ static int mov_write_stbl_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContext
 if (track->cenc.aes_ctr) {
 ff_mov_cenc_write_stbl_atoms(>cenc, pb);
 }
-if (track->par->codec_id == AV_CODEC_ID_OPUS) {
+if (track->par->codec_id == AV_CODEC_ID_OPUS || track->par->codec_id == 
AV_CODEC_ID_AAC) {
 mov_preroll_write_stbl_atoms(pb, track);
 }
 return update_size(pb, pos);
diff --git a/tests/ref/fate/adtstoasc_ticket3715 
b/tests/ref/fate/adtstoasc_ticket3715
index 949b565c2f..96795a2ca3 100644
--- a/tests/ref/fate/adtstoasc_ticket3715
+++ b/tests/ref/fate/adtstoasc_ticket3715
@@ -1,5 +1,5 @@
-ef8ce3cbd1d86113e7c991a816086068 *tests/data/fate/adtstoasc_ticket3715.mov
-33270 tests/data/fate/adtstoasc_ticket3715.mov
+0221e04333e6ac432fa42960502f0d5a *tests/data/fate/adtstoasc_ticket3715.mov
+33324 tests/data/fate/adtstoasc_ticket3715.mov

Re: [FFmpeg-devel] Why the tag “DURATION” is a necessity in Matroska files?

2017-06-17 Thread Sasi Inguva
Hi,

I was the one who made that change. We needed a way to obtain individual
stream durations from a  Matroska file without reading the entire file. I
don't think it adds to the file size greatly (< 50 bytes) compared to the
size of video and audio data, hence I didn't hide it under an option.
However if u really need it I can add an option.

On Jun 16, 2017 7:21 AM, <21na...@gmail.com> wrote:

Le 16/06/2017 à 16:04, wm4 a écrit :

> On Fri, 16 Jun 2017 15:43:51 +0200
> 21na...@gmail.com wrote:
>
> Le 16/06/2017 à 14:25, wm4 a écrit :
>>
>>> On Fri, 16 Jun 2017 13:51:20 +0200
>>> 21na...@gmail.com wrote:
>>>
>>>
 Le 16/06/2017 à 12:55, wm4 a écrit :

> On Fri, 16 Jun 2017 02:32:10 +0200
> 21na...@gmail.com wrote:
>
>
>> Hello,
>>
>>
>> I would like to know why the tag “DURATION” in Matroska files (.mkv)
>> is
>> a necessity? Even mkvmerge lets the choice to use it or not with
>> “--enable-durations”, in addition it is written “Write durations for
>> all
>> blocks. This will increase file size and does not offer any additional
>> value for players at the moment.” (source
>> https://mkvtoolnix.download/doc/mkvmerge.html#d4e535).
>>
>> Possibly linked to
>> http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=3185254
>> 0d4fba0c4e8a16d0b3ddff08fc98e48fd
>>
> As far as I'm aware, the linked commit does not do the same thing as
> the mkvmerge option you pointed out.
>
 Yes that is why I wrote “possibly”, also because this commit is the one
 which adds the tag “DURATION” as a necessity, but a necessity that no
 software seems to use and it is not even a standard in the Matroska’s
 documentation if I am not mistaken. So the fact that it is a necessity
 and not a choice is the main problem.

>>> Who says it's a necessity or standard? It's just what mkvmerge does.
>>> Since the patch is by google, I assume google has some use for it
>>> (there might also be a discussion about it on the ML).
>>>
>> Sorry for the bad word “necessity”, it is better with “imposed”. Could
>> you let the choice to the user like mkvmerge with
>> “--disable-track-statistics-tags”?
>>
> We could add a private option to the ffmpeg matroska muxer to disable
> writing this tag, and we could even switch that option off by default
> (so the tag isn't written unless the user explicitly requests it). Feel
> free to propose a patch.
>

I do not have the capacity for the moment to write patches for such a
software but what you have written is exactly what I would like.

I can create a bug report if needed.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Offset index timestamps by the minimum pts to make first pts zero.

2017-06-09 Thread Sasi Inguva
That's great. Thanks.

On Jun 9, 2017 9:24 AM, "wm4" <nfx...@googlemail.com> wrote:

> On Tue,  6 Jun 2017 11:16:01 -0700
> Sasi Inguva <isasi-at-google@ffmpeg.org> wrote:
>
> > Fixes t/6421. If the videos starts with B frame, then the minimum
> composition time as computed by stts + ctts will be non-zero. Hence we need
> to shift the DTS, so that the first pts is zero. This was the intention of
> that code-block. However it was subtracting by the wrong amount.
> > For example, for one of the videos in the bug nonFormatted.mp4 we have
> > stts:
> > sample_count  duration
> > 960  1001
> > ctts:
> > sample_count  duration
> > 1   3003
> > 2   0
> > 1   3003
> > 
> >
> > The resulting composition times are :  3003, 1001, 2002, 6006, ...
> > The minimum composition time or PTS is 1001, which should be used to
> offset DTS. However the code block was wrongly using ctts[0] which is 3003.
> Hence the PTS was negative. This change computes the minimum pts
> encountered while fixing the index, and then subtracts it from all the
> timestamps after the edit list fixes are applied.
> >
> > fate-suite/h264/twofields_packet.mp4 is a similar file starting with 2
> Bframes. Before this change the PTS of first two B-frames was -6006 and
> -3003, and I am guessing one of them got dropped when being decoded and
> remuxed  to the framecrc before, and now it is not being dropped.
> >
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
>
> Applied. I added line breaks and white space to the commit message, and
> added links to those chromium issues. I hope that's ok.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Offset index timestamps by the minimum pts to make first pts zero.

2017-06-08 Thread Sasi Inguva
Ping!

On Jun 6, 2017 11:17 AM, "Sasi Inguva" <is...@google.com> wrote:

> Got it. Added to the description.
>
> On Tue, Jun 6, 2017 at 6:51 AM, wm4 <nfx...@googlemail.com> wrote:
>
>> On Sat, 3 Jun 2017 19:31:37 -0700
>> Sasi Inguva <isasi-at-google@ffmpeg.org> wrote:
>>
>> > > -// Offset the DTS by ctts[0] to make the PTS of the first frame 0
>> > > -if (ctts_data_old && ctts_count_old > 0) {
>> > > -edit_list_dts_entry_end -= ctts_data_old[0].duration;
>> > > -av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by
>> ctts[%d].duration:
>> > %d\n", 0, ctts_data_old[0].duration);
>> > > +av_log(mov->fc, AV_LOG_DEBUG, "Shifting DTS by %d because of
>> > negative CTTS.\n", msc->dts_shift);
>> > >  }
>> >
>> > The above lines were the cause of making the first frame PTS of videos
>> > starting with B-frames negative. If the videos starts with B frame, then
>> > the minimum composition time as computed by stts + ctts will be
>> non-zero.
>> > Hence we need to shift the DTS, so that the first pts is zero. This was
>> the
>> > intention of that code-block. However it was subtracting by the wrong
>> > amount.
>> > For example, for one of the videos in the bug nonFormatted.mp4 we have
>> > stts:
>> > sample_count  duration
>> > 960  1001
>> > ctts:
>> > sample_count  duration
>> > 1   3003
>> > 2   0
>> > 1   3003
>> > 
>> >
>> > The resulting composition times are :  3003, 1001, 2002, 6006, ...
>> > Hence the minimum composition time or PTS is 1001, which should be used
>> to
>> > offset DTS. However the code block was wrongly using ctts[0] which is
>> 3003
>> > . Hence the PTS  was negative.
>> >
>> > About the fate test expectations, fate-suite/h264/twofields_packet.mp4
>> is a
>> > similar file starting with 2 Bframes. Before this change the PTS of
>> first
>> > two B-frames was -6006 and -3003, and I am guessing one of them got
>> dropped
>> > when being decoded and remuxed  to the framecrc before, and now it is
>> not
>> > being dropped but I dont understand why.
>>
>> All of this should go into the commit message.
>>
>> Can't judge the correctness of the actual code.
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Offset index timestamps by the minimum pts to make first pts zero.

2017-06-06 Thread Sasi Inguva
Got it. Added to the description.

On Tue, Jun 6, 2017 at 6:51 AM, wm4 <nfx...@googlemail.com> wrote:

> On Sat, 3 Jun 2017 19:31:37 -0700
> Sasi Inguva <isasi-at-google@ffmpeg.org> wrote:
>
> > > -// Offset the DTS by ctts[0] to make the PTS of the first frame 0
> > > -if (ctts_data_old && ctts_count_old > 0) {
> > > -edit_list_dts_entry_end -= ctts_data_old[0].duration;
> > > -av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by
> ctts[%d].duration:
> > %d\n", 0, ctts_data_old[0].duration);
> > > +av_log(mov->fc, AV_LOG_DEBUG, "Shifting DTS by %d because of
> > negative CTTS.\n", msc->dts_shift);
> > >  }
> >
> > The above lines were the cause of making the first frame PTS of videos
> > starting with B-frames negative. If the videos starts with B frame, then
> > the minimum composition time as computed by stts + ctts will be non-zero.
> > Hence we need to shift the DTS, so that the first pts is zero. This was
> the
> > intention of that code-block. However it was subtracting by the wrong
> > amount.
> > For example, for one of the videos in the bug nonFormatted.mp4 we have
> > stts:
> > sample_count  duration
> > 960  1001
> > ctts:
> > sample_count  duration
> > 1   3003
> > 2   0
> > 1   3003
> > 
> >
> > The resulting composition times are :  3003, 1001, 2002, 6006, ...
> > Hence the minimum composition time or PTS is 1001, which should be used
> to
> > offset DTS. However the code block was wrongly using ctts[0] which is
> 3003
> > . Hence the PTS  was negative.
> >
> > About the fate test expectations, fate-suite/h264/twofields_packet.mp4
> is a
> > similar file starting with 2 Bframes. Before this change the PTS of first
> > two B-frames was -6006 and -3003, and I am guessing one of them got
> dropped
> > when being decoded and remuxed  to the framecrc before, and now it is not
> > being dropped but I dont understand why.
>
> All of this should go into the commit message.
>
> Can't judge the correctness of the actual code.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/mov.c: Offset index timestamps by the minimum pts to make first pts zero.

2017-06-06 Thread Sasi Inguva
Fixes t/6421. If the videos starts with B frame, then the minimum composition 
time as computed by stts + ctts will be non-zero. Hence we need to shift the 
DTS, so that the first pts is zero. This was the intention of that code-block. 
However it was subtracting by the wrong amount.
For example, for one of the videos in the bug nonFormatted.mp4 we have
stts:
sample_count  duration
960  1001
ctts:
sample_count  duration
1   3003
2   0
1   3003


The resulting composition times are :  3003, 1001, 2002, 6006, ...
The minimum composition time or PTS is 1001, which should be used to offset 
DTS. However the code block was wrongly using ctts[0] which is 3003. Hence the 
PTS was negative. This change computes the minimum pts encountered while fixing 
the index, and then subtracts it from all the timestamps after the edit list 
fixes are applied.

fate-suite/h264/twofields_packet.mp4 is a similar file starting with 2 Bframes. 
Before this change the PTS of first two B-frames was -6006 and -3003, and I am 
guessing one of them got dropped when being decoded and remuxed  to the 
framecrc before, and now it is not being dropped.

Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 57 --
 tests/ref/fate/h264-twofields-packet | 60 ++--
 2 files changed, 70 insertions(+), 47 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 3845e63b53..d7d64c3361 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3039,6 +3039,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int64_t edit_list_dts_entry_end = 0;
 int64_t edit_list_start_ctts_sample = 0;
 int64_t curr_cts;
+int64_t curr_ctts = 0;
+int64_t min_corrected_pts = -1;
+int64_t empty_edits_sum_duration = 0;
 int64_t edit_list_index = 0;
 int64_t index;
 int64_t index_ctts_count;
@@ -3053,6 +3056,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int first_non_zero_audio_edit = -1;
 int packet_skip_samples = 0;
 MOVIndexRange *current_index_range;
+int i;
 
 if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
 return;
@@ -3080,13 +3084,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // If the dts_shift is positive (in case of negative ctts values in mov),
 // then negate the DTS by dts_shift
-if (msc->dts_shift > 0)
+if (msc->dts_shift > 0) {
 edit_list_dts_entry_end -= msc->dts_shift;
-
-// Offset the DTS by ctts[0] to make the PTS of the first frame 0
-if (ctts_data_old && ctts_count_old > 0) {
-edit_list_dts_entry_end -= ctts_data_old[0].duration;
-av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by ctts[%d].duration: %d\n", 
0, ctts_data_old[0].duration);
+av_log(mov->fc, AV_LOG_DEBUG, "Shifting DTS by %d because of negative 
CTTS.\n", msc->dts_shift);
 }
 
 start_dts = edit_list_dts_entry_end;
@@ -3100,6 +3100,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 edit_list_dts_entry_end += edit_list_duration;
 num_discarded_begin = 0;
 if (edit_list_media_time == -1) {
+empty_edits_sum_duration += edit_list_duration;
 continue;
 }
 
@@ -3179,11 +3180,13 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // frames (pts) before or after edit list
 curr_cts = current->timestamp + msc->dts_shift;
+curr_ctts = 0;
 
 if (ctts_data_old && ctts_index_old < ctts_count_old) {
-av_log(mov->fc, AV_LOG_DEBUG, "shifted frame pts, curr_cts: 
%"PRId64" @ %"PRId64", ctts: %d, ctts_count: %"PRId64"\n",
-   curr_cts, ctts_index_old, 
ctts_data_old[ctts_index_old].duration, ctts_count_old);
-curr_cts += ctts_data_old[ctts_index_old].duration;
+curr_ctts = ctts_data_old[ctts_index_old].duration;
+av_log(mov->fc, AV_LOG_DEBUG, "stts: %"PRId64" ctts: 
%"PRId64", ctts_index: %"PRId64", ctts_count: %"PRId64"\n",
+   curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
+curr_cts += curr_ctts;
 ctts_sample_old++;
 if (ctts_sample_old == ctts_data_old[ctts_index_old].count) {
 if (add_ctts_entry(>ctts_data, >ctts_count,
@@ -3244,14 +3247,21 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 }
 }
-} else if (edit_list_start_encountered == 0) {
-edit_list_start_encountered = 1;
-// Make timestamps strictly monotonically increasing for 
audio, by rewriting timestamps for
-   

Re: [FFmpeg-devel] [PATCH] lavf/mov.c: Offset index timestamps by the minimum pts to make first pts zero.

2017-06-03 Thread Sasi Inguva
> -// Offset the DTS by ctts[0] to make the PTS of the first frame 0
> -if (ctts_data_old && ctts_count_old > 0) {
> -edit_list_dts_entry_end -= ctts_data_old[0].duration;
> -av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by ctts[%d].duration:
%d\n", 0, ctts_data_old[0].duration);
> +av_log(mov->fc, AV_LOG_DEBUG, "Shifting DTS by %d because of
negative CTTS.\n", msc->dts_shift);
>  }

The above lines were the cause of making the first frame PTS of videos
starting with B-frames negative. If the videos starts with B frame, then
the minimum composition time as computed by stts + ctts will be non-zero.
Hence we need to shift the DTS, so that the first pts is zero. This was the
intention of that code-block. However it was subtracting by the wrong
amount.
For example, for one of the videos in the bug nonFormatted.mp4 we have
stts:
sample_count  duration
960  1001
ctts:
sample_count  duration
1   3003
2   0
1   3003


The resulting composition times are :  3003, 1001, 2002, 6006, ...
Hence the minimum composition time or PTS is 1001, which should be used to
offset DTS. However the code block was wrongly using ctts[0] which is 3003
. Hence the PTS  was negative.

About the fate test expectations, fate-suite/h264/twofields_packet.mp4 is a
similar file starting with 2 Bframes. Before this change the PTS of first
two B-frames was -6006 and -3003, and I am guessing one of them got dropped
when being decoded and remuxed  to the framecrc before, and now it is not
being dropped but I dont understand why.

On Sat, Jun 3, 2017 at 5:40 AM, wm4 <nfx...@googlemail.com> wrote:

> On Fri,  2 Jun 2017 18:17:22 -0700
> Sasi Inguva <isasi-at-google@ffmpeg.org> wrote:
>
> > Fixes t/6421
> >
> > Signed-off-by: Sasi Inguva <is...@google.com>
> > ---
> >  libavformat/mov.c| 57 --
> 
> >  tests/ref/fate/h264-twofields-packet | 60
> ++--
> >  2 files changed, 70 insertions(+), 47 deletions(-)
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index 3845e63b53..d7d64c3361 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -3039,6 +3039,9 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
> >  int64_t edit_list_dts_entry_end = 0;
> >  int64_t edit_list_start_ctts_sample = 0;
> >  int64_t curr_cts;
> > +int64_t curr_ctts = 0;
> > +int64_t min_corrected_pts = -1;
> > +int64_t empty_edits_sum_duration = 0;
> >  int64_t edit_list_index = 0;
> >  int64_t index;
> >  int64_t index_ctts_count;
> > @@ -3053,6 +3056,7 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
> >  int first_non_zero_audio_edit = -1;
> >  int packet_skip_samples = 0;
> >  MOVIndexRange *current_index_range;
> > +int i;
> >
> >  if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
> >  return;
> > @@ -3080,13 +3084,9 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
> >
> >  // If the dts_shift is positive (in case of negative ctts values in
> mov),
> >  // then negate the DTS by dts_shift
> > -if (msc->dts_shift > 0)
> > +if (msc->dts_shift > 0) {
> >  edit_list_dts_entry_end -= msc->dts_shift;
> > -
> > -// Offset the DTS by ctts[0] to make the PTS of the first frame 0
> > -if (ctts_data_old && ctts_count_old > 0) {
> > -edit_list_dts_entry_end -= ctts_data_old[0].duration;
> > -av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by ctts[%d].duration:
> %d\n", 0, ctts_data_old[0].duration);
> > +av_log(mov->fc, AV_LOG_DEBUG, "Shifting DTS by %d because of
> negative CTTS.\n", msc->dts_shift);
> >  }
> >
> >  start_dts = edit_list_dts_entry_end;
> > @@ -3100,6 +3100,7 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
> >  edit_list_dts_entry_end += edit_list_duration;
> >  num_discarded_begin = 0;
> >  if (edit_list_media_time == -1) {
> > +empty_edits_sum_duration += edit_list_duration;
> >  continue;
> >  }
> >
> > @@ -3179,11 +3180,13 @@ static void mov_fix_index(MOVContext *mov,
> AVStream *st)
> >
> >  // frames (pts) before or after edit list
> >  curr_cts = current->timestamp + msc->dts_shift;
> > +curr_ctts = 0;
> >
> >  if (ctts_data_old && ctts_in

[FFmpeg-devel] [PATCH] lavf/mov.c: Offset index timestamps by the minimum pts to make first pts zero.

2017-06-02 Thread Sasi Inguva
Fixes t/6421

Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c| 57 --
 tests/ref/fate/h264-twofields-packet | 60 ++--
 2 files changed, 70 insertions(+), 47 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 3845e63b53..d7d64c3361 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3039,6 +3039,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int64_t edit_list_dts_entry_end = 0;
 int64_t edit_list_start_ctts_sample = 0;
 int64_t curr_cts;
+int64_t curr_ctts = 0;
+int64_t min_corrected_pts = -1;
+int64_t empty_edits_sum_duration = 0;
 int64_t edit_list_index = 0;
 int64_t index;
 int64_t index_ctts_count;
@@ -3053,6 +3056,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 int first_non_zero_audio_edit = -1;
 int packet_skip_samples = 0;
 MOVIndexRange *current_index_range;
+int i;
 
 if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) {
 return;
@@ -3080,13 +3084,9 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // If the dts_shift is positive (in case of negative ctts values in mov),
 // then negate the DTS by dts_shift
-if (msc->dts_shift > 0)
+if (msc->dts_shift > 0) {
 edit_list_dts_entry_end -= msc->dts_shift;
-
-// Offset the DTS by ctts[0] to make the PTS of the first frame 0
-if (ctts_data_old && ctts_count_old > 0) {
-edit_list_dts_entry_end -= ctts_data_old[0].duration;
-av_log(mov->fc, AV_LOG_DEBUG, "Offset DTS by ctts[%d].duration: %d\n", 
0, ctts_data_old[0].duration);
+av_log(mov->fc, AV_LOG_DEBUG, "Shifting DTS by %d because of negative 
CTTS.\n", msc->dts_shift);
 }
 
 start_dts = edit_list_dts_entry_end;
@@ -3100,6 +3100,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 edit_list_dts_entry_end += edit_list_duration;
 num_discarded_begin = 0;
 if (edit_list_media_time == -1) {
+empty_edits_sum_duration += edit_list_duration;
 continue;
 }
 
@@ -3179,11 +3180,13 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 
 // frames (pts) before or after edit list
 curr_cts = current->timestamp + msc->dts_shift;
+curr_ctts = 0;
 
 if (ctts_data_old && ctts_index_old < ctts_count_old) {
-av_log(mov->fc, AV_LOG_DEBUG, "shifted frame pts, curr_cts: 
%"PRId64" @ %"PRId64", ctts: %d, ctts_count: %"PRId64"\n",
-   curr_cts, ctts_index_old, 
ctts_data_old[ctts_index_old].duration, ctts_count_old);
-curr_cts += ctts_data_old[ctts_index_old].duration;
+curr_ctts = ctts_data_old[ctts_index_old].duration;
+av_log(mov->fc, AV_LOG_DEBUG, "stts: %"PRId64" ctts: 
%"PRId64", ctts_index: %"PRId64", ctts_count: %"PRId64"\n",
+   curr_cts, curr_ctts, ctts_index_old, ctts_count_old);
+curr_cts += curr_ctts;
 ctts_sample_old++;
 if (ctts_sample_old == ctts_data_old[ctts_index_old].count) {
 if (add_ctts_entry(>ctts_data, >ctts_count,
@@ -3244,14 +3247,21 @@ static void mov_fix_index(MOVContext *mov, AVStream *st)
 }
 }
 }
-} else if (edit_list_start_encountered == 0) {
-edit_list_start_encountered = 1;
-// Make timestamps strictly monotonically increasing for 
audio, by rewriting timestamps for
-// discarded packets.
-if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
frame_duration_buffer) {
-fix_index_entry_timestamps(st, st->nb_index_entries, 
edit_list_dts_counter,
-   frame_duration_buffer, 
num_discarded_begin);
-av_freep(_duration_buffer);
+} else {
+if (min_corrected_pts < 0) {
+min_corrected_pts = edit_list_dts_counter + curr_ctts + 
msc->dts_shift;
+} else {
+min_corrected_pts = FFMIN(min_corrected_pts, 
edit_list_dts_counter + curr_ctts + msc->dts_shift);
+}
+if (edit_list_start_encountered == 0) {
+edit_list_start_encountered = 1;
+// Make timestamps strictly monotonically increasing for 
audio, by rewriting timestamps for
+// discarded packets.
+if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && 
frame_duration_buffer) {
+ 

[FFmpeg-devel] [PATCH] lavf/mov.c: Correct keyframe search in edit list to return the very first keyframe/frame with matching timestamp. Fixes ticket#5904

2017-02-15 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/mov.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index b5181775e7..2a7cbfe142 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2847,11 +2847,23 @@ static int64_t find_prev_closest_index(AVStream *st,
 AVIndexEntry *e_keep = st->index_entries;
 int nb_keep = st->nb_index_entries;
 int64_t found = -1;
+int64_t i = 0;
 
 st->index_entries = e_old;
 st->nb_index_entries = nb_old;
 found = av_index_search_timestamp(st, timestamp, flag | 
AVSEEK_FLAG_BACKWARD);
 
+// Keep going backwards in the index entries until the timestamp is the 
same.
+if (found >= 0) {
+for (i = found; i > 0 && e_old[i].timestamp == e_old[i - 1].timestamp;
+ i--) {
+if ((flag & AVSEEK_FLAG_ANY) ||
+(e_old[i - 1].flags & AVINDEX_KEYFRAME)) {
+found = i - 1;
+}
+}
+}
+
 /* restore AVStream state*/
 st->index_entries = e_keep;
 st->nb_index_entries = nb_keep;
-- 
2.11.0.483.g087da7b7c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] mov: support for multiple edits and cenc decryption

2017-01-30 Thread Sasi Inguva
patch looks good to me.

Thanks.

On Mon, Jan 30, 2017 at 6:48 AM, Michael Niedermayer <michae...@gmx.at>
wrote:

> On Mon, Jan 30, 2017 at 03:39:19PM +0100, Michael Niedermayer wrote:
> > On Mon, Jan 30, 2017 at 10:51:02AM +, Eran Kornblau wrote:
> > > > -Original Message-
> > > > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> Behalf Of Sasi Inguva
> > > > Sent: Wednesday, January 18, 2017 3:30 AM
> > > > To: FFmpeg development discussions and patches <
> ffmpeg-devel@ffmpeg.org>
> > > > Subject: Re: [FFmpeg-devel] mov: support for multiple edits and cenc
> decryption
> > > >
> > > > Can you add a fate test ? Rest looks fine to me.
> > > >
> > > Attached:
> > > 1. Fate test
> > > 2. The original patch
> >
> > > 3. Sample file - needs to be uploaded to $(TARGET_SAMPLES)/mov/mov-
> 3elist-encrypted.mov
> >
> > uploaded
> > fate tested on x86 32/64 linux, mingw32/64, arm
>
> tested on qemu mips as well
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Modern terrorism, a quick summary: Need oil, start war with country that
> has oil, kill hundread thousand in war. Let country fall into chaos,
> be surprised about raise of fundamantalists. Drop more bombs, kill more
> people, be surprised about them taking revenge and drop even more bombs
> and strip your own citizens of their rights and freedoms. to be continued
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/matroskaenc.c: Free dyn bufs in mkv_free. Fixes memory leaks when muxing fails.

2017-01-26 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 libavformat/matroskaenc.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index f731b678b9..88f6c647b9 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -393,6 +393,23 @@ static void put_xiph_size(AVIOContext *pb, int size)
  * Free the members allocated in the mux context.
  */
 static void mkv_free(MatroskaMuxContext *mkv) {
+uint8_t* buf;
+if (mkv->dyn_bc) {
+avio_close_dyn_buf(mkv->dyn_bc, );
+av_free(buf);
+}
+if (mkv->info_bc) {
+avio_close_dyn_buf(mkv->info_bc, );
+av_free(buf);
+}
+if (mkv->tracks_bc) {
+avio_close_dyn_buf(mkv->tracks_bc, );
+av_free(buf);
+}
+if (mkv->tags_bc) {
+avio_close_dyn_buf(mkv->tags_bc, );
+av_free(buf);
+}
 if (mkv->main_seekhead) {
 av_freep(>main_seekhead->entries);
 av_freep(>main_seekhead);
-- 
2.11.0.483.g087da7b7c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg.c: Add output file index and stream index to vstats file.

2017-01-25 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 doc/ffmpeg.texi | 8 +++-
 ffmpeg.c| 9 +++--
 ffmpeg_opt.c| 2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index cdea1a271f..996d6a6cc4 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -637,9 +637,15 @@ Dump video coding statistics to @file{vstats_HHMMSS.log}.
 @item -vstats_file @var{file}
 Dump video coding statistics to @var{file}.
 @item -vstats_version @var{file}
-Specifies which version of the vstats format to use. If version is 1, format is
+Specifies which version of the vstats format to use. Default is 2.
+
+version = 1 :
 
 @code{frame= %5d q= %2.1f PSNR= %6.2f f_size= %6d s_size= %8.0fkB time= %0.3f 
br= %7.1fkbits/s avg_br= %7.1fkbits/s}
+
+version > 1:
+
+@code{out= %2d st= %2d frame= %5d q= %2.1f PSNR= %6.2f f_size= %6d s_size= 
%8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s}
 @item -top[:@var{stream_specifier}] @var{n} (@emph{output,per-stream})
 top=1/bottom=0/auto=-1 field first
 @item -dc @var{precision}
diff --git a/ffmpeg.c b/ffmpeg.c
index 977708c069..0a8f448995 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1347,8 +1347,13 @@ static void do_video_stats(OutputStream *ost, int 
frame_size)
 enc = ost->enc_ctx;
 if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 frame_number = ost->st->nb_frames;
-fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
-ost->quality / (float)FF_QP2LAMBDA);
+if (vstats_version <= 1) {
+fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
+ost->quality / (float)FF_QP2LAMBDA);
+} else  {
+fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", 
ost->file_index, ost->index, frame_number,
+ost->quality / (float)FF_QP2LAMBDA);
+}
 
 if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
 fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / 
(enc->width * enc->height * 255.0 * 255.0)));
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index b1a62e8620..6a47d32b53 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -121,7 +121,7 @@ int frame_bits_per_raw_sample = 0;
 float max_error_rate  = 2.0/3;
 int filter_nbthreads = 0;
 int filter_complex_nbthreads = 0;
-int vstats_version = 1;
+int vstats_version = 2;
 
 
 static int intra_only = 0;
-- 
2.11.0.483.g087da7b7c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] ffmpeg.c: Add output file index and stream index to vstats file.

2017-01-25 Thread Sasi Inguva
Updated the patch with using vstats_version. PTAL.

On Sat, Jan 21, 2017 at 3:52 AM, Michael Niedermayer <michae...@gmx.at>
wrote:

> On Fri, Jan 20, 2017 at 07:31:09PM -0800, Sasi Inguva wrote:
> > Couldn't find any version that relates to vstats. There is nothing that
> > says format may change any time , but there is no defined format either.
> > Let me know the version enum I have to update if I need to.
>
> i dont think theres a enum
> I think the way to resolve this is to send a patch that updates the
> docs and either state that vstats format can change at any time or
> that it cannot in which case something like a -vtstats_version
> parameter would need to be added
>
> When the docs patch passes review, that is everyone is happy with the
> solution it describes then the change with or without a version
> check which either way then matches the docs can be pushed
>
> thx
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Dictatorship: All citizens are under surveillance, all their steps and
> actions recorded, for the politicians to enforce control.
> Democracy: All politicians are under surveillance, all their steps and
> actions recorded, for the citizens to enforce control.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
From 9bc4d038af3478467eddc45a634b0e03e163dc39 Mon Sep 17 00:00:00 2001
From: Sasi Inguva <is...@google.com>
Date: Thu, 19 Jan 2017 14:33:32 -0800
Subject: [PATCH] ffmpeg.c: Add output file index and stream index to vstats
 file.

Signed-off-by: Sasi Inguva <is...@google.com>
---
 doc/ffmpeg.texi | 8 +++-
 ffmpeg.c| 9 +++--
 ffmpeg_opt.c| 2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index cdea1a271f..996d6a6cc4 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -637,9 +637,15 @@ Dump video coding statistics to @file{vstats_HHMMSS.log}.
 @item -vstats_file @var{file}
 Dump video coding statistics to @var{file}.
 @item -vstats_version @var{file}
-Specifies which version of the vstats format to use. If version is 1, format is
+Specifies which version of the vstats format to use. Default is 2.
+
+version = 1 :
 
 @code{frame= %5d q= %2.1f PSNR= %6.2f f_size= %6d s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s}
+
+version > 1:
+
+@code{out= %2d st= %2d frame= %5d q= %2.1f PSNR= %6.2f f_size= %6d s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s}
 @item -top[:@var{stream_specifier}] @var{n} (@emph{output,per-stream})
 top=1/bottom=0/auto=-1 field first
 @item -dc @var{precision}
diff --git a/ffmpeg.c b/ffmpeg.c
index 977708c069..0a8f448995 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1347,8 +1347,13 @@ static void do_video_stats(OutputStream *ost, int frame_size)
 enc = ost->enc_ctx;
 if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
 frame_number = ost->st->nb_frames;
-fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
-ost->quality / (float)FF_QP2LAMBDA);
+if (vstats_version <= 1) {
+fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
+ost->quality / (float)FF_QP2LAMBDA);
+} else  {
+fprintf(vstats_file, "out= %2d st= %2d frame= %5d q= %2.1f ", ost->file_index, ost->index, frame_number,
+ost->quality / (float)FF_QP2LAMBDA);
+}
 
 if (ost->error[0]>=0 && (enc->flags & AV_CODEC_FLAG_PSNR))
 fprintf(vstats_file, "PSNR= %6.2f ", psnr(ost->error[0] / (enc->width * enc->height * 255.0 * 255.0)));
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index b1a62e8620..6a47d32b53 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -121,7 +121,7 @@ int frame_bits_per_raw_sample = 0;
 float max_error_rate  = 2.0/3;
 int filter_nbthreads = 0;
 int filter_complex_nbthreads = 0;
-int vstats_version = 1;
+int vstats_version = 2;
 
 
 static int intra_only = 0;
-- 
2.11.0.483.g087da7b7c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] ffmpeg_opt.c: Introduce a -vstats_version option and document the existing -vstats format.

2017-01-24 Thread Sasi Inguva
Signed-off-by: Sasi Inguva <is...@google.com>
---
 doc/ffmpeg.texi | 4 
 ffmpeg.h| 1 +
 ffmpeg_opt.c| 3 +++
 3 files changed, 8 insertions(+)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index b56bdbe261..cdea1a271f 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -636,6 +636,10 @@ Calculate PSNR of compressed frames.
 Dump video coding statistics to @file{vstats_HHMMSS.log}.
 @item -vstats_file @var{file}
 Dump video coding statistics to @var{file}.
+@item -vstats_version @var{file}
+Specifies which version of the vstats format to use. If version is 1, format is
+
+@code{frame= %5d q= %2.1f PSNR= %6.2f f_size= %6d s_size= %8.0fkB time= %0.3f 
br= %7.1fkbits/s avg_br= %7.1fkbits/s}
 @item -top[:@var{stream_specifier}] @var{n} (@emph{output,per-stream})
 top=1/bottom=0/auto=-1 field first
 @item -dc @var{precision}
diff --git a/ffmpeg.h b/ffmpeg.h
index 75bf50ec29..458bb8a3dc 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -597,6 +597,7 @@ extern char *videotoolbox_pixfmt;
 
 extern int filter_nbthreads;
 extern int filter_complex_nbthreads;
+extern int vstats_version;
 
 extern const AVIOInterruptCB int_cb;
 
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index a1c02fc29b..b1a62e8620 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -121,6 +121,7 @@ int frame_bits_per_raw_sample = 0;
 float max_error_rate  = 2.0/3;
 int filter_nbthreads = 0;
 int filter_complex_nbthreads = 0;
+int vstats_version = 1;
 
 
 static int intra_only = 0;
@@ -3547,6 +3548,8 @@ const OptionDef options[] = {
 "dump video coding statistics to file" },
 { "vstats_file",  OPT_VIDEO | HAS_ARG | OPT_EXPERT ,   
  { .func_arg = opt_vstats_file },
 "dump video coding statistics to file", "file" },
+{ "vstats_version",  OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT ,  
  { _version },
+"Version of the vstats format to use."},
 { "vf",   OPT_VIDEO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT, 
  { .func_arg = opt_video_filters },
 "set video filters", "filter_graph" },
 { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT  | OPT_STRING | 
OPT_SPEC |
-- 
2.11.0.483.g087da7b7c-goog

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


  1   2   3   >