From 09c4bbd3d4ef6fbcb1558fce5cff4d15d7839526 Mon Sep 17 00:00:00 2001
From: John Coiner <jcoiner@google.com>
Date: Thu, 26 Jan 2023 13:34:24 -0500
Subject: [PATCH] Proposed fix for https://trac.ffmpeg.org/ticket/10148
---
libavformat/mpegtsenc.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 48d39e6a7d..6cb398f99c 100644
|
a
|
b
|
static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
|
| 1886 | 1886 | if (extradd && AV_RB24(st->codecpar->extradata) > 1) |
| 1887 | 1887 | extradd = 0; |
| 1888 | 1888 | |
| 1889 | | do { |
| | 1889 | while (p < buf_end |
| | 1890 | && extradd > 0 |
| | 1891 | && (state & 0x1f) != 5 // IDR picture |
| | 1892 | && (state & 0x1f) != 1 // non-IDR picture |
| | 1893 | ) { |
| 1890 | 1894 | p = avpriv_find_start_code(p, buf_end, &state); |
| 1891 | 1895 | av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f); |
| 1892 | | if ((state & 0x1f) == 7) |
| | 1896 | if ((state & 0x1f) == 7) // SPS NAL |
| 1893 | 1897 | extradd = 0; |
| 1894 | | } while (p < buf_end && (state & 0x1f) != 9 && |
| 1895 | | (state & 0x1f) != 5 && (state & 0x1f) != 1); |
| 1896 | | |
| 1897 | | if ((state & 0x1f) != 5) |
| | 1898 | } |
| | 1899 | if ((state & 0x1f) != 5) { |
| | 1900 | // Not an IDR picture |
| 1898 | 1901 | extradd = 0; |
| 1899 | | if ((state & 0x1f) != 9) { // AUD NAL |
| | 1902 | } |
| | 1903 | if (extradd > 0) { |
| 1900 | 1904 | data = av_malloc(pkt->size + 6 + extradd); |
| 1901 | 1905 | if (!data) |
| 1902 | 1906 | return AVERROR(ENOMEM); |