* [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
@ 2023-01-31 12:45 John Coiner
2023-02-05 23:33 ` Marton Balint
0 siblings, 1 reply; 11+ messages in thread
From: John Coiner @ 2023-01-31 12:45 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: John Coiner
This replaces and obsoletes the earlier version of this patch, which had a bug. Thanks to Marton Balint for spotting it.
This fixes https://trac.ffmpeg.org/ticket/10148, it ensures that each IDR frame is prefixed with SPS/PPS.
Tested manually, with inputs containing AUDs (x264's aud=1 mode) and also without (aud=0) to confirm it still inserts AUDs when necessary, and not otherwise.
---
libavformat/mpegtsenc.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 48d39e6a7d..64948f4d75 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1877,6 +1877,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
const uint8_t *p = buf, *buf_end = p + size;
+ uint8_t found_aud = 0;
uint32_t state = -1;
int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codecpar->extradata_size : 0;
int ret = ff_check_h264_startcode(s, st, pkt);
@@ -1886,17 +1887,25 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
if (extradd && AV_RB24(st->codecpar->extradata) > 1)
extradd = 0;
+ // Ensure that all pictures are prefixed with an AUD, and that
+ // IDR pictures are also prefixed with SPS and PPS. SPS and PPS
+ // are assumed to be available in 'extradata' if not found in-band.
do {
p = avpriv_find_start_code(p, buf_end, &state);
av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f);
- if ((state & 0x1f) == 7)
+ if ((state & 0x1f) == 7) // SPS NAL
extradd = 0;
- } while (p < buf_end && (state & 0x1f) != 9 &&
- (state & 0x1f) != 5 && (state & 0x1f) != 1);
-
- if ((state & 0x1f) != 5)
+ if ((state & 0x1f) == 9) // AUD
+ found_aud = 1;
+ } while (p < buf_end
+ && (state & 0x1f) != 5 // IDR picture
+ && (state & 0x1f) != 1 // non-IDR picture
+ && (extradd > 0 || !found_aud));
+ if ((state & 0x1f) != 5) {
+ // Did not find IDR picture; do not emit extradata.
extradd = 0;
- if ((state & 0x1f) != 9) { // AUD NAL
+ }
+ if (extradd > 0 || !found_aud) {
data = av_malloc(pkt->size + 6 + extradd);
if (!data)
return AVERROR(ENOMEM);
--
2.39.1.456.gfc5497dd1b-goog
_______________________________________________
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] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
2023-01-31 12:45 [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures John Coiner
@ 2023-02-05 23:33 ` Marton Balint
2023-02-11 16:38 ` John Coiner
0 siblings, 1 reply; 11+ messages in thread
From: Marton Balint @ 2023-02-05 23:33 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, 31 Jan 2023, John Coiner wrote:
> This replaces and obsoletes the earlier version of this patch, which had a bug. Thanks to Marton Balint for spotting it.
>
> This fixes https://trac.ffmpeg.org/ticket/10148, it ensures that each IDR frame is prefixed with SPS/PPS.
>
> Tested manually, with inputs containing AUDs (x264's aud=1 mode) and also without (aud=0) to confirm it still inserts AUDs when necessary, and not otherwise.
Your code duplicates AUD-s if they are already present and sps is also
added:
if original packet had
[AUD][IDR]
it will become
[AUD][SPS][PPS][AUD][IDR].
Regards,
Marton
>
> ---
> libavformat/mpegtsenc.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index 48d39e6a7d..64948f4d75 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -1877,6 +1877,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
>
> if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
> const uint8_t *p = buf, *buf_end = p + size;
> + uint8_t found_aud = 0;
> uint32_t state = -1;
> int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codecpar->extradata_size : 0;
> int ret = ff_check_h264_startcode(s, st, pkt);
> @@ -1886,17 +1887,25 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
> if (extradd && AV_RB24(st->codecpar->extradata) > 1)
> extradd = 0;
>
> + // Ensure that all pictures are prefixed with an AUD, and that
> + // IDR pictures are also prefixed with SPS and PPS. SPS and PPS
> + // are assumed to be available in 'extradata' if not found in-band.
> do {
> p = avpriv_find_start_code(p, buf_end, &state);
> av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f);
> - if ((state & 0x1f) == 7)
> + if ((state & 0x1f) == 7) // SPS NAL
> extradd = 0;
> - } while (p < buf_end && (state & 0x1f) != 9 &&
> - (state & 0x1f) != 5 && (state & 0x1f) != 1);
> -
> - if ((state & 0x1f) != 5)
> + if ((state & 0x1f) == 9) // AUD
> + found_aud = 1;
> + } while (p < buf_end
> + && (state & 0x1f) != 5 // IDR picture
> + && (state & 0x1f) != 1 // non-IDR picture
> + && (extradd > 0 || !found_aud));
> + if ((state & 0x1f) != 5) {
> + // Did not find IDR picture; do not emit extradata.
> extradd = 0;
> - if ((state & 0x1f) != 9) { // AUD NAL
> + }
> + if (extradd > 0 || !found_aud) {
> data = av_malloc(pkt->size + 6 + extradd);
> if (!data)
> return AVERROR(ENOMEM);
> --
> 2.39.1.456.gfc5497dd1b-goog
>
> _______________________________________________
> 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".
>
_______________________________________________
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] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
2023-02-05 23:33 ` Marton Balint
@ 2023-02-11 16:38 ` John Coiner
0 siblings, 0 replies; 11+ messages in thread
From: John Coiner @ 2023-02-11 16:38 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: cus
On Sun, Feb 5, 2023 at 6:33 PM Marton Balint <cus@passwd.hu> wrote:
> Your code duplicates AUD-s if they are already present and sps is also
> added:
>
> if original packet had
> [AUD][IDR]
> it will become
> [AUD][SPS][PPS][AUD][IDR].
>
> Regards,
> Marton
Hi Marton,
You're right, this is not compliant. The H.264 spec (section
7.4.1.2.3) is clear about this, it says:
- There should be at most one AUD per access unit
- Each access unit should include a picture. (We can't produce a fake
"access unit" to carry the SPS and PPS alone; that's not allowed.)
- When AUD is present, it should be the first NAL in the access unit.
(We can't just prepend SPS and PPS ahead of the AUD.)
Perhaps you knew all this; I am just learning. :-)
So if the original packet has [AUD][IDR], then we should produce
[AUD][SPS][PPS][IDR].
And if the original packet has [SEI][AUD][IDR], then we should produce
[AUD][SPS][PPS][SEI][IDR] -- chopping out the original AUD, and then
inserting the prefix with the new AUD. Tests show x264 producing the
[SEI][AUD][IDR] sequence, despite it being contrary to the spec's
recommendation that AUD should be first.
Does that seem like the correct handling? If so I'll post a v2 patch
for it. Thanks again.
John
_______________________________________________
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] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
2023-01-30 21:12 ` Marton Balint
@ 2023-02-02 17:43 ` John Coiner
0 siblings, 0 replies; 11+ messages in thread
From: John Coiner @ 2023-02-02 17:43 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, Jan 30, 2023 at 4:12 PM Marton Balint <cus@passwd.hu> wrote:
>
> For normal mpegts it also makes sense to include SPS/PPS before IDR-s, so
> I'd say it is better if it is fixed in mpegtsenc.
>
> But it is mandatory to insert AUD NAL-s for every frame, and your patch
> breaks that, because it only inserts it if SPS/PPS is also inserted,
> because you changed
>
> if ((state & 0x1f) != 9) { // AUD NAL
>
> to
>
> if (extradd > 0) {
>
> So you need to rework your patch to keep the AUD insertion (but you don't
> want to duplicate it of course).
>
> Regards,
> Marton
>
Marton, thank you for this explanation. I understand now. There's an
updated patch that preserves AUD insertion at
http://ffmpeg.org/pipermail/ffmpeg-devel/2023-January/306143.html
Posting to bump the visibility of that one, which perhaps should have
been tagged "v2", whoops. Should I repost with "v2" to start a new
thread?
Cheers,
John
_______________________________________________
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] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
2023-01-30 17:36 ` John Coiner
@ 2023-01-30 21:12 ` Marton Balint
2023-02-02 17:43 ` John Coiner
0 siblings, 1 reply; 11+ messages in thread
From: Marton Balint @ 2023-01-30 21:12 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, 30 Jan 2023, John Coiner wrote:
> Marton Balint wrote:
>> This does not look right, because AFAIK you always want to insert an AUD
>> unless it is already there. I guess that is why current code works as it
>> is, it assumes if an AUD is already present, then IDR-s are already
>> prefixed with SPS/PPS, and no magic is needed.
>
> I'm not sure if it should be valid to assume that an AUD implies that
> an SPS/PPS will follow,
Well, most likely not, but worked mostly in the past...
> but this is how the above command makes that
> assumption go wrong:
>
> * The HLS muxer requests global headers as input:
> https://github.com/FFmpeg/FFmpeg/blob/2d202985b79630cd5056c4e32f8f77f22bf1067c/libavformat/hlsenc.c#L3194
> * This sets the AV_CODEC_FLAG_GLOBAL_HEADER option for the codec:
> https://github.com/FFmpeg/FFmpeg/blob/2d202985b79630cd5056c4e32f8f77f22bf1067c/fftools/ffmpeg_mux_init.c#L599
> * The libx264.c codec responds to this option by producing
> extradata, and also by configuring x264 not to repeat SPS and PPS
> in-band: https://github.com/FFmpeg/FFmpeg/blob/2d202985b79630cd5056c4e32f8f77f22bf1067c/libavcodec/libx264.c#L1044
> * When x264 runs with its "aud" option, it emits AUDs.
> * The AUDs inhibit mpegtsenc.c from emitting the extradata,
> producing the buggy behavior.
>
> An alternative to changing the extradata "magic" in mpegtsenc would be
> for the HLS muxer to re-emit the extradata on its own. The HLS muxer
> has good context for this: it knows when new HLS media segments begin,
> and it knows that each one must begin with SPS and PPS if the encoder
> didn't already include them. It knows it's producing HLS. The
> mpegtsenc muxer doesn't know any of this.
>
> Would it be safer to fix in hlsenc.c and leave mpegtsenc alone? It's
> not clear to me that the mpegtsenc logic is verifiable or falsifiable
> to stronger than a "happens to work" standard; a fix in hlsenc.c could
> be.
For normal mpegts it also makes sense to include SPS/PPS before IDR-s, so
I'd say it is better if it is fixed in mpegtsenc.
But it is mandatory to insert AUD NAL-s for every frame, and your patch
breaks that, because it only inserts it if SPS/PPS is also inserted,
because you changed
if ((state & 0x1f) != 9) { // AUD NAL
to
if (extradd > 0) {
So you need to rework your patch to keep the AUD insertion (but you don't
want to duplicate it of course).
Regards,
Marton
_______________________________________________
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] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
2023-01-30 15:13 John Coiner
@ 2023-01-30 17:36 ` John Coiner
2023-01-30 21:12 ` Marton Balint
0 siblings, 1 reply; 11+ messages in thread
From: John Coiner @ 2023-01-30 17:36 UTC (permalink / raw)
To: ffmpeg-devel
Marton Balint wrote:
> This does not look right, because AFAIK you always want to insert an AUD
> unless it is already there. I guess that is why current code works as it
> is, it assumes if an AUD is already present, then IDR-s are already
> prefixed with SPS/PPS, and no magic is needed.
I'm not sure if it should be valid to assume that an AUD implies that
an SPS/PPS will follow, but this is how the above command makes that
assumption go wrong:
* The HLS muxer requests global headers as input:
https://github.com/FFmpeg/FFmpeg/blob/2d202985b79630cd5056c4e32f8f77f22bf1067c/libavformat/hlsenc.c#L3194
* This sets the AV_CODEC_FLAG_GLOBAL_HEADER option for the codec:
https://github.com/FFmpeg/FFmpeg/blob/2d202985b79630cd5056c4e32f8f77f22bf1067c/fftools/ffmpeg_mux_init.c#L599
* The libx264.c codec responds to this option by producing
extradata, and also by configuring x264 not to repeat SPS and PPS
in-band: https://github.com/FFmpeg/FFmpeg/blob/2d202985b79630cd5056c4e32f8f77f22bf1067c/libavcodec/libx264.c#L1044
* When x264 runs with its "aud" option, it emits AUDs.
* The AUDs inhibit mpegtsenc.c from emitting the extradata,
producing the buggy behavior.
An alternative to changing the extradata "magic" in mpegtsenc would be
for the HLS muxer to re-emit the extradata on its own. The HLS muxer
has good context for this: it knows when new HLS media segments begin,
and it knows that each one must begin with SPS and PPS if the encoder
didn't already include them. It knows it's producing HLS. The
mpegtsenc muxer doesn't know any of this.
Would it be safer to fix in hlsenc.c and leave mpegtsenc alone? It's
not clear to me that the mpegtsenc logic is verifiable or falsifiable
to stronger than a "happens to work" standard; a fix in hlsenc.c could
be.
Cheers
John
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
@ 2023-01-30 15:13 John Coiner
2023-01-30 17:36 ` John Coiner
0 siblings, 1 reply; 11+ messages in thread
From: John Coiner @ 2023-01-30 15:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: cus
Hi Marton,
Thanks for pointing out
https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_EE0E40DE9A569FE5AB454E6E700A2DA79A08@qq.com/
Adding prints to h264_mp4toannexb_bsf.c shows that it's not reached in
the sequence that reproduces bug 10148 so it seems to be unrelated.
I found a simpler process to reproduce bug 10148 with probably any input file:
ffmpeg -i <any_input_media> -vf scale=320:-1 -c:v libx264 -x264-params
aud=1 -c:a aac -f hls -method PUT
'https://upload.youtube.com/http_upload_hls?cid=<your-stream-key>©=0&nightly=1&file=out.m3u8'
... where 'youtube.com' can be any HTTP server that accepts PUT,
there's nothing specific to youtube here.
Without the fix, that produces an unjoinable and noncompliant upload
where all HLS media segments after the first are not independently
decodable. With the fix, all are independently decodable.
thanks!
John
_______________________________________________
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] 11+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
2023-01-27 21:18 John Coiner
@ 2023-01-29 12:30 ` Marton Balint
0 siblings, 0 replies; 11+ messages in thread
From: Marton Balint @ 2023-01-29 12:30 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, 27 Jan 2023, John Coiner wrote:
> From: John Coiner <jcoiner@google.com>
>
> This is the proposed fix for https://trac.ffmpeg.org/ticket/10148
>
> Very sorry to send the same patch 3 times; this time with `git send-email' so it should be legal :)
>
> ---
> 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/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -1886,17 +1886,21 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
> if (extradd && AV_RB24(st->codecpar->extradata) > 1)
> extradd = 0;
>
> - do {
> + while (p < buf_end
> + && extradd > 0
> + && (state & 0x1f) != 5 // IDR picture
> + && (state & 0x1f) != 1 // non-IDR picture
> + ) {
> p = avpriv_find_start_code(p, buf_end, &state);
> av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f);
> - if ((state & 0x1f) == 7)
> + if ((state & 0x1f) == 7) // SPS NAL
> extradd = 0;
> - } while (p < buf_end && (state & 0x1f) != 9 &&
> - (state & 0x1f) != 5 && (state & 0x1f) != 1);
> -
> - if ((state & 0x1f) != 5)
> + }
> + if ((state & 0x1f) != 5) {
> + // Not an IDR picture
> extradd = 0;
> - if ((state & 0x1f) != 9) { // AUD NAL
> + }
> + if (extradd > 0) {
This does not look right, because AFAIK you always want to insert an AUD
unless it is already there. I guess that is why current code works as it
is, it assumes if an AUD is already present, then IDR-s are already
prefixed with SPS/PPS, and no magic is needed.
I wonder if the issue is indeed caused by this:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_EE0E40DE9A569FE5AB454E6E700A2DA79A08@qq.com/
Because if it is, then maybe nothing need to be fixed in the mpegts muxer.
Regards,
Marton
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
@ 2023-01-27 21:18 John Coiner
2023-01-29 12:30 ` Marton Balint
0 siblings, 1 reply; 11+ messages in thread
From: John Coiner @ 2023-01-27 21:18 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: John Coiner
From: John Coiner <jcoiner@google.com>
This is the proposed fix for https://trac.ffmpeg.org/ticket/10148
Very sorry to send the same patch 3 times; this time with `git send-email' so it should be legal :)
---
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/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1886,17 +1886,21 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
if (extradd && AV_RB24(st->codecpar->extradata) > 1)
extradd = 0;
- do {
+ while (p < buf_end
+ && extradd > 0
+ && (state & 0x1f) != 5 // IDR picture
+ && (state & 0x1f) != 1 // non-IDR picture
+ ) {
p = avpriv_find_start_code(p, buf_end, &state);
av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f);
- if ((state & 0x1f) == 7)
+ if ((state & 0x1f) == 7) // SPS NAL
extradd = 0;
- } while (p < buf_end && (state & 0x1f) != 9 &&
- (state & 0x1f) != 5 && (state & 0x1f) != 1);
-
- if ((state & 0x1f) != 5)
+ }
+ if ((state & 0x1f) != 5) {
+ // Not an IDR picture
extradd = 0;
- if ((state & 0x1f) != 9) { // AUD NAL
+ }
+ if (extradd > 0) {
data = av_malloc(pkt->size + 6 + extradd);
if (!data)
return AVERROR(ENOMEM);
--
2.39.1.456.gfc5497dd1b-goog
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
@ 2023-01-26 19:16 John Coiner
0 siblings, 0 replies; 11+ messages in thread
From: John Coiner @ 2023-01-26 19:16 UTC (permalink / raw)
To: ffmpeg-devel
Trying again to upload the same patch, this time inline:
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/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1886,17 +1886,21 @@ static int
mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
if (extradd && AV_RB24(st->codecpar->extradata) > 1)
extradd = 0;
- do {
+ while (p < buf_end
+ && extradd > 0
+ && (state & 0x1f) != 5 // IDR picture
+ && (state & 0x1f) != 1 // non-IDR picture
+ ) {
p = avpriv_find_start_code(p, buf_end, &state);
av_log(s, AV_LOG_TRACE, "nal %"PRId32"\n", state & 0x1f);
- if ((state & 0x1f) == 7)
+ if ((state & 0x1f) == 7) // SPS NAL
extradd = 0;
- } while (p < buf_end && (state & 0x1f) != 9 &&
- (state & 0x1f) != 5 && (state & 0x1f) != 1);
-
- if ((state & 0x1f) != 5)
+ }
+ if ((state & 0x1f) != 5) {
+ // Not an IDR picture
extradd = 0;
- if ((state & 0x1f) != 9) { // AUD NAL
+ }
+ if (extradd > 0) {
data = av_malloc(pkt->size + 6 + extradd);
if (!data)
return AVERROR(ENOMEM);
--
2.39.1.456.gfc5497dd1b-goog
_______________________________________________
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] 11+ messages in thread
* [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures
@ 2023-01-26 18:43 John Coiner
0 siblings, 0 replies; 11+ messages in thread
From: John Coiner @ 2023-01-26 18:43 UTC (permalink / raw)
To: ffmpeg-devel
A proposed fix for https://trac.ffmpeg.org/attachment/ticket/10148 is
attached to the bug, here:
https://trac.ffmpeg.org/attachment/ticket/10148/0001-Proposed-fix-for-https-trac.ffmpeg.org-ticket-10148.patch
_______________________________________________
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] 11+ messages in thread
end of thread, other threads:[~2023-02-11 16:39 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 12:45 [FFmpeg-devel] [PATCH] libavformat/mpegtsenc.c -- correctly re-emit extradata ahead of IDR pictures John Coiner
2023-02-05 23:33 ` Marton Balint
2023-02-11 16:38 ` John Coiner
-- strict thread matches above, loose matches on Subject: below --
2023-01-30 15:13 John Coiner
2023-01-30 17:36 ` John Coiner
2023-01-30 21:12 ` Marton Balint
2023-02-02 17:43 ` John Coiner
2023-01-27 21:18 John Coiner
2023-01-29 12:30 ` Marton Balint
2023-01-26 19:16 John Coiner
2023-01-26 18:43 John Coiner
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