History

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

Peter Zebühr committed 2 years ago

Commit e2492031 parent 5a526fd3 files · +6 −6Browse files

Unified · Split

3 files
  1. libavformat/avformat.h +1 −1
  2. libavformat/format.c +4 −4
  3. libavformat/libopenmpt.c +1 −1
libavformat/avformat.h+1−1
@@ -459,7 +459,7 @@ typedef struct AVProbeData { · 458 unmodified lines
459459 #define AVPROBE_SCORE_STREAM_RETRY (AVPROBE_SCORE_MAX/4-1)
460460
461461 #define AVPROBE_SCORE_EXTENSION 50 ///< score for file extension
462−#define AVPROBE_SCORE_MIME 75 ///< score for file mime type
462+#define AVPROBE_SCORE_MIME_BONUS 30 ///< score added for matching mime type
463463 #define AVPROBE_SCORE_MAX 100 ///< maximum score
464464
465465 #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
libavformat/format.c+4−4
@@ -212,10 +212,10 @@ const AVInputFormat *av_probe_input_format3(const AVProbeData *pd, · 211 unmodified lines
212212 score = AVPROBE_SCORE_EXTENSION;
213213 }
214214 if (av_match_name(lpd.mime_type, fmt1->mime_type)) {
215− if (AVPROBE_SCORE_MIME > score) {
216− av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to %d due to MIME type\n", fmt1->name, score, AVPROBE_SCORE_MIME);
217− score = AVPROBE_SCORE_MIME;
218− }
215+ int old_score = score;
216+ score += AVPROBE_SCORE_MIME_BONUS;
217+ if (score > AVPROBE_SCORE_MAX) score = AVPROBE_SCORE_MAX;
218+ av_log(NULL, AV_LOG_DEBUG, "Probing %s score:%d increased to %d due to MIME type\n", fmt1->name, old_score, score);
219219 }
220220 if (score > score_max) {
221221 score_max = score;
libavformat/libopenmpt.c+1−1
@@ -244,7 +244,7 @@ static int read_probe_openmpt(const AVProbeData *p) · 243 unmodified lines
244244 * AVPROBE_SCORE_MAX in order to reduce the impact in the rare
245245 * cases of false positives.
246246 */
247− return AVPROBE_SCORE_MIME + 1;
247+ return (AVPROBE_SCORE_MAX * 3) / 4 + 1;
248248 } else if (probe_result == OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA) {
249249 if (probe_openmpt_extension(p) > 0) {
250250 return AVPROBE_SCORE_RETRY;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t