From 15a191f920fa46c56face1d1364402fbfb498c5c Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 22 Dec 2014 12:53:51 +0100 Subject: demux_mkv: support embedded coverart The code could as well be in demux.c, but it's better to avoid accidental clashes with demux_lavf.c. FFmpeg provides no way yet to map a mime type to a codec, so do it manually. (It _can_ map a mime type to an "input format", but not a codec.) Fixes #1374. --- demux/codec_tags.c | 17 +++++++++++++++++ demux/codec_tags.h | 2 ++ demux/demux_mkv.c | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/demux/codec_tags.c b/demux/codec_tags.c index 9af4035ed1..0ca6ce70da 100644 --- a/demux/codec_tags.c +++ b/demux/codec_tags.c @@ -421,3 +421,20 @@ void mp_set_pcm_codec(struct sh_stream *sh, bool sign, bool is_float, int bits, mp_snprintf_cat(codec, sizeof(codec), is_be ? "be" : "le"); sh->codec = talloc_strdup(sh->audio, codec); } + +static const char *const mimetype_to_codec[][2] = { + {"image/jpeg", "mjpeg"}, + {"image/png", "png"}, + {0} +}; + +const char *mp_map_mimetype_to_video_codec(const char *mimetype) +{ + if (mimetype) { + for (int n = 0; mimetype_to_codec[n][0]; n++) { + if (strcmp(mimetype_to_codec[n][0], mimetype) == 0) + return mimetype_to_codec[n][1]; + } + } + return NULL; +} diff --git a/demux/codec_tags.h b/demux/codec_tags.h index b65b68792a..93f046da0d 100644 --- a/demux/codec_tags.h +++ b/demux/codec_tags.h @@ -30,4 +30,6 @@ void mp_set_codec_from_tag(struct sh_stream *sh); void mp_set_pcm_codec(struct sh_stream *sh, bool sign, bool is_float, int bits, bool is_be); +const char *mp_map_mimetype_to_video_codec(const char *mimetype); + #endif diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 980f8e79da..9e26c175ea 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -1123,7 +1123,20 @@ skip: return 0; } - +static void add_coverart(struct demuxer *demuxer) +{ + for (int n = 0; n < demuxer->num_attachments; n++) { + struct demux_attachment *att = &demuxer->attachments[n]; + const char *codec = mp_map_mimetype_to_video_codec(att->type); + if (!codec) + continue; + struct sh_stream *sh = new_sh_stream(demuxer, STREAM_VIDEO); + if (!sh) + break; + sh->codec = codec; + sh->attached_picture = new_demux_packet_from(att->data, att->data_size); + } +} static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track); static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track); @@ -1859,6 +1872,7 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check) process_tags(demuxer); display_create_tracks(demuxer); + add_coverart(demuxer); if (demuxer->opts->mkv_probe_duration) probe_last_timestamp(demuxer); -- cgit v1.2.3