From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
To: ffmpeg-devel@ffmpeg.org
Cc: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Subject: [FFmpeg-devel] [PATCH v2 3/5] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets
Date: Fri, 1 Mar 2024 14:39:21 +0100
Message-ID: <20240301133923.1132924-4-nicolas.gaullier@cji.paris> (raw)
In-Reply-To: <20240301133923.1132924-1-nicolas.gaullier@cji.paris>
Fix fetch_timestamp when the frame start is in a previous packet.
Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
libavcodec/parser.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index ede9e7e8b4..e4e9fbf48f 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -102,7 +102,7 @@ void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy)
s->dts = s->cur_frame_dts[i];
s->pts = s->cur_frame_pts[i];
s->pos = s->cur_frame_pos[i];
- s->offset = s->next_frame_offset - s->cur_frame_offset[i];
+ s->offset = FFMAX( 0, s->next_frame_offset - s->cur_frame_offset[i]);
}
if (remove)
s->cur_frame_offset[i] = INT64_MAX;
@@ -157,11 +157,11 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
}
if (s->fetch_timestamp) {
- s->fetch_timestamp = 0;
s->last_pts = s->pts;
s->last_dts = s->dts;
s->last_pos = s->pos;
- ff_fetch_timestamp(s, 0, 0, 0);
+ ff_fetch_timestamp(s, FFMIN(s->fetch_timestamp, 0), 0, 0);
+ s->fetch_timestamp = 0;
}
/* WARNING: the returned index can be negative */
index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf,
@@ -178,12 +178,13 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
/* update the file pointer */
if (*poutbuf_size) {
+ s->fetch_timestamp = index >= 0 || !s->frame_offset ? 1 : index;
+
/* fill the data for the current frame */
s->frame_offset = s->next_frame_offset;
/* offset of the next frame */
s->next_frame_offset = s->cur_offset + index;
- s->fetch_timestamp = 1;
} else {
/* Don't return a pointer to dummy_buf. */
*poutbuf = NULL;
--
2.30.2
_______________________________________________
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".
next prev parent reply other threads:[~2024-03-01 13:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 13:39 [FFmpeg-devel] [PATCH v2 0/5] " Nicolas Gaullier
2024-03-01 13:39 ` [FFmpeg-devel] [PATCH v2 1/5] avcodec/parser: merge packets from the same frame Nicolas Gaullier
2024-03-03 22:06 ` Michael Niedermayer
2024-03-04 17:38 ` Nicolas Gaullier
2024-03-05 20:51 ` Michael Niedermayer
2024-03-01 13:39 ` [FFmpeg-devel] [PATCH v2 2/5] avcodec/parser: reindent after previous commit Nicolas Gaullier
2024-03-01 13:39 ` Nicolas Gaullier [this message]
2024-03-01 13:39 ` [FFmpeg-devel] [PATCH v2 4/5] avcodec/h264_parser: fix start of packet for some broken streams Nicolas Gaullier
2024-03-01 13:39 ` [FFmpeg-devel] [PATCH v2 5/5] lavf/demux: duplicate side_data in parse_packet() Nicolas Gaullier
2024-03-01 13:49 ` James Almer
2024-03-01 13:54 ` James Almer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240301133923.1132924-4-nicolas.gaullier@cji.paris \
--to=nicolas.gaullier@cji.paris \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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