From 2ab6d21dbf9258794a95ee423929485ccad53d91 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Fri, 16 May 2014 09:58:54 -0700 Subject: [PATCH] metadata: get embedded cover art from video files using libavformat Newer version of libavformat can grab cover art, so we'll go ahead and use it. We also need to make sure we don't confuse cover art with a normal video stream. --- libav.h | 17 +++++++++++++++++ metadata.c | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libav.h b/libav.h index 69680a9..01da752 100644 --- a/libav.h +++ b/libav.h @@ -163,3 +163,20 @@ lav_get_interlaced(AVCodecContext *vc, AVStream *s) return (vc->time_base.den ? (s->avg_frame_rate.num / vc->time_base.den) : 0); #endif } + +static inline int +lav_is_thumbnail_stream(AVStream *s, uint8_t **data, int *size) +{ +#if LIBAVFORMAT_VERSION_INT >= ((54<<16)+(6<<8)) + if (s->disposition & AV_DISPOSITION_ATTACHED_PIC && + s->codec->codec_id == AV_CODEC_ID_MJPEG) + { + if (data) + *data = s->attached_pic.data; + if (size) + *size = s->attached_pic.size; + return 1; + } +#endif + return 0; +} diff --git a/metadata.c b/metadata.c index 2e287e8..5f4ef2c 100644 --- a/metadata.c +++ b/metadata.c @@ -712,6 +712,7 @@ GetVideoMetadata(const char *path, char *name) continue; } else if( video_stream == -1 && + !lav_is_thumbnail_stream(ctx->streams[i], &video.image, &video.image_size) && ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO ) { video_stream = i; @@ -1530,7 +1531,6 @@ video_no_dlna: else DPRINTF(E_WARN, L_METADATA, "%s: Unhandled format: %s\n", path, ctx->iformat->name); } - lav_close(ctx); if( !m.date ) { @@ -1544,6 +1544,7 @@ video_no_dlna: album_art = find_album_art(path, video.image, video.image_size); freetags(&video); + lav_close(ctx); ret = sql_exec(db, "INSERT into DETAILS" " (PATH, SIZE, TIMESTAMP, DURATION, DATE, CHANNELS, BITRATE, SAMPLERATE, RESOLUTION,"