[FFmpeg-devel] [PATCH v1 1/2] codec: vrawdepay: add decoder for RFC4175

Rostislav Pehlivanov atomnuker at gmail.com
Thu Feb 16 20:18:44 EET 2017


On 16 February 2017 at 17:43, Damien Riegel <
damien.riegel at savoirfairelinux.com> wrote:

> Add a codec capable of decoding some formats of the RFC4175. For now
> it's only capable of handling YCbCr-4:2:2 with 8-bit or 10-bit depth.
>
> For 8-bit it's a simple pass-through, for 10-bit it depacks the stream
> in the AV_PIX_FMT_YUV422P10 pixel format.
> Change-Id: Id2184a6cee7031edbcb65a39a369623114c1783c
>
> Signed-off-by: Damien Riegel <damien.riegel at savoirfairelinux.com>
> ---
>  libavcodec/Makefile     |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h    |   1 +
>  libavcodec/codec_desc.c |   7 +++
>  libavcodec/vrawdepay.c  | 113 ++++++++++++++++++++++++++++++
> ++++++++++++++++++
>  5 files changed, 123 insertions(+)
>  create mode 100644 libavcodec/vrawdepay.c
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index a1ce264f25..e09dcc3c1b 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -614,6 +614,7 @@ OBJS-$(CONFIG_VP9_CUVID_DECODER)       += cuvid.o
>  OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER)  += mediacodecdec.o
>  OBJS-$(CONFIG_VPLAYER_DECODER)         += textdec.o ass.o
>  OBJS-$(CONFIG_VQA_DECODER)             += vqavideo.o
> +OBJS-$(CONFIG_VRAWDEPAY_DECODER)       += vrawdepay.o
>  OBJS-$(CONFIG_WAVPACK_DECODER)         += wavpack.o
>  OBJS-$(CONFIG_WAVPACK_ENCODER)         += wavpackenc.o
>  OBJS-$(CONFIG_WEBP_DECODER)            += webp.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index f12a54df50..dcce291ba2 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -365,6 +365,7 @@ void avcodec_register_all(void)
>      REGISTER_DECODER(VP8,               vp8);
>      REGISTER_DECODER(VP9,               vp9);
>      REGISTER_DECODER(VQA,               vqa);
> +    REGISTER_DECODER(VRAWDEPAY,         vrawdepay);
>      REGISTER_DECODER(WEBP,              webp);
>      REGISTER_ENCODER(WRAPPED_AVFRAME,   wrapped_avframe);
>      REGISTER_ENCDEC (WMV1,              wmv1);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 5616fb01d6..aca4fe61e6 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -415,6 +415,7 @@ enum AVCodecID {
>      AV_CODEC_ID_PIXLET,
>      AV_CODEC_ID_SPEEDHQ,
>      AV_CODEC_ID_FMVC,
> +    AV_CODEC_ID_VRAWDEPAY,
>
>      /* various PCM "codecs" */
>      AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at
> the start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 35846c054e..8a3492adcf 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1360,6 +1360,13 @@ static const AVCodecDescriptor codec_descriptors[]
> = {
>          .long_name = NULL_IF_CONFIG_SMALL("FM Screen Capture Codec"),
>          .props     = AV_CODEC_PROP_LOSSLESS,
>      },
> +    {
> +        .id        = AV_CODEC_ID_VRAWDEPAY,
> +        .type      = AVMEDIA_TYPE_VIDEO,
> +        .name      = "rfc4175",
> +        .long_name = NULL_IF_CONFIG_SMALL("RFC4175 video depayloader"),
> +        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
> +    },
>
>      /* image codecs */
>      {
> diff --git a/libavcodec/vrawdepay.c b/libavcodec/vrawdepay.c
> new file mode 100644
> index 0000000000..53a5c38bb3
> --- /dev/null
> +++ b/libavcodec/vrawdepay.c
> @@ -0,0 +1,113 @@
> +/*
> + * Raw Video Depayloader (RFC4175)
> + * Copyright (c) 2017 Savoir-faire Linux, Inc
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + */
> +
> +/* Development sponsored by CBC/Radio-Canada */
> +
> +/**
> + * @file
> + * Raw Video Depayloader (RFC4175)
> + */
> +
> +#include <libavutil/imgutils.h>
> +#include "avcodec.h"
> +#include "internal.h"
> +#include "get_bits.h"
> +
> +static av_cold int vrawdepay_init_decoder(AVCodecContext *avctx)
> +{
> +   if (!avctx->codec_tag || !avctx->width || !avctx->height)
> +      return -1;
> +
> +   if (avctx->codec_tag == MKTAG('U', 'Y', 'V', 'Y')) {
> +      if (avctx->bits_per_coded_sample == 16)
> +         avctx->pix_fmt = AV_PIX_FMT_UYVY422;
> +      else if (avctx->bits_per_coded_sample == 20)
> +         avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
> +      else
> +         return -1;
> +   } else {
> +      return -1;
> +   }
> +
> +    return 0;
> +}
> +
> +static av_cold int vrawdepay_close_decoder(AVCodecContext *avctx)
> +{
> +   return 0;
> +}
> +
> +static int vrawdepay_decode(AVCodecContext *avctx, void *data, int
> *got_frame,
> +                      AVPacket *avpkt)
> +{
> +   const uint8_t *buf = avpkt->data;
> +   int buf_size = avpkt->size;
> +   AVFrame *frame = data;
> +   int res;
> +
> +   frame->pict_type = AV_PICTURE_TYPE_I;
> +   frame->key_frame = 1;
> +
> +   if (avctx->bits_per_coded_sample == 16) {
> +      /* there is no need to copy as the data already match
> +       * a known pixel format */
> +      frame->buf[0] = av_buffer_ref(avpkt->buf);
> +
> +      if ((res = av_image_fill_arrays(frame->data, frame->linesize, buf,
> +                  avctx->pix_fmt, avctx->width, avctx->height, 1)) < 0) {
> +         av_buffer_unref(&frame->buf[0]);
> +         return res;
> +      }
> +   } else {
> +      GetBitContext bc;
> +      uint16_t *y, *u, *v;
> +      int i;
> +
> +      res = ff_get_buffer(avctx, frame, 0);
> +      if (res < 0)
> +         return res;
> +      y = (uint16_t*)frame->data[0];
> +      u = (uint16_t*)frame->data[1];
> +      v = (uint16_t*)frame->data[2];
> +
> +      res = init_get_bits(&bc, buf, avctx->width * avctx->height * 20);
> +      for (i = 0; i < (avctx->width * avctx->height) / 2; i++) {
> +         *u++ = get_bits(&bc, 10);
> +         *y++ = get_bits(&bc, 10);
> +         *v++ = get_bits(&bc, 10);
> +         *y++ = get_bits(&bc, 10);
> +      }
> +   }
> +
> +   *got_frame = 1;
> +   return buf_size;
> +
> +}
> +
> +AVCodec ff_vrawdepay_decoder = {
> +    .name   = "vrawdepay",
> +    .long_name = NULL_IF_CONFIG_SMALL("RFC4175 codec"),
> +    .type = AVMEDIA_TYPE_VIDEO,
> +    .id = AV_CODEC_ID_VRAWDEPAY,
> +    .init = vrawdepay_init_decoder,
> +    .close = vrawdepay_close_decoder,
> +    .decode = vrawdepay_decode,
> +};
> --
> 2.11.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

No, do this in libavfilter and do not introduce another useless pseudo codec


More information about the ffmpeg-devel mailing list