[libav-commits] mov: detect cover art pictures by content

wm4 git at libav.org
Tue Nov 3 15:48:37 CET 2015


Module: libav
Branch: master
Commit: f128b8e19ac7f702adae899ab91cc1e80f238761

Author:    wm4 <nfxjfg at googlemail.com>
Committer: Luca Barbato <lu_zero at gentoo.org>
Date:      Sat Oct 31 14:36:38 2015 +0100

mov: detect cover art pictures by content

I've got some m4a samples that had jpeg cover art marked as png. Since
these files were supposedly written by iTunes, and other software can
read it (e.g. clementine does), this should be worked around.

Since png has a very simple to detect header, while it's apparently a
real pain to detect jpeg in the general case, try to detect png and
assume jpeg otherwise. Not bothering with bmp, as I have no test case.

Signed-off-by: Luca Barbato <lu_zero at gentoo.org>

---

 libavformat/mov.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 95dc1ee..9532213 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -200,6 +200,14 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len)
     if (ret < 0)
         return ret;
 
+    if (pkt.size >= 8 && id != AV_CODEC_ID_BMP) {
+        if (AV_RB64(pkt.data) == 0x89504e470d0a1a0a) {
+            id = AV_CODEC_ID_PNG;
+        } else {
+            id = AV_CODEC_ID_MJPEG;
+        }
+    }
+
     st->disposition              |= AV_DISPOSITION_ATTACHED_PIC;
 
     st->attached_pic              = pkt;



More information about the libav-commits mailing list