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.
This commit is contained in:
Justin Maggard 2014-05-16 09:58:54 -07:00
parent 05cde8a79f
commit 2ab6d21dbf
2 changed files with 19 additions and 1 deletions

17
libav.h
View File

@ -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;
}

View File

@ -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,"