* [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files
@ 2023-09-23 11:10 llyyr
2024-02-26 21:52 ` llyyr
0 siblings, 1 reply; 7+ messages in thread
From: llyyr @ 2023-09-23 11:10 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: llyyr
ab77b878f1 attempted to fix the issue of broken packets being sent to
the decoder by implementing logic that kept attempting to PTS-step
backwards until it reached a valid point, however applying this
heuristic meant that in files that had no valid points (such as HEVC
videos shot on iPhones), we'd seek back to sample 0 on every seek
attempt. This meant that files that were previously seekable, albeit
with some skipped frames, were not seekable at all now.
Relax this heuristic a bit by giving up on seeking to a valid point if
we've tried a different sample and we still don't have a valid point to
seek to. This may some frames to be skipped on seeking but it's better
than not being able to seek at all in such files.
Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP files")
---
libavformat/mov.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1996e0028c..60a4d581d9 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -9108,7 +9108,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
- int sample, time_sample, ret;
+ int sample, time_sample, ret, next_ts, requested_sample;
unsigned int i;
// Here we consider timestamp to be PTS, hence try to offset it so that we
@@ -9129,7 +9129,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
- timestamp -= FFMAX(sc->min_sample_duration, 1);
+
+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
+ requested_sample = av_index_search_timestamp(st, next_ts, flags);
+
+ // If we can't seek to the next pts either and it's a different sample,
+ // give up trying to find a good pts to seek to, otherwise we'll end up
+ // seeking back to sample 0 on every seek.
+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
+ break;
+
+ timestamp = next_ts;
}
mov_current_sample_set(sc, sample);
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files
2023-09-23 11:10 [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files llyyr
@ 2024-02-26 21:52 ` llyyr
0 siblings, 0 replies; 7+ messages in thread
From: llyyr @ 2024-02-26 21:52 UTC (permalink / raw)
To: ffmpeg-devel
On 9/23/23 16:40, llyyr wrote:
> ab77b878f1 attempted to fix the issue of broken packets being sent to
> the decoder by implementing logic that kept attempting to PTS-step
> backwards until it reached a valid point, however applying this
> heuristic meant that in files that had no valid points (such as HEVC
> videos shot on iPhones), we'd seek back to sample 0 on every seek
> attempt. This meant that files that were previously seekable, albeit
> with some skipped frames, were not seekable at all now.
>
> Relax this heuristic a bit by giving up on seeking to a valid point if
> we've tried a different sample and we still don't have a valid point to
> seek to. This may some frames to be skipped on seeking but it's better
> than not being able to seek at all in such files.
>
> Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP files")
> ---
> libavformat/mov.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 1996e0028c..60a4d581d9 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -9108,7 +9108,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
> {
> MOVStreamContext *sc = st->priv_data;
> FFStream *const sti = ffstream(st);
> - int sample, time_sample, ret;
> + int sample, time_sample, ret, next_ts, requested_sample;
> unsigned int i;
>
> // Here we consider timestamp to be PTS, hence try to offset it so that we
> @@ -9129,7 +9129,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
>
> if (!sample || can_seek_to_key_sample(st, sample, timestamp))
> break;
> - timestamp -= FFMAX(sc->min_sample_duration, 1);
> +
> + next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
> + requested_sample = av_index_search_timestamp(st, next_ts, flags);
> +
> + // If we can't seek to the next pts either and it's a different sample,
> + // give up trying to find a good pts to seek to, otherwise we'll end up
> + // seeking back to sample 0 on every seek.
> + if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
> + break;
> +
> + timestamp = next_ts;
> }
>
> mov_current_sample_set(sc, sample);
Pinging this as it seems to have been missed. The patch still applies on
current master and the issue also still exists.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files
@ 2024-05-14 20:06 llyyr.public
2024-05-15 2:07 ` Philip Langdale via ffmpeg-devel
0 siblings, 1 reply; 7+ messages in thread
From: llyyr.public @ 2024-05-14 20:06 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: llyyr
From: llyyr <llyyr.public@gmail.com>
ab77b878f1 attempted to fix the issue of broken packets being sent to
the decoder by implementing logic that kept attempting to PTS-step
backwards until it reached a valid point, however applying this
heuristic meant that in files that had no valid points (such as HEVC
videos shot on iPhones), we'd seek back to sample 0 on every seek
attempt. This meant that files that were previously seekable, albeit
with some skipped frames, were not seekable at all now.
Relax this heuristic a bit by giving up on seeking to a valid point if
we've tried a different sample and we still don't have a valid point to
seek to. This may some frames to be skipped on seeking but it's better
than not being able to seek at all in such files.
Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP files")
Fixes: #10585
---
libavformat/mov.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index b3fa748f27e8..6174a04c3169 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10133,7 +10133,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
- int sample, time_sample, ret;
+ int sample, time_sample, ret, next_ts, requested_sample;
unsigned int i;
// Here we consider timestamp to be PTS, hence try to offset it so that we
@@ -10154,7 +10154,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
- timestamp -= FFMAX(sc->min_sample_duration, 1);
+
+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
+ requested_sample = av_index_search_timestamp(st, next_ts, flags);
+
+ // If we've reached a different sample trying to find a good pts to
+ // seek to, give up searching because we'll end up seeking back to
+ // sample 0 on every seek.
+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
+ break;
+
+ timestamp = next_ts;
}
mov_current_sample_set(sc, sample);
--
2.45.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files
2024-05-14 20:06 llyyr.public
@ 2024-05-15 2:07 ` Philip Langdale via ffmpeg-devel
2024-05-22 1:59 ` Philip Langdale via ffmpeg-devel
0 siblings, 1 reply; 7+ messages in thread
From: Philip Langdale via ffmpeg-devel @ 2024-05-15 2:07 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Philip Langdale
On Wed, 15 May 2024 01:36:43 +0530
llyyr.public@gmail.com wrote:
> From: llyyr <llyyr.public@gmail.com>
>
> ab77b878f1 attempted to fix the issue of broken packets being sent to
> the decoder by implementing logic that kept attempting to PTS-step
> backwards until it reached a valid point, however applying this
> heuristic meant that in files that had no valid points (such as HEVC
> videos shot on iPhones), we'd seek back to sample 0 on every seek
> attempt. This meant that files that were previously seekable, albeit
> with some skipped frames, were not seekable at all now.
>
> Relax this heuristic a bit by giving up on seeking to a valid point if
> we've tried a different sample and we still don't have a valid point
> to seek to. This may some frames to be skipped on seeking but it's
> better than not being able to seek at all in such files.
>
> Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP
> files") Fixes: #10585
> ---
> libavformat/mov.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index b3fa748f27e8..6174a04c3169 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -10133,7 +10133,7 @@ static int mov_seek_stream(AVFormatContext
> *s, AVStream *st, int64_t timestamp, {
> MOVStreamContext *sc = st->priv_data;
> FFStream *const sti = ffstream(st);
> - int sample, time_sample, ret;
> + int sample, time_sample, ret, next_ts, requested_sample;
> unsigned int i;
>
> // Here we consider timestamp to be PTS, hence try to offset it
> so that we @@ -10154,7 +10154,17 @@ static int
> mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
> if (!sample || can_seek_to_key_sample(st, sample, timestamp))
> break;
> - timestamp -= FFMAX(sc->min_sample_duration, 1);
> +
> + next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
> + requested_sample = av_index_search_timestamp(st, next_ts,
> flags); +
> + // If we've reached a different sample trying to find a good
> pts to
> + // seek to, give up searching because we'll end up seeking
> back to
> + // sample 0 on every seek.
> + if (!can_seek_to_key_sample(st, requested_sample, next_ts)
> && sample != requested_sample)
> + break;
> +
> + timestamp = next_ts;
> }
>
> mov_current_sample_set(sc, sample);
LGTM.
I know it's been a _long time_ since you first sent this; I'll push next
week if there aren't any other comments.
--phil
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files
2024-05-15 2:07 ` Philip Langdale via ffmpeg-devel
@ 2024-05-22 1:59 ` Philip Langdale via ffmpeg-devel
0 siblings, 0 replies; 7+ messages in thread
From: Philip Langdale via ffmpeg-devel @ 2024-05-22 1:59 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Philip Langdale
On Tue, 14 May 2024 19:07:59 -0700
Philip Langdale via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> wrote:
> On Wed, 15 May 2024 01:36:43 +0530
> llyyr.public@gmail.com wrote:
>
> > From: llyyr <llyyr.public@gmail.com>
> >
> > ab77b878f1 attempted to fix the issue of broken packets being sent
> > to the decoder by implementing logic that kept attempting to
> > PTS-step backwards until it reached a valid point, however applying
> > this heuristic meant that in files that had no valid points (such
> > as HEVC videos shot on iPhones), we'd seek back to sample 0 on
> > every seek attempt. This meant that files that were previously
> > seekable, albeit with some skipped frames, were not seekable at all
> > now.
> >
> > Relax this heuristic a bit by giving up on seeking to a valid point
> > if we've tried a different sample and we still don't have a valid
> > point to seek to. This may some frames to be skipped on seeking but
> > it's better than not being able to seek at all in such files.
> >
> > Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP
> > files") Fixes: #10585
>
> LGTM.
>
> I know it's been a _long time_ since you first sent this; I'll push
> next week if there aren't any other comments.
>
Pushed. Thanks!
--phil
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files
@ 2023-09-23 10:56 llyyr.public
0 siblings, 0 replies; 7+ messages in thread
From: llyyr.public @ 2023-09-23 10:56 UTC (permalink / raw)
To: ffmpeg-devel
ab77b878f1 attempted to fix the issue of broken packets being sent to
the decoder by implementing logic that kept attempting to PTS-step
backwards until it reached a valid point, however applying this
heuristic meant that in files that had no valid points (such as HEVC
videos shot on iPhones), we'd seek back to sample 0 on every seek
attempt. This meant that files that were previously seekable, albeit
with some skipped frames, were not seekable at all now.
Relax this heuristic a bit by giving up on seeking to a valid point if
we've tried a different sample and we still don't have a valid point to
seek to. This may some frames to be skipped on seeking but it's better
than not being able to seek at all in such files.
Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP files")
Fixes: #10585
---
libavformat/mov.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index b3fa748f27e8..6174a04c3169 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10133,7 +10133,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
- int sample, time_sample, ret;
+ int sample, time_sample, ret, next_ts, requested_sample;
unsigned int i;
// Here we consider timestamp to be PTS, hence try to offset it so that we
@@ -10154,7 +10154,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
- timestamp -= FFMAX(sc->min_sample_duration, 1);
+
+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
+ requested_sample = av_index_search_timestamp(st, next_ts, flags);
+
+ // If we've reached a different sample trying to find a good pts to
+ // seek to, give up searching because we'll end up seeking back to
+ // sample 0 on every seek.
+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
+ break;
+
+ timestamp = next_ts;
}
mov_current_sample_set(sc, sample);
base-commit: b0093ab8a3d34bf2fefd6665464cc343a9ef0d53
--
2.45.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files
@ 2023-09-23 10:56 llyyr.public
0 siblings, 0 replies; 7+ messages in thread
From: llyyr.public @ 2023-09-23 10:56 UTC (permalink / raw)
To: ffmpeg-devel
ab77b878f1 attempted to fix the issue of broken packets being sent to
the decoder by implementing logic that kept attempting to PTS-step
backwards until it reached a valid point, however applying this
heuristic meant that in files that had no valid points (such as HEVC
videos shot on iPhones), we'd seek back to sample 0 on every seek
attempt. This meant that files that were previously seekable, albeit
with some skipped frames, were not seekable at all now.
Relax this heuristic a bit by giving up on seeking to a valid point if
we've tried a different sample and we still don't have a valid point to
seek to. This may some frames to be skipped on seeking but it's better
than not being able to seek at all in such files.
Fixes: ab77b878f1 ("avformat/mov: fix seeking with HEVC open GOP files")
Fixes: #10585
---
libavformat/mov.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index b3fa748f27e8..6174a04c3169 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10133,7 +10133,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
- int sample, time_sample, ret;
+ int sample, time_sample, ret, next_ts, requested_sample;
unsigned int i;
// Here we consider timestamp to be PTS, hence try to offset it so that we
@@ -10154,7 +10154,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
- timestamp -= FFMAX(sc->min_sample_duration, 1);
+
+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
+ requested_sample = av_index_search_timestamp(st, next_ts, flags);
+
+ // If we've reached a different sample trying to find a good pts to
+ // seek to, give up searching because we'll end up seeking back to
+ // sample 0 on every seek.
+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
+ break;
+
+ timestamp = next_ts;
}
mov_current_sample_set(sc, sample);
base-commit: b0093ab8a3d34bf2fefd6665464cc343a9ef0d53
--
2.45.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-22 2:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-23 11:10 [FFmpeg-devel] [PATCH] avformat/mov: avoid seeking back to 0 on HEVC open GOP files llyyr
2024-02-26 21:52 ` llyyr
-- strict thread matches above, loose matches on Subject: below --
2024-05-14 20:06 llyyr.public
2024-05-15 2:07 ` Philip Langdale via ffmpeg-devel
2024-05-22 1:59 ` Philip Langdale via ffmpeg-devel
2023-09-23 10:56 llyyr.public
2023-09-23 10:56 llyyr.public
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git