From dd453f197c136aa6ee45bb1e9d2a1d65e69c9fcc Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Wed, 25 Jan 2012 19:46:57 +0000 Subject: [PATCH] r210, r10k and avrp encoder Signed-off-by: Paul B Mahol Signed-off-by: Michael Niedermayer --- Changelog | 3 +- doc/general.texi | 6 +-- libavcodec/Makefile | 3 ++ libavcodec/allcodecs.c | 6 +-- libavcodec/r210enc.c | 120 +++++++++++++++++++++++++++++++++++++++++ libavcodec/version.h | 2 +- 6 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 libavcodec/r210enc.c diff --git a/Changelog b/Changelog index 14e60b6b38..554a176c07 100644 --- a/Changelog +++ b/Changelog @@ -18,7 +18,7 @@ version next: - Automatic thread count based on detection number of (available) CPU cores - y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder - ffprobe -show_error option -- Avid 1:1 10-bit RGB Packer decoder +- Avid 1:1 10-bit RGB Packer codec - v308 Quicktime Uncompressed 4:4:4 encoder and decoder - yuv4 libquicktime packed 4:2:0 encoder and decoder - ffprobe -show_frames option @@ -28,6 +28,7 @@ version next: - optimized iMDCT transform on x86 using SSE for for mpegaudiodec - Improved PGS subtitle decoder - dumpgraph option to lavfi device +- r210 and r10k encoders version 0.9: diff --git a/doc/general.texi b/doc/general.texi index e4139c8a24..c3506efd93 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -440,7 +440,7 @@ following image formats are supported: @item Autodesk Animator Flic video @tab @tab X @item Autodesk RLE @tab @tab X @tab fourcc: AASC -@item Avid 1:1 10-bit RGB Packer @tab @tab X +@item Avid 1:1 10-bit RGB Packer @tab X @tab X @tab fourcc: AVrp @item AVS (Audio Video Standard) video @tab @tab X @tab Video encoding used by the Creature Shock game. @@ -577,8 +577,8 @@ following image formats are supported: @tab fourcc: 'smc ' @item QuickTime video (RPZA) @tab @tab X @tab fourcc: rpza -@item R10K AJA Kona 10-bit RGB Codec @tab @tab X -@item R210 Quicktime Uncompressed RGB 10-bit @tab @tab X +@item R10K AJA Kona 10-bit RGB Codec @tab X @tab X +@item R210 Quicktime Uncompressed RGB 10-bit @tab X @tab X @item Raw Video @tab X @tab X @item RealVideo 1.0 @tab X @tab X @item RealVideo 2.0 @tab X @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 2e8c908429..0e9034015d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -92,6 +92,7 @@ OBJS-$(CONFIG_ATRAC3_DECODER) += atrac3.o atrac.o OBJS-$(CONFIG_AURA_DECODER) += cyuv.o OBJS-$(CONFIG_AURA2_DECODER) += aura.o OBJS-$(CONFIG_AVRP_DECODER) += r210dec.o +OBJS-$(CONFIG_AVRP_ENCODER) += r210enc.o OBJS-$(CONFIG_AVS_DECODER) += avs.o OBJS-$(CONFIG_BETHSOFTVID_DECODER) += bethsoftvideo.o OBJS-$(CONFIG_BFI_DECODER) += bfi.o @@ -339,7 +340,9 @@ OBJS-$(CONFIG_QPEG_DECODER) += qpeg.o OBJS-$(CONFIG_QTRLE_DECODER) += qtrle.o OBJS-$(CONFIG_QTRLE_ENCODER) += qtrleenc.o OBJS-$(CONFIG_R10K_DECODER) += r210dec.o +OBJS-$(CONFIG_R10K_ENCODER) += r210enc.o OBJS-$(CONFIG_R210_DECODER) += r210dec.o +OBJS-$(CONFIG_R210_ENCODER) += r210enc.o OBJS-$(CONFIG_RA_144_DECODER) += ra144dec.o ra144.o celp_filters.o OBJS-$(CONFIG_RA_144_ENCODER) += ra144enc.o ra144.o celp_filters.o OBJS-$(CONFIG_RA_288_DECODER) += ra288.o celp_math.o celp_filters.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 164e8b373d..32f3f52942 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -79,7 +79,7 @@ void avcodec_register_all(void) REGISTER_ENCDEC (ASV2, asv2); REGISTER_DECODER (AURA, aura); REGISTER_DECODER (AURA2, aura2); - REGISTER_DECODER (AVRP, avrp); + REGISTER_ENCDEC (AVRP, avrp); REGISTER_DECODER (AVS, avs); REGISTER_DECODER (BETHSOFTVID, bethsoftvid); REGISTER_DECODER (BFI, bfi); @@ -184,8 +184,8 @@ void avcodec_register_all(void) REGISTER_DECODER (QDRAW, qdraw); REGISTER_DECODER (QPEG, qpeg); REGISTER_ENCDEC (QTRLE, qtrle); - REGISTER_DECODER (R10K, r10k); - REGISTER_DECODER (R210, r210); + REGISTER_ENCDEC (R10K, r10k); + REGISTER_ENCDEC (R210, r210); REGISTER_ENCDEC (RAWVIDEO, rawvideo); REGISTER_DECODER (RL2, rl2); REGISTER_ENCDEC (ROQ, roq); diff --git a/libavcodec/r210enc.c b/libavcodec/r210enc.c new file mode 100644 index 0000000000..cfe433e8ff --- /dev/null +++ b/libavcodec/r210enc.c @@ -0,0 +1,120 @@ +/* + * R210 encoder + * + * Copyright (c) 2012 Paul B Mahol + * + * 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 "avcodec.h" +#include "bytestream.h" + +static av_cold int encode_init(AVCodecContext *avctx) +{ + avctx->coded_frame = avcodec_alloc_frame(); + + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + + return 0; +} + +static int encode_frame(AVCodecContext *avctx, uint8_t *buf, + int buf_size, void *data) +{ + AVFrame *pic = data; + int i, j; + int aligned_width = FFALIGN(avctx->width, 64); + uint8_t *src_line; + uint8_t *dst = buf; + + if (buf_size < 4 * aligned_width * avctx->height) { + av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); + return AVERROR(ENOMEM); + } + + avctx->coded_frame->reference = 0; + avctx->coded_frame->key_frame = 1; + avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + src_line = pic->data[0]; + + for (i = 0; i < avctx->height; i++) { + uint16_t *src = (uint16_t *)src_line; + for (j = 0; j < avctx->width; j++) { + uint32_t pixel; + uint16_t r = *src++ >> 6; + uint16_t g = *src++ >> 6; + uint16_t b = *src++ >> 4; + if (avctx->codec_id == CODEC_ID_R210) + pixel = (r << 20) | (g << 10) | b >> 2; + else + pixel = (r << 22) | (g << 12) | b; + if (avctx->codec_id == CODEC_ID_AVRP) + bytestream_put_le32(&dst, pixel); + else + bytestream_put_be32(&dst, pixel); + } + dst += aligned_width - avctx->width; + src_line += pic->linesize[0]; + } + + return 4 * aligned_width * avctx->height; +} + +static av_cold int encode_close(AVCodecContext *avctx) +{ + av_freep(&avctx->coded_frame); + + return 0; +} + +#if CONFIG_R210_ENCODER +AVCodec ff_r210_encoder = { + .name = "r210", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_R210, + .init = encode_init, + .encode = encode_frame, + .close = encode_close, + .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"), +}; +#endif +#if CONFIG_R10K_ENCODER +AVCodec ff_r10k_encoder = { + .name = "r10k", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_R10K, + .init = encode_init, + .encode = encode_frame, + .close = encode_close, + .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"), +}; +#endif +#if CONFIG_AVRP_ENCODER +AVCodec ff_avrp_encoder = { + .name = "avrp", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_AVRP, + .init = encode_init, + .encode = encode_frame, + .close = encode_close, + .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"), +}; +#endif diff --git a/libavcodec/version.h b/libavcodec/version.h index f5d15667e0..d67ad2f5d2 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -21,7 +21,7 @@ #define AVCODEC_VERSION_H #define LIBAVCODEC_VERSION_MAJOR 53 -#define LIBAVCODEC_VERSION_MINOR 59 +#define LIBAVCODEC_VERSION_MINOR 60 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \