[FFmpeg-devel] [PATCH 2/2] avformat/avienc: reformat raw rgb to comply to specs

Mats Peterson matsp888 at yahoo.com
Wed Feb 17 04:48:01 CET 2016


On 02/17/2016 04:38 AM, Mats Peterson wrote:
> Michael Niedermayer <michael at niedermayer.cc> skrev: (17 februari 2016 03:50:58 CET)
>> @todo move to seperate file and reuse in movenc
>>
>> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
>> ---
>> libavformat/avienc.c          |   40
>> ++++++++++++++++++++++++++++++++++++++++
>> tests/ref/vsynth/vsynth3-bpp1 |    4 ++--
>> tests/ref/vsynth/vsynth3-rgb  |    4 ++--
>> 3 files changed, 44 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavformat/avienc.c b/libavformat/avienc.c
>> index 649961d..b9aee37 100644
>> --- a/libavformat/avienc.c
>> +++ b/libavformat/avienc.c
>> @@ -644,6 +644,38 @@ static int write_skip_frames(AVFormatContext *s,
>> int stream_index, int64_t dts)
>>      return 0;
>> }
>>
>> +static int write_reshuffled_raw_rgb(AVFormatContext *s, AVPacket *pkt,
>> AVCodecContext *enc, int expected_stride)
>> +{
>> +    int ret;
>> +    AVPacket *new_pkt = av_packet_alloc();
>> +    int stride = pkt->size / enc->height;
>> +    int padding = expected_stride - FFMIN(expected_stride, stride);
>> +    int y;
>> +
>> +    if (!new_pkt)
>> +        return AVERROR(ENOMEM);
>> +
>> +    ret = av_new_packet(new_pkt, expected_stride * enc->height);
>> +    if (ret < 0)
>> +        goto end;
>> +
>> +    ret = av_packet_copy_props(new_pkt, pkt);
>> +    if (ret < 0)
>> +        goto end;
>> +
>> +    for (y = 0; y<enc->height; y++) {
>> +        memcpy(new_pkt->data + y*expected_stride, pkt->data +
>> y*stride, FFMIN(expected_stride, stride));
>> +        memset(new_pkt->data + y*expected_stride + expected_stride -
>> padding, 0, padding);
>> +    }
>> +
>> +    ret = avi_write_packet(s, new_pkt);
>> +
>> +end:
>> +    av_packet_free(&new_pkt);
>> +
>> +    return ret;
>> +}
>> +
>> static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
>> {
>>      unsigned char tag[5];
>> @@ -661,6 +693,14 @@ static int avi_write_packet(AVFormatContext *s,
>> AVPacket *pkt)
>>          if (ret < 0)
>>              return ret;
>>      }
>> +    if (enc->codec_id == AV_CODEC_ID_RAWVIDEO && enc->codec_tag == 0)
>> {
>> +        int64_t bpc = enc->bits_per_coded_sample != 15 ?
>> enc->bits_per_coded_sample : 16;
>> +        int expected_stride = ((enc->width * bpc + 31) >> 5)*4;
>> +        int stride = (enc->width * bpc + 7) >> 3;
>> +        if (expected_stride * enc->height != pkt->size &&
>> +            stride * enc->height == pkt->size)
>> +            return write_reshuffled_raw_rgb(s, pkt, enc,
>> expected_stride);
>> +    }
>>
>>      if ((ret = write_skip_frames(s, stream_index, pkt->dts)) < 0)
>>          return ret;
>> diff --git a/tests/ref/vsynth/vsynth3-bpp1
>> b/tests/ref/vsynth/vsynth3-bpp1
>> index 5a65728..39f27f3 100644
>> --- a/tests/ref/vsynth/vsynth3-bpp1
>> +++ b/tests/ref/vsynth/vsynth3-bpp1
>> @@ -1,4 +1,4 @@
>> -98852649c5201df7d85d0e9b5a5b9f15 *tests/data/fate/vsynth3-bpp1.avi
>> -15352 tests/data/fate/vsynth3-bpp1.avi
>> +d5689d1f5c2d4c28a345d5964a6161a8 *tests/data/fate/vsynth3-bpp1.avi
>> +20452 tests/data/fate/vsynth3-bpp1.avi
>> 0b1ea21b69d384564dd3a978065443b2
>> *tests/data/fate/vsynth3-bpp1.out.rawvideo
>> stddev:   97.64 PSNR:  8.34 MAXDIFF:  248 bytes:    86700/    86700
>> diff --git a/tests/ref/vsynth/vsynth3-rgb
>> b/tests/ref/vsynth/vsynth3-rgb
>> index c0a8563..f67d285 100644
>> --- a/tests/ref/vsynth/vsynth3-rgb
>> +++ b/tests/ref/vsynth/vsynth3-rgb
>> @@ -1,4 +1,4 @@
>> -a2cb86007b8945e2d1399b56585b983a *tests/data/fate/vsynth3-rgb.avi
>> -180252 tests/data/fate/vsynth3-rgb.avi
>> +000bd5f3251bfd6a2a2b590b2d16fe0b *tests/data/fate/vsynth3-rgb.avi
>> +183652 tests/data/fate/vsynth3-rgb.avi
>> 693aff10c094f8bd31693f74cf79d2b2
>> *tests/data/fate/vsynth3-rgb.out.rawvideo
>> stddev:    3.67 PSNR: 36.82 MAXDIFF:   43 bytes:    86700/    86700
>> --
>> 1.7.9.5
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> Splendid job, Michael. Now only to properly attach the palette to the BITMAPINFOHEADER in the strf chunk for AVI. And include it in the video sample description for QuickTime.
>
> Mats
>

AVI has support for palette switching by using the 'xxpc' chunk in the 
video data for the record, but it hasn't been implemented yet. I suppose 
it's enough to just add an "initial" palette to the BITMAPINFOHEADER in 
the meantime.

Mats

-- 
Mats Peterson
http://matsp888.no-ip.org/~mats/


More information about the ffmpeg-devel mailing list