[FFmpeg-devel] [PATCH v4] lavf/movenc: Add palette to video sample description

Michael Niedermayer michael at niedermayer.cc
Sun Feb 21 04:23:54 CET 2016


On Sun, Feb 21, 2016 at 02:00:14AM +0100, Mats Peterson wrote:
> Forgot movenc.h.
> 
> -- 
> Mats Peterson
> http://matsp888.no-ip.org/~mats/

>  movenc.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  movenc.h |    3 +++
>  2 files changed, 52 insertions(+), 1 deletion(-)
> c457708edf127bdc07abe09d583ac34603a5f4df  0001-lavf-movenc-Add-palette-to-video-sample-description.patch
> From dac790207f7057a460a6f460a6146e937fc89211 Mon Sep 17 00:00:00 2001
> From: Mats Peterson <matsp888 at yahoo.com>
> Date: Sun, 21 Feb 2016 01:59:17 +0100
> Subject: [PATCH v4] lavf/movenc: Add palette to video sample description
> 
> ---
>  libavformat/movenc.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++++-
>  libavformat/movenc.h |    3 +++
>  2 files changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index b9c0f7a..cc5ceb2 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1714,7 +1714,29 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr
>          avio_wb16(pb, track->enc->bits_per_coded_sample);
>      else
>          avio_wb16(pb, 0x18); /* Reserved */
> -    avio_wb16(pb, 0xffff); /* Reserved */
> +
> +    if (track->enc->codec_id == AV_CODEC_ID_RAWVIDEO &&
> +        track->enc->bits_per_coded_sample >= 1 && track->enc->bits_per_coded_sample <= 8) {
> +        int i;
> +        int pal_size = 1 << track->enc->bits_per_coded_sample;
> +        avio_wb16(pb, 0);             /* Color table ID */
> +        avio_wb32(pb, 0);             /* Color table seed */
> +        avio_wb16(pb, 0x8000);        /* Color table flags */
> +        avio_wb16(pb, pal_size - 1);  /* Color table size (zero-relative) */
> +        for (i = 0; i < pal_size; i++) {
> +            uint32_t v = mov->palette[i];
> +            uint32_t r, g, b;
> +            avio_wb16(pb, 0);
> +            r = (v >> 16) & 0xff;
> +            avio_wb16(pb, (r << 8) | r);
> +            g = (v >> 8) & 0xff;
> +            avio_wb16(pb, (g << 8) | g);
> +            b = v & 0xff;
> +            avio_wb16(pb, (b << 8) | b);
> +        }
> +    } else
> +        avio_wb16(pb, 0xffff); /* Color table ID, -1 for no or default palette */
> +
>      if (track->tag == MKTAG('m','p','4','v'))
>          mov_write_esds_tag(pb, track);
>      else if (track->enc->codec_id == AV_CODEC_ID_H263)
> @@ -4703,6 +4725,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
>      } else {
>          int i;
>          MOVMuxContext *mov = s->priv_data;
> +        MOVTrack *trk = &mov->tracks[pkt->stream_index];
>  
>          if (!pkt->size)
>              return mov_write_single_packet(s, pkt); /* Passthrough. */
> @@ -4739,6 +4762,31 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
>              }
>          }
>  
> +        if (trk->enc->codec_id == AV_CODEC_ID_RAWVIDEO) {
> +            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);

i think this would also get run for raw yuv formats

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange
-------------- 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/20160221/265c5dd6/attachment.sig>


More information about the ffmpeg-devel mailing list