diff options
author | Mats Peterson <matsp888@yahoo.com> | 2015-12-27 21:28:09 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2015-12-28 02:47:58 +0100 |
commit | 7973603843731b57cea5a62d4b4381722731fd2c (patch) | |
tree | 5f23bd22dd714fe85ffc0d8f957bd93577d57fa0 | |
parent | 57631f1851ef71918b68b9a9bdfbeb2974ec1458 (diff) | |
download | ffmpeg-7973603843731b57cea5a62d4b4381722731fd2c.tar.gz |
avformat/matroskadec: palettized QuickTime video in Matroska
Palettized QuickTime video in Matroska has hitherto not been recognized
whatsoever, and the "palette" used has been completely random.
The patch for matroskadec.c fixes this issue by adding a palette side
data packet in matroska_deliver_packet(), much in the same way as it's
done in mov.c.
Video samples for testing are available at
https://drive.google.com/open?id=0B3_pEBoLs0faWElmM2FnLTZYNlk.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavformat/matroskadec.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index c5747492a0..9de7cfba74 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -64,6 +64,8 @@ #include <zlib.h> #endif +#include "qtpalette.h" + typedef enum { EBML_NONE, EBML_UINT, @@ -312,6 +314,9 @@ typedef struct MatroskaDemuxContext { /* WebM DASH Manifest live flag/ */ int is_live; + + uint32_t palette[AVPALETTE_COUNT]; + int has_palette; } MatroskaDemuxContext; typedef struct MatroskaBlock { @@ -1856,7 +1861,7 @@ static int matroska_parse_tracks(AVFormatContext *s) fourcc = st->codec->codec_tag; extradata_offset = FFMIN(track->codec_priv.size, 18); } else if (!strcmp(track->codec_id, "A_QUICKTIME") - && (track->codec_priv.size >= 86) + && (track->codec_priv.size >= 36) && (track->codec_priv.data)) { fourcc = AV_RL32(track->codec_priv.data + 4); codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc); @@ -1881,6 +1886,16 @@ static int matroska_parse_tracks(AVFormatContext *s) av_log(matroska->ctx, AV_LOG_ERROR, "mov FourCC not found %s.\n", buf); } + if (track->codec_priv.size >= 86) { + bit_depth = AV_RB16(track->codec_priv.data + 82); + ffio_init_context(&b, track->codec_priv.data, + track->codec_priv.size, + 0, NULL, NULL, NULL, NULL); + if (ff_get_qtpalette(codec_id, &b, matroska->palette)) { + bit_depth &= 0x1F; + matroska->has_palette = 1; + } + } } else if (codec_id == AV_CODEC_ID_PCM_S16BE) { switch (track->audio.bitdepth) { case 8: @@ -2326,6 +2341,15 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, if (matroska->num_packets > 0) { memcpy(pkt, matroska->packets[0], sizeof(AVPacket)); av_freep(&matroska->packets[0]); + if (matroska->has_palette) { + uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); + if (!pal) { + av_log(matroska->ctx, AV_LOG_ERROR, "Cannot append palette to packet\n"); + } else { + memcpy(pal, matroska->palette, AVPALETTE_SIZE); + } + matroska->has_palette = 0; + } if (matroska->num_packets > 1) { void *newpackets; memmove(&matroska->packets[0], &matroska->packets[1], |