[FFmpeg-devel] [PATCH]Autodetect raw flac files

Carl Eugen Hoyos cehoyos at ag.or.at
Fri Apr 10 00:13:28 CEST 2015


On Thursday 09 April 2015 03:46:42 pm Michael Niedermayer wrote:
> On Thu, Apr 09, 2015 at 01:21:32PM +0200, Carl Eugen Hoyos wrote:
> > Hi!
> >
> > Attached patch allows to autodetect headerless flac files.
> >
> > Please comment, Carl Eugen
> >
> >  flacdec.c |    2 ++
> >  1 file changed, 2 insertions(+)
> > 393c746cefb2dd386719591734f01d6df2ca124c  patchflac.diff
> > diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
>
> i would slightly prefer if more bytes are checked

New patch attached.

Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 1a8dc19..f3d0689 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -178,6 +178,14 @@ fail:
 
 static int flac_probe(AVProbeData *p)
 {
+    if (   (AV_RB16(p->buf) & 0xFFFE) == 0xFFF8
+        && p->buf[2] & 0xF0        // blocksize code != 0
+        && p->buf[2] & 0x0F ^ 0x0F // sample rate code < 15
+        && (p->buf[3] & 0xF0) < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE << 4
+        // channel mode < 11
+        && p->buf[3] & 0x06 ^ 0x06 // bits per sample code valid
+        && p->buf[3] ^ 1)          // reserved bit not set
+        return AVPROBE_SCORE_EXTENSION / 4 + 1;
     if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4))
         return 0;
     return AVPROBE_SCORE_EXTENSION;


More information about the ffmpeg-devel mailing list