Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Nicolas Gaullier <nicolas.gaullier@cji.paris>
To: ffmpeg-devel@ffmpeg.org
Cc: Nicolas Gaullier <nicolas.gaullier@cji.paris>
Subject: [FFmpeg-devel] [PATCH v3 4/5] avcodec/h264_parser: fix start of packet for some broken streams
Date: Mon,  4 Mar 2024 18:32:18 +0100
Message-ID: <20240304173219.1877658-5-nicolas.gaullier@cji.paris> (raw)
In-Reply-To: <20240304173219.1877658-1-nicolas.gaullier@cji.paris>

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 libavcodec/h264_parser.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 94cfbc481e..6b721ec253 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -124,7 +124,16 @@ static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,
             if (nalu_type == H264_NAL_SEI || nalu_type == H264_NAL_SPS ||
                 nalu_type == H264_NAL_PPS || nalu_type == H264_NAL_AUD) {
                 if (pc->frame_start_found) {
-                    i++;
+                    /* Some streams in the wild are missing the zero_byte at the NAL_AUD:
+                     * it is following just afterwards.
+                     * To avoid any accidental borrowing of a byte in the previous frame
+                     * (which would return a negative index and indicate that fetch_timestamps
+                     * has to get the pts from the previous frame),
+                     * better have the start of packet strictly aligned.
+                     * To make it a more general rule, just test the following three bytes are null.
+                     */
+                    i += 1 + (!p->is_avc && state == 5 && i == 3 && nalu_type == H264_NAL_AUD &&
+                        buf_size >= 9 && !AV_RB24(buf + 5));
                     goto found;
                 }
             } else if (nalu_type == H264_NAL_SLICE || nalu_type == H264_NAL_DPA ||
-- 
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".

  parent reply	other threads:[~2024-03-04 17:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 17:32 [FFmpeg-devel] [PATCH v3 0/5] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets Nicolas Gaullier
2024-03-04 17:32 ` [FFmpeg-devel] [PATCH v3 1/5] avcodec/parser: merge packets from the same frame Nicolas Gaullier
2024-03-04 17:32 ` [FFmpeg-devel] [PATCH v3 2/5] avcodec/parser: reindent after previous commit Nicolas Gaullier
2024-03-04 17:32 ` [FFmpeg-devel] [PATCH v3 3/5] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets Nicolas Gaullier
2024-03-04 17:32 ` Nicolas Gaullier [this message]
2024-03-04 17:32 ` [FFmpeg-devel] [PATCH v3 5/5] lavf/demux: duplicate side_data in parse_packet() Nicolas Gaullier
2024-03-14 11:28 ` [FFmpeg-devel] [PATCH v3 0/5] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets Nicolas Gaullier

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=20240304173219.1877658-5-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