[FFmpeg-cvslog] mp3/ac3 probe: search for PES headers to prevent probing MPEG-PS as MP3.

Ronald S. Bultje git at videolan.org
Thu May 31 21:42:38 CEST 2012


ffmpeg | branch: master | Ronald S. Bultje <rsbultje at gmail.com> | Wed May  2 15:45:18 2012 -0700| [64bde8056337bb656a11f3c9e2857c10b94e2871] | committer: Ronald S. Bultje

mp3/ac3 probe: search for PES headers to prevent probing MPEG-PS as MP3.

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

 libavformat/ac3dec.c |   30 +++++++++++++++++++++++++-----
 libavformat/mp3dec.c |   30 +++++++++++++++++++++++++-----
 2 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 60c3cf9..c2e3301 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -57,11 +57,31 @@ static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
     if(codec_id != expected_codec_id) return 0;
     // keep this in sync with mp3 probe, both need to avoid
     // issues with MPEG-files!
-    if   (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
-    else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
-    else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
-    else if(max_frames>=1) return 1;
-    else                   return 0;
+    if (first_frames >= 4) return AVPROBE_SCORE_MAX / 2 + 1;
+
+    if (max_frames) {
+        int pes = 0, i;
+        unsigned int code = -1;
+
+#define VIDEO_ID 0x000001e0
+#define AUDIO_ID 0x000001c0
+        /* do a search for mpegps headers to be able to properly bias
+         * towards mpegps if we detect this stream as both. */
+        for (i = 0; i<p->buf_size; i++) {
+            code = (code << 8) + p->buf[i];
+            if ((code & 0xffffff00) == 0x100) {
+                if     ((code & 0x1f0) == VIDEO_ID) pes++;
+                else if((code & 0x1e0) == AUDIO_ID) pes++;
+            }
+        }
+
+        if (pes)
+            max_frames = (max_frames + pes - 1) / pes;
+    }
+    if      (max_frames >  500) return AVPROBE_SCORE_MAX / 2;
+    else if (max_frames >= 4)   return AVPROBE_SCORE_MAX / 4;
+    else if (max_frames >= 1)   return 1;
+    else                        return 0;
 }
 
 #if CONFIG_AC3_DEMUXER
diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index d233209..3987520 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -63,11 +63,31 @@ static int mp3_read_probe(AVProbeData *p)
     }
     // keep this in sync with ac3 probe, both need to avoid
     // issues with MPEG-files!
-    if   (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
-    else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
-    else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
-    else if(max_frames>=1) return 1;
-    else                   return 0;
+    if (first_frames >= 4) return AVPROBE_SCORE_MAX / 2 + 1;
+
+    if (max_frames) {
+        int pes = 0, i;
+        unsigned int code = -1;
+
+#define VIDEO_ID 0x000001e0
+#define AUDIO_ID 0x000001c0
+        /* do a search for mpegps headers to be able to properly bias
+         * towards mpegps if we detect this stream as both. */
+        for (i = 0; i<p->buf_size; i++) {
+            code = (code << 8) + p->buf[i];
+            if ((code & 0xffffff00) == 0x100) {
+                if     ((code & 0x1f0) == VIDEO_ID) pes++;
+                else if((code & 0x1e0) == AUDIO_ID) pes++;
+            }
+        }
+
+        if (pes)
+            max_frames = (max_frames + pes - 1) / pes;
+    }
+    if      (max_frames >  500) return AVPROBE_SCORE_MAX / 2;
+    else if (max_frames >= 4)   return AVPROBE_SCORE_MAX / 4;
+    else if (max_frames >= 1)   return 1;
+    else                        return 0;
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
 }
 



More information about the ffmpeg-cvslog mailing list