[FFmpeg-cvslog] avformat/movenc: properly handle cover image codecs
Timo Teräs
git at videolan.org
Sat Jun 16 01:32:37 EEST 2018
ffmpeg | branch: release/4.0 | Timo Teräs <timo.teras at iki.fi> | Fri Jun 1 02:24:39 2018 +0300| [36628bd215699afaeec732f54fc08287e3f76b56] | committer: Michael Niedermayer
avformat/movenc: properly handle cover image codecs
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>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 12205d2c896b7edbc929d4886e7bfda4b53538e5)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=36628bd215699afaeec732f54fc08287e3f76b56
---
libavformat/movenc.c | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 0b44fd66ea..9beb1e2395 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1554,10 +1554,20 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track)
return tag;
}
+static const AVCodecTag codec_cover_image_tags[] = {
+ { AV_CODEC_ID_MJPEG, 0xD },
+ { AV_CODEC_ID_PNG, 0xE },
+ { AV_CODEC_ID_BMP, 0x1B },
+ { 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)
@@ -3426,7 +3436,7 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s)
{
MOVMuxContext *mov = s->priv_data;
int64_t pos = 0;
- int i, type;
+ int i;
for (i = 0; i < s->nb_streams; i++) {
MOVTrack *trk = &mov->tracks[i];
@@ -3436,22 +3446,6 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s)
trk->cover_image.size <= 0)
continue;
- switch (st->codecpar->codec_id) {
- case AV_CODEC_ID_MJPEG:
- type = 0xD;
- break;
- case AV_CODEC_ID_PNG:
- type = 0xE;
- break;
- case AV_CODEC_ID_BMP:
- type = 0x1B;
- break;
- default:
- av_log(s, AV_LOG_ERROR, "unsupported codec_id (0x%x) for cover",
- st->codecpar->codec_id);
- continue;
- }
-
if (!pos) {
pos = avio_tell(pb);
avio_wb32(pb, 0);
@@ -3459,7 +3453,7 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s)
}
avio_wb32(pb, 16 + trk->cover_image.size);
ffio_wfourcc(pb, "data");
- avio_wb32(pb, type);
+ avio_wb32(pb, trk->tag);
avio_wb32(pb , 0);
avio_write(pb, trk->cover_image.data, trk->cover_image.size);
}
More information about the ffmpeg-cvslog
mailing list