[FFmpeg-devel] [PATCH v4 2/5 v2] lavf/movenc: Add support for palette side data

Michael Niedermayer michael at niedermayer.cc
Wed Mar 2 22:30:06 CET 2016


On Wed, Mar 02, 2016 at 08:33:42PM +0100, Mats Peterson wrote:
> Check that the track type is AVMEDIA_TYPE_VIDEO in appropriate places.
> 
> -- 
> Mats Peterson
> http://matsp888.no-ip.org/~mats/

>  movenc.c |   45 +++++++++++++++++++++++++++------------------
>  1 file changed, 27 insertions(+), 18 deletions(-)
> f2f811cb47f8ba331ca3886ef99239f68aef98a0  0002-lavf-movenc-Add-support-for-palette-side-data.patch
> From c2d0b7a69486afb926e731216b4aff3b04c4ee4a Mon Sep 17 00:00:00 2001
> From: Mats Peterson <matsp888 at yahoo.com>
> Date: Wed, 2 Mar 2016 20:30:59 +0100
> Subject: [PATCH v4 2/5 v2] lavf/movenc: Add support for palette side data
> 
> ---
>  libavformat/movenc.c |   45 +++++++++++++++++++++++++++------------------
>  1 file changed, 27 insertions(+), 18 deletions(-)
> 
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 3295266..277f2d2 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1716,13 +1716,14 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr
>      else
>          avio_wb16(pb, 0x18); /* Reserved */
>  
> -    if (track->is_unaligned_qt_rgb && track->enc->pix_fmt == AV_PIX_FMT_PAL8) {
> +    if (track->mode == MODE_MOV && track->enc->pix_fmt == AV_PIX_FMT_PAL8) {
> +        int pal_size = 1 << track->enc->bits_per_coded_sample;
>          int i;
>          avio_wb16(pb, 0);             /* Color table ID */
>          avio_wb32(pb, 0);             /* Color table seed */
>          avio_wb16(pb, 0x8000);        /* Color table flags */
> -        avio_wb16(pb, 255);           /* Color table size (zero-relative) */
> -        for (i = 0; i < 256; i++) {
> +        avio_wb16(pb, pal_size - 1);  /* Color table size (zero-relative) */
> +        for (i = 0; i < pal_size; i++) {
>              uint32_t rgb = AV_RL32(&track->palette[i]);
>              uint16_t r = (rgb >> 16) & 0xff;
>              uint16_t g = (rgb >> 8)  & 0xff;
> @@ -4763,21 +4764,29 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
>              }
>          }
>  
> -        if (trk->is_unaligned_qt_rgb) {
> -            const uint8_t *data = pkt->data;
> -            int size = pkt->size;
> -            int64_t bpc = trk->enc->bits_per_coded_sample != 15 ? trk->enc->bits_per_coded_sample : 16;
> -            int expected_stride = ((trk->enc->width * bpc + 15) >> 4)*2;
> -            int ret = ff_reshuffle_raw_rgb(s, &pkt, trk->enc, expected_stride);
> -            if (ret < 0)
> -                return ret;
> -            if (ret == CONTAINS_PAL && !trk->pal_done) {
> -                int pal_size = 1 << trk->enc->bits_per_coded_sample;
> -                memset(trk->palette, 0, AVPALETTE_SIZE);
> -                memcpy(trk->palette, data + size - 4*pal_size, 4*pal_size);
> -                trk->pal_done++;
> -            } else if (trk->enc->pix_fmt == AV_PIX_FMT_GRAY8 ||
> -                       trk->enc->pix_fmt == AV_PIX_FMT_MONOBLACK) {
> +        if (trk->mode == MODE_MOV && trk->enc->codec_type == AVMEDIA_TYPE_VIDEO) {
> +            AVPacket *opkt = pkt;
> +            int ret;
> +            if (trk->is_unaligned_qt_rgb) {
> +                int64_t bpc = trk->enc->bits_per_coded_sample != 15 ? trk->enc->bits_per_coded_sample : 16;
> +                int expected_stride = ((trk->enc->width * bpc + 15) >> 4)*2;
> +                ret = ff_reshuffle_raw_rgb(s, &pkt, trk->enc, expected_stride);
> +                if (ret < 0)
> +                    return ret;
> +            } else
> +                ret = 0;
> +            if (trk->enc->pix_fmt == AV_PIX_FMT_PAL8 && !trk->pal_done) {
> +                const uint8_t *pal;
> +                int ret2 = ff_get_packet_palette(s, opkt, ret, &pal);
> +                if (ret2 < 0)
> +                    return ret2;
> +                if (pal) {
> +                    memcpy(trk->palette, pal, AVPALETTE_SIZE);

this fails on big endian
AV_PKT_DATA_PALETTE is stored in cpu endianness

in general AVPacket->data is defined byte per byte and can be stored
as is byte per byte
AVPacket->side_data is in whatever endianness
people preferred at the time a specific AV_PKT_DATA_* was added.
in case of AV_PKT_DATA_PALETTE its native cpu endianness

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160302/9b31f106/attachment.sig>


More information about the ffmpeg-devel mailing list