[FFmpeg-devel] [PATCH] accelerate h2645 nalu start code finding
Lingjiang Fang
vacingfang at foxmail.com
Thu Dec 9 04:54:34 EET 2021
---
libavcodec/h2645_parse.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
refer from webrtc h264 parser
diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 6fbe97ad4a..e372d2a27b 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -330,16 +330,25 @@ static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
static int find_next_start_code(const uint8_t *buf, const uint8_t *next_avc)
{
int i = 0;
+ const uint8_t *end = NULL;
if (buf + 3 >= next_avc)
return next_avc - buf;
- while (buf + i + 3 < next_avc) {
- if (buf[i] == 0 && buf[i + 1] == 0 && buf[i + 2] == 1)
- break;
- i++;
+ end = next_avc - 3;
+ while (buf + i < end) {
+ if (buf[i + 2] > 1) {
+ i += 3;
+ } else if (buf[i + 2] == 1) {
+ if (buf[i + 1] == 0 && buf[i] == 0) {
+ break;
+ }
+ i += 3;
+ } else {
+ ++i;
+ }
}
- return i + 3;
+ return (buf + i + 3 > next_avc)? next_avc - buf : i + 3;
}
static void alloc_rbsp_buffer(H2645RBSP *rbsp, unsigned int size, int use_ref)
--
2.29.2
More information about the ffmpeg-devel
mailing list