* [FFmpeg-devel] [PATCH] avformat/mov: fix missing extra data updating
@ 2022-03-29 18:04 Zhao Zhili
2022-04-25 10:13 ` "zhilizhao(赵志立)"
0 siblings, 1 reply; 2+ messages in thread
From: Zhao Zhili @ 2022-03-29 18:04 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
The stsc_index is checked and updated for the next sample. If the
next sample needs to update stsd_index and stsc_index, then only
stsc_index is updated, which leads to a missing
AV_PKT_DATA_NEW_EXTRADATA. For example, the sample in the second
chunk needs to update both.
entry[0]
first_chunk = 1
samples_per_chunk = 3
sample_description_index = 1
entry[1]
first_chunk = 2
samples_per_chunk = 1
sample_description_index = 2
entry[2]
first_chunk = 3
samples_per_chunk = 8
sample_description_index = 2
The fix is simple: first check and update stsd_index for current
sample, then check and update stsc_index for the next.
---
libavformat/mov.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6c847de164..c9d4f2ef43 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8591,20 +8591,20 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
/* Multiple stsd handling. */
if (sc->stsc_data) {
- /* Keep track of the stsc index for the given sample, then check
- * if the stsd index is different from the last used one. */
+ if (sc->stsc_data[sc->stsc_index].id > 0 &&
+ sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count &&
+ sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) {
+ ret = mov_change_extradata(sc, pkt);
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Update the stsc index for the next sample */
sc->stsc_sample++;
if (mov_stsc_index_valid(sc->stsc_index, sc->stsc_count) &&
mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) {
sc->stsc_index++;
sc->stsc_sample = 0;
- /* Do not check indexes after a switch. */
- } else if (sc->stsc_data[sc->stsc_index].id > 0 &&
- sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count &&
- sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) {
- ret = mov_change_extradata(sc, pkt);
- if (ret < 0)
- return ret;
}
}
--
2.31.1
_______________________________________________
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] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/mov: fix missing extra data updating
2022-03-29 18:04 [FFmpeg-devel] [PATCH] avformat/mov: fix missing extra data updating Zhao Zhili
@ 2022-04-25 10:13 ` "zhilizhao(赵志立)"
0 siblings, 0 replies; 2+ messages in thread
From: "zhilizhao(赵志立)" @ 2022-04-25 10:13 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> On Mar 30, 2022, at 2:04 AM, Zhao Zhili <quinkblack@foxmail.com> wrote:
>
> The stsc_index is checked and updated for the next sample. If the
> next sample needs to update stsd_index and stsc_index, then only
> stsc_index is updated, which leads to a missing
> AV_PKT_DATA_NEW_EXTRADATA. For example, the sample in the second
> chunk needs to update both.
>
> entry[0]
> first_chunk = 1
> samples_per_chunk = 3
> sample_description_index = 1
> entry[1]
> first_chunk = 2
> samples_per_chunk = 1
> sample_description_index = 2
> entry[2]
> first_chunk = 3
> samples_per_chunk = 8
> sample_description_index = 2
>
> The fix is simple: first check and update stsd_index for current
> sample, then check and update stsc_index for the next.
> ---
> libavformat/mov.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 6c847de164..c9d4f2ef43 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -8591,20 +8591,20 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
>
> /* Multiple stsd handling. */
> if (sc->stsc_data) {
> - /* Keep track of the stsc index for the given sample, then check
> - * if the stsd index is different from the last used one. */
> + if (sc->stsc_data[sc->stsc_index].id > 0 &&
> + sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count &&
> + sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) {
> + ret = mov_change_extradata(sc, pkt);
> + if (ret < 0)
> + return ret;
> + }
> +
> + /* Update the stsc index for the next sample */
> sc->stsc_sample++;
> if (mov_stsc_index_valid(sc->stsc_index, sc->stsc_count) &&
> mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) {
> sc->stsc_index++;
> sc->stsc_sample = 0;
> - /* Do not check indexes after a switch. */
> - } else if (sc->stsc_data[sc->stsc_index].id > 0 &&
> - sc->stsc_data[sc->stsc_index].id - 1 < sc->stsd_count &&
> - sc->stsc_data[sc->stsc_index].id - 1 != sc->last_stsd_index) {
> - ret = mov_change_extradata(sc, pkt);
> - if (ret < 0)
> - return ret;
> }
> }
>
Multi sample entry is a less used feature. Since we have it, better keep it
work. This patch fixed a corner case.
Will apply this week unless there are objections.
_______________________________________________
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] 2+ messages in thread
end of thread, other threads:[~2022-04-25 10:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 18:04 [FFmpeg-devel] [PATCH] avformat/mov: fix missing extra data updating Zhao Zhili
2022-04-25 10:13 ` "zhilizhao(赵志立)"
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