[FFmpeg-devel] [PATCH] v210 decoder
Reimar Döffinger
Reimar.Doeffinger
Tue Feb 17 20:39:27 CET 2009
On Tue, Feb 17, 2009 at 11:21:31AM -0800, Baptiste Coudurier wrote:
> On 2/17/2009 9:26 AM, Reimar D?ffinger wrote:
> > this is a decoder for
> > http://samples.mplayerhq.hu/V-codecs/v210/v210_720p.avi
> > it is not actually a proper codec, it is just little-endian
> > UYVY with 10 bits per component and aligned to 32 bit every 3
> > components.
>
> Interesting, 'v210' is a registered Quicktime fourcc.
> http://developer.apple.com/quicktime/icefloe/dispatch019.html
>
> I suspect someone stream copied into avi.
Hm, Google seems not so good at finding stuff in the QuickTime
documentation.
I added this link to the multimedia wiki and fixed the line length
rounding.
Also attaching a fixed patch (also including the MPlayer etc/codecs.conf
part), just in case someone in the future stumbles over this.
Hope you don't mind that I use this list as backup storage/publishing
method :-)
-------------- next part --------------
Index: libavformat/riff.c
===================================================================
--- libavformat/riff.c (revision 17395)
+++ libavformat/riff.c (working copy)
@@ -200,6 +200,7 @@
{ CODEC_ID_RPZA, MKTAG('R', 'P', 'Z', 'A') },
{ CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') },
{ CODEC_ID_SP5X, MKTAG('S', 'P', '5', '4') },
+ { CODEC_ID_V210, MKTAG('v', '2', '1', '0') },
{ CODEC_ID_NONE, 0 }
};
Index: etc/codecs.conf
===================================================================
--- etc/codecs.conf (revision 28636)
+++ etc/codecs.conf (working copy)
@@ -2324,6 +2324,14 @@
dll "dnxhd"
out 422P
+videocodec ffv210
+ info "FFmpeg v210"
+ status working
+ fourcc v210
+ driver ffmpeg
+ dll "v210"
+ out UYVY
+
; quicktime codecs:
videocodec qt3ivx
Index: libavcodec/v210.c
===================================================================
--- libavcodec/v210.c (revision 0)
+++ libavcodec/v210.c (revision 0)
@@ -0,0 +1,109 @@
+/*
+ * v210 (10 bit 4:2:2 YUV) decoder
+ * Copyright (c) 2009 Reimar Doeffinger
+ *
+ * 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 int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
+ const uint8_t *buf, int buf_size) {
+ int x, y;
+ AVFrame *picture = data;
+ AVFrame *pic = avctx->priv_data;
+ uint8_t *dst_line = pic->data[0];
+ const uint8_t *src_line = buf;
+ int src_linesize = (avctx->width + 5) / 6 * 16;
+ src_linesize = (src_linesize + 127) & ~127;
+ if (buf_size < src_linesize * avctx->height) {
+ av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
+ return -1;
+ }
+
+ for (y = 0; y < avctx->height; y++) {
+ const uint8_t *src = src_line;
+ uint64_t val;
+ for (x = 0; x < avctx->width - 5; x += 6) {
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 0] = val >> 2;
+ dst_line[2 * x + 1] = val >> 12;
+ dst_line[2 * x + 2] = val >> 22;
+ dst_line[2 * x + 3] = val >> 34;
+ dst_line[2 * x + 4] = val >> 44;
+ dst_line[2 * x + 5] = val >> 54;
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 6] = val >> 2;
+ dst_line[2 * x + 7] = val >> 12;
+ dst_line[2 * x + 8] = val >> 22;
+ dst_line[2 * x + 9] = val >> 34;
+ dst_line[2 * x + 10] = val >> 44;
+ dst_line[2 * x + 11] = val >> 54;
+ }
+ if (x < avctx->width - 1) {
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 0] = val >> 2;
+ dst_line[2 * x + 1] = val >> 12;
+ dst_line[2 * x + 2] = val >> 22;
+ dst_line[2 * x + 3] = val >> 34;
+ }
+ if (x < avctx->width - 3) {
+ dst_line[2 * x + 4] = val >> 44;
+ dst_line[2 * x + 5] = val >> 54;
+ val = bytestream_get_le64(&src);
+ dst_line[2 * x + 6] = val >> 2;
+ dst_line[2 * x + 7] = val >> 12;
+ }
+ src_line += src_linesize;
+ dst_line += pic->linesize[0];
+ }
+
+ *picture = *pic;
+ *data_size = sizeof(AVFrame);
+ return src_line - buf;
+}
+
+static av_cold int decode_init(AVCodecContext *avctx) {
+ AVFrame *pic = avctx->priv_data;
+ if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0)
+ return 1;
+ avctx->pix_fmt = PIX_FMT_UYVY422;
+ if (avctx->get_buffer(avctx, pic) < 0)
+ return 1;
+ pic->pict_type = FF_I_TYPE;
+ pic->key_frame = 1;
+ return 0;
+}
+
+static av_cold int decode_end(AVCodecContext *avctx) {
+ avctx->release_buffer(avctx, avctx->priv_data);
+ return 0;
+}
+
+AVCodec v210_decoder = {
+ "v210",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_V210,
+ sizeof(AVFrame),
+ decode_init,
+ NULL,
+ decode_end,
+ decode_frame,
+ CODEC_CAP_DR1,
+ .long_name = NULL_IF_CONFIG_SMALL("v210 10 bit 4:2:2 YUV"),
+};
+
Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile (revision 17395)
+++ libavcodec/Makefile (working copy)
@@ -219,6 +219,7 @@
OBJS-$(CONFIG_TTA_DECODER) += tta.o
OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o
OBJS-$(CONFIG_ULTI_DECODER) += ulti.o
+OBJS-$(CONFIG_V210_DECODER) += v210.o
OBJS-$(CONFIG_VB_DECODER) += vb.o
OBJS-$(CONFIG_VC1_DECODER) += vc1.o vc1data.o vc1dsp.o msmpeg4data.o h263dec.o h263.o intrax8.o intrax8dsp.o error_resilience.o mpegvideo.o
OBJS-$(CONFIG_VC1_VDPAU_DECODER) += vdpau.o vc1.o vc1data.o vc1dsp.o msmpeg4data.o h263dec.o h263.o intrax8.o intrax8dsp.o error_resilience.o mpegvideo.o
Index: libavcodec/allcodecs.c
===================================================================
--- libavcodec/allcodecs.c (revision 17395)
+++ libavcodec/allcodecs.c (working copy)
@@ -156,6 +156,7 @@
REGISTER_DECODER (TSCC, tscc);
REGISTER_DECODER (TXD, txd);
REGISTER_DECODER (ULTI, ulti);
+ REGISTER_DECODER (V210, v210);
REGISTER_DECODER (VB, vb);
REGISTER_DECODER (VC1, vc1);
REGISTER_DECODER (VC1_VDPAU, vc1_vdpau);
Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h (revision 17395)
+++ libavcodec/avcodec.h (working copy)
@@ -191,6 +191,7 @@
CODEC_ID_TGV,
CODEC_ID_TGQ,
CODEC_ID_TQI,
+ CODEC_ID_V210,
/* various PCM "codecs" */
CODEC_ID_PCM_S16LE= 0x10000,
More information about the ffmpeg-devel
mailing list