[FFmpeg-devel] [PATCH]Support decoding Avid 1:1 10-bit RGB Packer
Carl Eugen Hoyos
cehoyos at ag.or.at
Wed Jan 4 01:36:32 CET 2012
Hi!
Attached patch allows to decode the one AVrp sample I have.
Please review, Carl Eugen
-------------- next part --------------
diff --git a/Changelog b/Changelog
index 09e44d4..e1b2ca2 100644
--- a/Changelog
+++ b/Changelog
@@ -15,6 +15,7 @@ version next:
- amerge audio filter
- Automatic thread count based on detection number of (available) CPU cores
- y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder
+- Avid 1:1 10-bit RGB Packer decoder
version 0.9:
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c3901ef..463e10b 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -91,6 +91,7 @@ OBJS-$(CONFIG_ATRAC1_DECODER) += atrac1.o atrac.o
OBJS-$(CONFIG_ATRAC3_DECODER) += atrac3.o atrac.o
OBJS-$(CONFIG_AURA_DECODER) += cyuv.o
OBJS-$(CONFIG_AURA2_DECODER) += aura.o
+OBJS-$(CONFIG_AVRP_DECODER) += avrpdec.o
OBJS-$(CONFIG_AVS_DECODER) += avs.o
OBJS-$(CONFIG_BETHSOFTVID_DECODER) += bethsoftvideo.o
OBJS-$(CONFIG_BFI_DECODER) += bfi.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b96339d..ec9f928 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -79,6 +79,7 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (ASV2, asv2);
REGISTER_DECODER (AURA, aura);
REGISTER_DECODER (AURA2, aura2);
+ REGISTER_DECODER (AVRP, avrp);
REGISTER_DECODER (AVS, avs);
REGISTER_DECODER (BETHSOFTVID, bethsoftvid);
REGISTER_DECODER (BFI, bfi);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index bb1e239..11b4ae0 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -258,6 +258,7 @@ enum CodecID {
CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
CODEC_ID_UTVIDEO = 0x800,
CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'),
+ CODEC_ID_AVRP = MKBETAG('A','V','R','P'),
CODEC_ID_G2M = MKBETAG( 0 ,'G','2','M'),
diff --git a/libavcodec/avrpdec.c b/libavcodec/avrpdec.c
index e69de29..5fcd6d8 100644
--- a/libavcodec/avrpdec.c
+++ b/libavcodec/avrpdec.c
@@ -0,0 +1,105 @@
+/*
+ * Avid 1:1 10-bit RGB Packer decoder
+ *
+ * Copyright (c) 2012 Carl Eugen Hoyos
+ *
+ * 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
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avcodec.h"
+
+static av_cold int avrp_decode_init(AVCodecContext *avctx)
+{
+ avctx->pix_fmt = PIX_FMT_RGB48;
+ avctx->bits_per_raw_sample = 10;
+
+ avctx->coded_frame = avcodec_alloc_frame();
+
+ if (!avctx->coded_frame) {
+ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
+ return AVERROR(ENOMEM);
+ }
+
+ return 0;
+}
+
+static int avrp_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *avpkt)
+{
+ AVFrame *pic = avctx->coded_frame;
+ uint32_t *src = (uint32_t *)avpkt->data, val;
+ uint16_t *dst;
+ int i, j;
+
+ if (pic->data[0])
+ avctx->release_buffer(avctx, pic);
+
+ if (avpkt->size < 4 * avctx->height * avctx->width) {
+ av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
+ return AVERROR(EINVAL);
+ }
+
+ pic->reference = 0;
+
+ if (avctx->get_buffer(avctx, pic) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
+ return AVERROR(ENOMEM);
+ }
+
+ pic->key_frame = 1;
+ pic->pict_type = AV_PICTURE_TYPE_I;
+
+ dst = (uint16_t *)pic->data[0];
+
+ for (i = 0; i < avctx->height; i++) {
+ for (j = 0; j < avctx->width; j++) {
+ val = AV_RL32(src++);
+
+ dst[3 * j] = val >> 16 & 0xFFC0 | val >> 26;
+ dst[3 * j + 1] = val >> 6 & 0xFFC0 | val >> 16 & 0x3F;
+ dst[3 * j + 2] = val << 4 & 0xFFC0 | val >> 6 & 0x3F;
+ }
+ dst += pic->linesize[0] >> 1;
+ }
+
+ *data_size = sizeof(AVFrame);
+ *(AVFrame *)data = *pic;
+
+ return avpkt->size;
+}
+
+static av_cold int avrp_decode_close(AVCodecContext *avctx)
+{
+ if (avctx->coded_frame->data[0])
+ avctx->release_buffer(avctx, avctx->coded_frame);
+
+ av_freep(&avctx->coded_frame);
+
+ return 0;
+}
+
+AVCodec ff_avrp_decoder = {
+ .name = "avrp",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_AVRP,
+ .init = avrp_decode_init,
+ .decode = avrp_decode_frame,
+ .close = avrp_decode_close,
+ .capabilities = CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"),
+};
diff --git a/libavformat/isom.c b/libavformat/isom.c
index 7cadcef..47f980c 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -215,6 +215,7 @@ const AVCodecTag codec_movvideo_tags[] = {
{ CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'u', 'p') },
{ CODEC_ID_SGI, MKTAG('s', 'g', 'i', ' ') }, /* SGI */
{ CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') }, /* DPX */
+ { CODEC_ID_AVRP, MKTAG('A', 'V', 'r', 'p') }, /* Avid 1:1 10-bit RGB Packer */
{ CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'h') }, /* Apple ProRes 422 High Quality */
{ CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'n') }, /* Apple ProRes 422 Standard Definition */
More information about the ffmpeg-devel
mailing list