* [FFmpeg-devel] [PATCH 2/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors
2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin
@ 2025-02-05 14:19 ` Tomas Härdin
2025-02-05 16:28 ` Marth64
2025-02-05 14:20 ` [FFmpeg-devel] [PATCH 3/8] libavformat/flacdec: Export samples md5 as metadata Tomas Härdin
` (5 subsequent siblings)
6 siblings, 1 reply; 9+ messages in thread
From: Tomas Härdin @ 2025-02-05 14:19 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0002-libavcodec-wmadec-Return-AVERROR_INVALIDDATA-on-deco.patch --]
[-- Type: text/x-patch, Size: 7417 bytes --]
From 18a64198487582e9ef3246e7490d919ee19af595 Mon Sep 17 00:00:00 2001
From: Jonathan Murray <jonathanmurray@spotify.com>
Date: Wed, 9 Jun 2021 12:00:24 +0200
Subject: [PATCH 2/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding
errors
WMA files that fail to decode due to incoherent block lengths and
frame lengths currently result in a "Operation not permitted".
After this change, they will instead result in "Invalid data found
when processing input".
Several other error cases are also changed from returning -1.
As we change the error propagation logic in wma_decode_frame and
wma_decode_superframe, previous occurrences of returning
AVERROR_INVALIDDATA are also affected by this. This includes
"total_gain overread" and a "channel exponents_initialized" check.
---
Tomas: changed some -1's to AVERROR_INVALIDDATA
---
libavcodec/wmadec.c | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 3427e482dc..c24fff5522 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -368,7 +368,7 @@ static int decode_exp_vlc(WMACodecContext *s, int ch)
if ((unsigned) last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {
av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
last_exp);
- return -1;
+ return AVERROR_INVALIDDATA;
}
v = ptab[last_exp];
iv = iptab[last_exp];
@@ -439,8 +439,10 @@ static void wma_window(WMACodecContext *s, float *out)
}
/**
- * @return 0 if OK. 1 if last block of frame. return -1 if
- * unrecoverable error.
+ * @return
+ * 0 if OK.
+ * 1 if last block of frame.
+ * AVERROR if unrecoverable error.
*/
static int wma_decode_block(WMACodecContext *s)
{
@@ -468,7 +470,7 @@ static int wma_decode_block(WMACodecContext *s)
av_log(s->avctx, AV_LOG_ERROR,
"prev_block_len_bits %d out of range\n",
s->frame_len_bits - v);
- return -1;
+ return AVERROR_INVALIDDATA;
}
s->prev_block_len_bits = s->frame_len_bits - v;
v = get_bits(&s->gb, n);
@@ -476,7 +478,7 @@ static int wma_decode_block(WMACodecContext *s)
av_log(s->avctx, AV_LOG_ERROR,
"block_len_bits %d out of range\n",
s->frame_len_bits - v);
- return -1;
+ return AVERROR_INVALIDDATA;
}
s->block_len_bits = s->frame_len_bits - v;
} else {
@@ -489,7 +491,7 @@ static int wma_decode_block(WMACodecContext *s)
av_log(s->avctx, AV_LOG_ERROR,
"next_block_len_bits %d out of range\n",
s->frame_len_bits - v);
- return -1;
+ return AVERROR_INVALIDDATA;
}
s->next_block_len_bits = s->frame_len_bits - v;
} else {
@@ -501,14 +503,14 @@ static int wma_decode_block(WMACodecContext *s)
if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){
av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
/* now check if the block length is coherent with the frame length */
s->block_len = 1 << s->block_len_bits;
if ((s->block_pos + s->block_len) > s->frame_len) {
av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
if (channels == 2)
@@ -590,7 +592,7 @@ static int wma_decode_block(WMACodecContext *s)
if (s->channel_coded[ch]) {
if (s->use_exp_vlc) {
if (decode_exp_vlc(s, ch) < 0)
- return -1;
+ return AVERROR_INVALIDDATA;
} else {
decode_exp_lsp(s, ch);
}
@@ -802,7 +804,7 @@ static int wma_decode_frame(WMACodecContext *s, float **samples,
for (;;) {
ret = wma_decode_block(s);
if (ret < 0)
- return -1;
+ return ret;
if (ret)
break;
}
@@ -879,8 +881,10 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
return AVERROR_INVALIDDATA;
if ((s->last_superframe_len + buf_size - 1) >
- MAX_CODED_SUPERFRAME_SIZE)
+ MAX_CODED_SUPERFRAME_SIZE) {
+ ret = AVERROR_INVALIDDATA;
goto fail;
+ }
q = s->last_superframe + s->last_superframe_len;
len = buf_size - 1;
@@ -911,14 +915,17 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
av_log(avctx, AV_LOG_ERROR,
"Invalid last frame bit offset %d > buf size %d (%d)\n",
bit_offset, get_bits_left(&s->gb), buf_size);
+ ret = AVERROR_INVALIDDATA;
goto fail;
}
if (s->last_superframe_len > 0) {
/* add bit_offset bits to last frame */
if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
- MAX_CODED_SUPERFRAME_SIZE)
+ MAX_CODED_SUPERFRAME_SIZE) {
+ ret = AVERROR_INVALIDDATA;
goto fail;
+ }
q = s->last_superframe + s->last_superframe_len;
len = bit_offset;
while (len > 7) {
@@ -937,7 +944,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
skip_bits(&s->gb, s->last_bitoffset);
/* this frame is stored in the last superframe and in the
* current one */
- if (wma_decode_frame(s, samples, samples_offset) < 0)
+ if ((ret = wma_decode_frame(s, samples, samples_offset)) < 0)
goto fail;
samples_offset += s->frame_len;
nb_frames--;
@@ -954,7 +961,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
s->reset_block_lengths = 1;
for (i = 0; i < nb_frames; i++) {
- if (wma_decode_frame(s, samples, samples_offset) < 0)
+ if ((ret = wma_decode_frame(s, samples, samples_offset)) < 0)
goto fail;
samples_offset += s->frame_len;
}
@@ -967,13 +974,14 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
len = buf_size - pos;
if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len);
+ ret = AVERROR_INVALIDDATA;
goto fail;
}
s->last_superframe_len = len;
memcpy(s->last_superframe, buf + pos, len);
} else {
/* single frame decode */
- if (wma_decode_frame(s, samples, samples_offset) < 0)
+ if ((ret = wma_decode_frame(s, samples, samples_offset)) < 0)
goto fail;
samples_offset += s->frame_len;
}
@@ -989,7 +997,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
fail:
/* when error, we reset the bit reservoir */
s->last_superframe_len = 0;
- return -1;
+ return ret;
}
static av_cold void flush(AVCodecContext *avctx)
--
2.39.5
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 9+ messages in thread
* [FFmpeg-devel] [PATCH 3/8] libavformat/flacdec: Export samples md5 as metadata
2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin
2025-02-05 14:19 ` [FFmpeg-devel] [PATCH 2/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors Tomas Härdin
@ 2025-02-05 14:20 ` Tomas Härdin
2025-02-05 14:20 ` [FFmpeg-devel] [PATCH 4/8] avformat/flacdec: Return correct error-codes on read-failure Tomas Härdin
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Tomas Härdin @ 2025-02-05 14:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0003-libavformat-flacdec-Export-samples-md5-as-metadata.patch --]
[-- Type: text/x-patch, Size: 3776 bytes --]
From e1c4dfa4cc7a574f6fac76c11591547d3cd90ad2 Mon Sep 17 00:00:00 2001
From: Mattias Wadman <wader@spotify.com>
Date: Mon, 11 Oct 2021 15:38:13 +0200
Subject: [PATCH 3/8] libavformat/flacdec: Export samples md5 as metadata
Will be used by mal to compare metadat md5 with decoded samples md5.
Part of fixing https://jira.spotify.net/browse/GOL-681
---
libavformat/flacdec.c | 6 ++++++
tests/ref/fate/cover-art-aiff-id3v2-remux | 5 +++--
tests/ref/fate/cover-art-flac-remux | 1 +
tests/ref/fate/id3v2-utf16-bom | 5 +++--
4 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 3c317acaee..9f65c25864 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -33,6 +33,7 @@
#include "replaygain.h"
#define SEEKPOINT_SIZE 18
+#define MD5_BYTE_SIZE 16
typedef struct FLACDecContext {
FFRawDemuxerContext rawctx;
@@ -109,6 +110,7 @@ static int flac_read_header(AVFormatContext *s)
if (metadata_type == FLAC_METADATA_TYPE_STREAMINFO) {
uint32_t samplerate;
uint64_t samples;
+ char md5hex[MD5_BYTE_SIZE*2+1]; // hex representation plus null terminator
/* STREAMINFO can only occur once */
if (found_streaminfo) {
@@ -133,6 +135,10 @@ static int flac_read_header(AVFormatContext *s)
if (samples > 0)
st->duration = samples;
}
+
+ ff_data_to_hex(md5hex, st->codecpar->extradata+18, MD5_BYTE_SIZE, 1 /* lowercase */);
+ md5hex[sizeof(md5hex)-1] = '\0';
+ av_dict_set(&s->metadata, "samples_md5", md5hex, 0);
} else if (metadata_type == FLAC_METADATA_TYPE_CUESHEET) {
uint8_t isrc[13];
uint64_t start;
diff --git a/tests/ref/fate/cover-art-aiff-id3v2-remux b/tests/ref/fate/cover-art-aiff-id3v2-remux
index a59ba37c65..57c5a9f387 100644
--- a/tests/ref/fate/cover-art-aiff-id3v2-remux
+++ b/tests/ref/fate/cover-art-aiff-id3v2-remux
@@ -1,5 +1,5 @@
-330ad2bf538e91a31752b38024461df1 *tests/data/fate/cover-art-aiff-id3v2-remux.aiff
-608914 tests/data/fate/cover-art-aiff-id3v2-remux.aiff
+d8caddad3af3879f5957f71adcaedd23 *tests/data/fate/cover-art-aiff-id3v2-remux.aiff
+608970 tests/data/fate/cover-art-aiff-id3v2-remux.aiff
#tb 0: 1/44100
#media_type 0: audio
#codec_id 0: pcm_s16be
@@ -68,6 +68,7 @@ TAG:comment=Composer
[/STREAM]
[FORMAT]
TAG:artist=Мельница
+TAG:samples_md5=03462731b2dba8e6a9da639b07054121
TAG:RATING=0
TAG:album=Ангелофрения
TAG:title=Дороги
diff --git a/tests/ref/fate/cover-art-flac-remux b/tests/ref/fate/cover-art-flac-remux
index fa91975881..109bf7395e 100644
--- a/tests/ref/fate/cover-art-flac-remux
+++ b/tests/ref/fate/cover-art-flac-remux
@@ -90,6 +90,7 @@ TAG:comment=Publisher/Studio logotype
TAG:title=White King Granulated Soap
[/STREAM]
[FORMAT]
+TAG:samples_md5=496206705f222f9a63bf23dc874d9d71
TAG:major_brand=M4A
TAG:minor_version=0
TAG:compatible_brands=M4A mp42isom
diff --git a/tests/ref/fate/id3v2-utf16-bom b/tests/ref/fate/id3v2-utf16-bom
index dd2566de2b..a1adb4730d 100644
--- a/tests/ref/fate/id3v2-utf16-bom
+++ b/tests/ref/fate/id3v2-utf16-bom
@@ -1,5 +1,5 @@
-9b8bfdf87a8d3d089819ef9f6f264ec4 *tests/data/fate/id3v2-utf16-bom.aiff
-885482 tests/data/fate/id3v2-utf16-bom.aiff
+b712d97d4ab0cfd77d79235c312c438a *tests/data/fate/id3v2-utf16-bom.aiff
+885538 tests/data/fate/id3v2-utf16-bom.aiff
#tb 0: 1/90000
#media_type 0: video
#codec_id 0: mjpeg
@@ -31,6 +31,7 @@ TAG:comment=Other
[/STREAM]
[FORMAT]
TAG:artist=Мельница
+TAG:samples_md5=03462731b2dba8e6a9da639b07054121
TAG:RATING=0
TAG:album=Ангелофрения
TAG:title=Дороги
--
2.39.5
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 9+ messages in thread
* [FFmpeg-devel] [PATCH 4/8] avformat/flacdec: Return correct error-codes on read-failure
2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin
2025-02-05 14:19 ` [FFmpeg-devel] [PATCH 2/8] libavcodec/wmadec: Return AVERROR_INVALIDDATA on decoding errors Tomas Härdin
2025-02-05 14:20 ` [FFmpeg-devel] [PATCH 3/8] libavformat/flacdec: Export samples md5 as metadata Tomas Härdin
@ 2025-02-05 14:20 ` Tomas Härdin
2025-02-05 14:21 ` [FFmpeg-devel] [PATCH 5/8] rtmp: Set correct message stream id when writing as server Tomas Härdin
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Tomas Härdin @ 2025-02-05 14:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0004-avformat-flacdec-Return-correct-error-codes-on-read-.patch --]
[-- Type: text/x-patch, Size: 2241 bytes --]
From c81e350d5419cf02f029ce006d94f257bc18fb97 Mon Sep 17 00:00:00 2001
From: Ulrik <ulrikm@spotify.com>
Date: Thu, 26 Jan 2023 17:51:02 +0100
Subject: [PATCH 4/8] avformat/flacdec: Return correct error-codes on
read-failure
Forward errors from `avio_read` directly. When `avio_read` sees EOF before
expected bytes can be read, consistently return `AVERROR_INVALIDDATA`
We used to return `AVERROR(AVERROR_INVALIDDATA)` when failing to read
metadata block headers. `AVERROR_INVALIDDATA` is already negative, so
wrapping in `AVERROR` leads to double-negation.
We used to return `AVERROR(EIO)` when failing to read extended metadata.
However, many times, the IO-layer is not at fault, the input data is simply
corrupted (truncated), so we return `AVERROR_INVALIDDATA` here as well.
---
Tomas: changed to use AVERROR_EOF
---
libavformat/flacdec.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 9f65c25864..77dcc620a4 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -81,8 +81,13 @@ static int flac_read_header(AVFormatContext *s)
/* process metadata blocks */
while (!avio_feof(s->pb) && !metadata_last) {
- if (avio_read(s->pb, header, 4) != 4)
- return AVERROR_INVALIDDATA;
+ ret = avio_read(s->pb, header, 4);
+ if (ret < 0) {
+ return ret;
+ } else if (ret != 4) {
+ return AVERROR_EOF;
+ }
+
flac_parse_block_header(header, &metadata_last, &metadata_type,
&metadata_size);
switch (metadata_type) {
@@ -96,8 +101,11 @@ static int flac_read_header(AVFormatContext *s)
if (!buffer) {
return AVERROR(ENOMEM);
}
- if (avio_read(s->pb, buffer, metadata_size) != metadata_size) {
- RETURN_ERROR(AVERROR(EIO));
+ ret = avio_read(s->pb, buffer, metadata_size);
+ if (ret < 0) {
+ RETURN_ERROR(ret);
+ } else if (ret != metadata_size) {
+ RETURN_ERROR(AVERROR_EOF);
}
break;
/* skip metadata block for unsupported types */
--
2.39.5
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 9+ messages in thread
* [FFmpeg-devel] [PATCH 5/8] rtmp: Set correct message stream id when writing as server
2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin
` (2 preceding siblings ...)
2025-02-05 14:20 ` [FFmpeg-devel] [PATCH 4/8] avformat/flacdec: Return correct error-codes on read-failure Tomas Härdin
@ 2025-02-05 14:21 ` Tomas Härdin
2025-02-05 14:22 ` [FFmpeg-devel] [PATCH 6/8] GOL-1361: Remove invalid CTTS sample_offset check Tomas Härdin
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Tomas Härdin @ 2025-02-05 14:21 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 50 bytes --]
This one is difficult to test. Any ideas?
/Tomas
[-- Attachment #2: 0005-rtmp-Set-correct-message-stream-id-when-writing-as-s.patch --]
[-- Type: text/x-patch, Size: 1761 bytes --]
From c8689abcbf9bf85e1f7775a347b6bc994679cb77 Mon Sep 17 00:00:00 2001
From: Jonathan Murray <jonathanmurray@spotify.com>
Date: Thu, 31 Mar 2022 16:23:17 +0200
Subject: [PATCH 5/8] rtmp: Set correct message stream id when writing as
server
rtmp_write is used both for writing outputs as a server. The
rt->listen flag determines which mode we're running in.
Previously, when running as a server, the message stream id would
always be set to 0 for media/metadata messages. This is surprising
given that we have both responded to "createStream()" with a value
of 1 and sent a "Stream Begin 1" to the client. Furthermore, some
client libraries (Red5) seem to trip up on receiving
"@setDataFrame" on stream 0 (and may be correct to assume that
this message would be sent on stream 1).
---
libavformat/rtmpproto.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 4095ae9421..846376e668 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -3049,7 +3049,12 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
pkttype, ts, pktsize)) < 0)
return ret;
- rt->out_pkt.extra = rt->stream_id;
+ // If rt->listen, then we're running as a a server and should
+ // use the ID that we've sent in Stream Begin and in the
+ // _result to createStream.
+ // Otherwise, we're running as a client and should use the ID
+ // that we've received in the createStream from the server.
+ rt->out_pkt.extra = (rt->listen) ? rt->nb_streamid : rt->stream_id;
rt->flv_data = rt->out_pkt.data;
}
--
2.39.5
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 9+ messages in thread
* [FFmpeg-devel] [PATCH 6/8] GOL-1361: Remove invalid CTTS sample_offset check
2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin
` (3 preceding siblings ...)
2025-02-05 14:21 ` [FFmpeg-devel] [PATCH 5/8] rtmp: Set correct message stream id when writing as server Tomas Härdin
@ 2025-02-05 14:22 ` Tomas Härdin
2025-02-05 14:23 ` [FFmpeg-devel] [PATCH 7/8] avformat/mp3dec: Subtract known padding from duration Tomas Härdin
2025-02-05 14:24 ` [FFmpeg-devel] [PATCH 8/8] Make mime-type award a bonus probe score Tomas Härdin
6 siblings, 0 replies; 9+ messages in thread
From: Tomas Härdin @ 2025-02-05 14:22 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 60 bytes --]
I trust that ticket #385 has a FATE test these days
/Tomas
[-- Attachment #2: 0006-GOL-1361-Remove-invalid-CTTS-sample_offset-check.patch --]
[-- Type: text/x-patch, Size: 1176 bytes --]
From 8c105c5953c494402749eb27d2eb6a7a2393f855 Mon Sep 17 00:00:00 2001
From: ekir <ekir@spotify.com>
Date: Tue, 18 Apr 2023 17:31:43 +0200
Subject: [PATCH 6/8] GOL-1361: Remove invalid CTTS sample_offset check
We checked in this places:
* In 8.6.1.3 of ISO/IEC 14496-12 about the CTTS box
* In Apples MOV spec: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-SW19
---
libavformat/mov.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2c8be51063..89bfb52d2e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3697,13 +3697,6 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n",
count, duration);
- if (FFNABS(duration) < -(1<<28) && i+2<entries) {
- av_log(c->fc, AV_LOG_WARNING, "CTTS invalid\n");
- av_freep(&sc->ctts_data);
- sc->ctts_count = 0;
- return 0;
- }
-
if (i+2<entries)
mov_update_dts_shift(sc, duration, c->fc);
}
--
2.39.5
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 9+ messages in thread
* [FFmpeg-devel] [PATCH 7/8] avformat/mp3dec: Subtract known padding from duration
2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin
` (4 preceding siblings ...)
2025-02-05 14:22 ` [FFmpeg-devel] [PATCH 6/8] GOL-1361: Remove invalid CTTS sample_offset check Tomas Härdin
@ 2025-02-05 14:23 ` Tomas Härdin
2025-02-05 14:24 ` [FFmpeg-devel] [PATCH 8/8] Make mime-type award a bonus probe score Tomas Härdin
6 siblings, 0 replies; 9+ messages in thread
From: Tomas Härdin @ 2025-02-05 14:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0007-avformat-mp3dec-Subtract-known-padding-from-duration.patch --]
[-- Type: text/x-patch, Size: 8973 bytes --]
From 6dca5b958693588d74081e8fa29f05a5f257c841 Mon Sep 17 00:00:00 2001
From: Ulrik Mikaelsson <ulrik.mikaelsson@gmail.com>
Date: Tue, 22 Aug 2023 13:55:14 +0200
Subject: [PATCH 7/8] avformat/mp3dec: Subtract known padding from duration
When an Info-tag is present, marking initial and trailing samples as
padding, those samples should not be included in the calculation of track
duration.
This solves a surprising user experience where converting a WAV->MP3->WAV,
ffprobe will show the duration of the mp3 as slightly longer than both the
input and the output.
As a result, the estimated duration and imprecise seek-results of some
FATE-tests have been updated.
---
libavformat/mp3dec.c | 20 ++++++++++++++------
tests/ref/fate/gapless-mp3-side-data | 4 ++--
| 8 ++++----
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index dac91205d9..31eeb68ebb 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -52,6 +52,7 @@ typedef struct {
int usetoc;
unsigned frames; /* Total number of frames in file */
unsigned header_filesize; /* Total number of bytes in the stream */
+ unsigned frame_duration; /* Frame duration in st->time_base */
int is_cbr;
} MP3DecContext;
@@ -341,6 +342,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
mp3->frames = 0;
mp3->header_filesize = 0;
+ mp3->frame_duration = av_rescale_q(spf, (AVRational){1, c.sample_rate}, st->time_base);
mp3_parse_info_tag(s, st, &c, spf);
mp3_parse_vbri_tag(s, st, base);
@@ -351,11 +353,18 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
/* Skip the vbr tag frame */
avio_seek(s->pb, base + vbrtag_size, SEEK_SET);
- if (mp3->frames)
- st->duration = av_rescale_q(mp3->frames, (AVRational){spf, c.sample_rate},
+ if (mp3->frames) {
+ int64_t full_duration_samples;
+
+ full_duration_samples = mp3->frames * (int64_t)spf;
+ st->duration = av_rescale_q(full_duration_samples - mp3->start_pad - mp3->end_pad,
+ (AVRational){1, c.sample_rate},
st->time_base);
- if (mp3->header_filesize && mp3->frames && !mp3->is_cbr)
- st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate, mp3->frames * (int64_t)spf);
+
+ if (mp3->header_filesize && !mp3->is_cbr)
+ st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate,
+ full_duration_samples);
+ }
return 0;
}
@@ -586,8 +595,7 @@ static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
return best_pos;
if (mp3->is_cbr && ie == &ie1 && mp3->frames && mp3->header_filesize > 0) {
- int frame_duration = av_rescale(st->duration, 1, mp3->frames);
- ie1.timestamp = frame_duration * av_rescale(best_pos - si->data_offset, mp3->frames, mp3->header_filesize);
+ ie1.timestamp = mp3->frame_duration * av_rescale(best_pos - si->data_offset, mp3->frames, mp3->header_filesize);
}
avpriv_update_cur_dts(s, st, ie->timestamp);
diff --git a/tests/ref/fate/gapless-mp3-side-data b/tests/ref/fate/gapless-mp3-side-data
index 49ebc32dc8..878425f092 100644
--- a/tests/ref/fate/gapless-mp3-side-data
+++ b/tests/ref/fate/gapless-mp3-side-data
@@ -593,5 +593,5 @@ packet|codec_type=audio|stream_index=0|pts=217866240|pts_time=15.438367|dts=2178
packet|codec_type=audio|stream_index=0|pts=218234880|pts_time=15.464490|dts=218234880|dts_time=15.464490|duration=368640|duration_time=0.026122|size=418|pos=248882|flags=K__|data_hash=CRC32:fbc83c3c
packet|codec_type=audio|stream_index=0|pts=218603520|pts_time=15.490612|dts=218603520|dts_time=15.490612|duration=368640|duration_time=0.026122|size=418|pos=249300|flags=K__|data_hash=CRC32:d5fb5f9c|side_datum/skip_samples:side_data_type=Skip Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=303|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
packet|codec_type=audio|stream_index=0|pts=218972160|pts_time=15.516735|dts=218972160|dts_time=15.516735|duration=368640|duration_time=0.026122|size=418|pos=249718|flags=K__|data_hash=CRC32:3789f3cf|side_datum/skip_samples:side_data_type=Skip Samples|side_datum/skip_samples:skip_samples=0|side_datum/skip_samples:discard_padding=1152|side_datum/skip_samples:skip_reason=0|side_datum/skip_samples:discard_reason=0
-stream|index=0|codec_name=mp3|profile=unknown|codec_type=audio|codec_tag_string=[0][0][0][0]|codec_tag=0x0000|sample_fmt=fltp|sample_rate=44100|channels=2|channel_layout=stereo|bits_per_sample=0|initial_padding=0|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/14112000|start_pts=353600|start_time=0.025057|duration_ts=219340800|duration=15.542857|bit_rate=128000|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=595|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0|disposition:multilayer=0|tag:encoder=LAME3.93
-format|filename=gapless.mp3|nb_streams=1|nb_programs=0|nb_stream_groups=0|format_name=mp3|start_time=0.025057|duration=15.542857|size=250264|bit_rate=128812|probe_score=51|tag:title=test
+stream|index=0|codec_name=mp3|profile=unknown|codec_type=audio|codec_tag_string=[0][0][0][0]|codec_tag=0x0000|sample_fmt=fltp|sample_rate=44100|channels=2|channel_layout=stereo|bits_per_sample=0|initial_padding=0|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/14112000|start_pts=353600|start_time=0.025057|duration_ts=218521600|duration=15.484807|bit_rate=128000|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=595|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:non_diegetic=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0|disposition:multilayer=0|tag:encoder=LAME3.93
+format|filename=gapless.mp3|nb_streams=1|nb_programs=0|nb_stream_groups=0|format_name=mp3|start_time=0.025057|duration=15.484807|size=250264|bit_rate=129295|probe_score=51|tag:title=test
--git a/tests/ref/seek/extra-mp3 b/tests/ref/seek/extra-mp3
index fdfb1a7c66..ec5947a9d5 100644
--- a/tests/ref/seek/extra-mp3
+++ b/tests/ref/seek/extra-mp3
@@ -8,11 +8,11 @@ ret: 0 st: 0 flags:1 dts: 0.809796 pts: 0.809796 pos: 14407 size: 418
ret: 0 st: 0 flags:1 ts:-0.317499
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 1451 size: 417
ret: 0 st:-1 flags:0 ts: 2.576668
-ret: 0 st: 0 flags:1 dts: 2.586122 pts: 2.586122 pos: 42828 size: 418
+ret: 0 st: 0 flags:1 dts: 2.612245 pts: 2.612245 pos: 43246 size: 418
ret: 0 st:-1 flags:1 ts: 1.470835
ret: 0 st: 0 flags:1 dts: 1.462857 pts: 1.462857 pos: 24856 size: 418
ret: 0 st: 0 flags:0 ts: 0.365002
-ret: 0 st: 0 flags:1 dts: 0.365714 pts: 0.365714 pos: 7302 size: 418
+ret: 0 st: 0 flags:1 dts: 0.391837 pts: 0.391837 pos: 7720 size: 418
ret: 0 st: 0 flags:1 ts:-0.740831
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 1451 size: 417
ret: 0 st:-1 flags:0 ts: 2.153336
@@ -22,11 +22,11 @@ ret: 0 st: 0 flags:1 dts: 1.044898 pts: 1.044898 pos: 18169 size: 418
ret: 0 st: 0 flags:0 ts:-0.058330
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 1451 size: 417
ret: 0 st: 0 flags:1 ts: 2.835837
-ret: 0 st: 0 flags:1 dts: 2.821224 pts: 2.821224 pos: 46590 size: 418
+ret: 0 st: 0 flags:1 dts: 2.847347 pts: 2.847347 pos: 47008 size: 418
ret: 0 st:-1 flags:0 ts: 1.730004
ret: 0 st: 0 flags:1 dts: 1.750204 pts: 1.750204 pos: 29454 size: 418
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 0 flags:1 dts: 0.600816 pts: 0.600816 pos: 11064 size: 418
+ret: 0 st: 0 flags:1 dts: 0.626939 pts: 0.626939 pos: 11482 size: 418
ret: 0 st: 0 flags:0 ts:-0.481662
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 1451 size: 417
ret: 0 st: 0 flags:1 ts: 2.412505
--
2.39.5
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 9+ messages in thread
* [FFmpeg-devel] [PATCH 8/8] Make mime-type award a bonus probe score
2025-02-05 14:18 [FFmpeg-devel] [PATCH 1/8] avformat/http: Return EIO for prematurely broken connection Tomas Härdin
` (5 preceding siblings ...)
2025-02-05 14:23 ` [FFmpeg-devel] [PATCH 7/8] avformat/mp3dec: Subtract known padding from duration Tomas Härdin
@ 2025-02-05 14:24 ` Tomas Härdin
6 siblings, 0 replies; 9+ messages in thread
From: Tomas Härdin @ 2025-02-05 14:24 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 47 bytes --]
Seems reasonable to me and passes FATE
/Tomas
[-- Attachment #2: 0008-Make-mime-type-award-a-bonus-probe-score.patch --]
[-- Type: text/x-patch, Size: 3407 bytes --]
From ecc3459990f2871fd907f96fe66362b8fea41bd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20Zeb=C3=BChr?= <peterz@spotify.com>
Date: Tue, 21 Nov 2023 14:16:49 +0100
Subject: [PATCH 8/8] Make mime-type award a bonus probe score
This changes the default behaviour of ffmpeg where content-type headers
on an input gives an absolut probe score (of 75) to instead give a bonus
score (of 30). This gives the probe a better chance to arrive at the
correct format by (hopefully) giving a large enough bonus to push edge
cases in the right direction (MPEG-PS vs MP3, I am looking at you) while
also not adversly punishing clearer cases (raw ADTS marked as
"audio/mpeg" for example).
This patch was regression tested against 20 million recent podcast
submissions (after content-type propagation was added to
original-storage), and 50k Juno vodcasts submissions (dito). No adverse
effects observed (but the bonus may still need tweaking if other edge
cases are detected in production).
---
libavformat/avformat.h | 2 +-
libavformat/format.c | 8 ++++----
libavformat/libopenmpt.c | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6abdb6d480..498c557a3c 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -459,7 +459,7 @@ typedef struct AVProbeData {
#define AVPROBE_SCORE_STREAM_RETRY (AVPROBE_SCORE_MAX/4-1)
#define AVPROBE_SCORE_EXTENSION 50 ///< score for file extension
-#define AVPROBE_SCORE_MIME 75 ///< score for file mime type
+#define AVPROBE_SCORE_MIME_BONUS 30 ///< score added for matching mime type
#define AVPROBE_SCORE_MAX 100 ///< maximum score
#define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
diff --git a/libavformat/format.c b/libavformat/format.c
index e65a6fc05e..71018ea6ab 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -212,10 +212,10 @@ const AVInputFormat *av_probe_input_format3(const AVProbeData *pd,
score = AVPROBE_SCORE_EXTENSION;
}
if (av_match_name(lpd.mime_type, fmt1->mime_type)) {
- if (AVPROBE_SCORE_MIME > score) {
- av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to %d due to MIME type\n", fmt1->name, score, AVPROBE_SCORE_MIME);
- score = AVPROBE_SCORE_MIME;
- }
+ int old_score = score;
+ score += AVPROBE_SCORE_MIME_BONUS;
+ if (score > AVPROBE_SCORE_MAX) score = AVPROBE_SCORE_MAX;
+ av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to %d due to MIME type\n", fmt1->name, old_score, score);
}
if (score > score_max) {
score_max = score;
diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
index 736af7caf2..dee975c9c2 100644
--- a/libavformat/libopenmpt.c
+++ b/libavformat/libopenmpt.c
@@ -244,7 +244,7 @@ static int read_probe_openmpt(const AVProbeData *p)
* AVPROBE_SCORE_MAX in order to reduce the impact in the rare
* cases of false positives.
*/
- return AVPROBE_SCORE_MIME + 1;
+ return (AVPROBE_SCORE_MAX * 3) / 4 + 1;
} else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) {
if (probe_openmpt_extension(p) > 0) {
return AVPROBE_SCORE_RETRY;
--
2.39.5
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 9+ messages in thread