[FFmpeg-cvslog] Make mime-type award a bonus probe score

Peter Zebühr git at videolan.org
Wed Feb 26 16:18:48 EET 2025


ffmpeg | branch: master | Peter Zebühr <peterz at spotify.com> | Tue Nov 21 14:16:49 2023 +0100| [e24920375cd2bbdd579424c16cf0f9c66579ea24] | committer: Tomas Härdin

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).

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e24920375cd2bbdd579424c16cf0f9c66579ea24
---

 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;



More information about the ffmpeg-cvslog mailing list