[FFmpeg-devel] [PATCH] avformat/movenc: properly handle cover image codecs

Timo Teräs timo.teras at iki.fi
Fri Jun 1 01:58:47 EEST 2018


Find codec tag for attached images using appropriate list of
supported image formats.

This fixes writing the cover image to m4v/m4a and other container
formats that do not allow these codecs as a track.

Signed-off-by: Timo Teräs <timo.teras at iki.fi>
---
This replaces the previous patch:
 PATCH] [RFC] avformat/movenc: support covert images for ipod muxer

It appears that query_codec() is used only to figure out which stream
to select as the default copy stream. Fixing it properly for movenc
attached pictures is difficult, as the stream disposition would need
to be passed through the call stack. Additionally, it would make sense
to rewrite the selection logic open_output_file() to not use APIC
special tag and be based on the input/output dispositions.

So this just adds proper handling of the codecs in mov_init() phase
which fixes most of the usability issues.

Please backport to 4.0 stable branch too.

 libavformat/movenc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7e616e866f..8c370ee7b9 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1557,10 +1557,20 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track)
     return tag;
 }
 
+static const AVCodecTag codec_cover_image_tags[] = {
+    { AV_CODEC_ID_MJPEG,  MKTAG('A','P','I','C') },
+    { AV_CODEC_ID_PNG,    MKTAG('A','P','I','C') },
+    { AV_CODEC_ID_BMP,    MKTAG('A','P','I','C') },
+    { AV_CODEC_ID_NONE, 0 },
+};
+
 static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
 {
     int tag;
 
+    if (track->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+        return ff_codec_get_tag(codec_cover_image_tags, track->par->codec_id);
+
     if (track->mode == MODE_MP4 || track->mode == MODE_PSP)
         tag = track->par->codec_tag;
     else if (track->mode == MODE_ISM)
-- 
2.17.0



More information about the ffmpeg-devel mailing list