2 * Raw v210 video demuxer
3 * Copyright (c) 2015 Tiancheng "Timothy" Gu
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/imgutils.h"
23 #include "libavutil/parseutils.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/opt.h"
29 typedef struct V210DemuxerContext {
30 const AVClass *class; /**< Class for private options. */
31 int width, height; /**< Integers describing video size, set by a private option. */
32 AVRational framerate; /**< AVRational describing framerate, set by a private option. */
35 // v210 frame width is padded to multiples of 48
36 #define GET_PACKET_SIZE(w, h) (((w + 47) / 48) * 48 * h * 8 / 3)
38 static int v210_read_header(AVFormatContext *ctx)
40 V210DemuxerContext *s = ctx->priv_data;
43 st = avformat_new_stream(ctx, NULL);
45 return AVERROR(ENOMEM);
47 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
49 st->codec->codec_id = ctx->iformat->raw_codec_id;
51 avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
53 st->codec->width = s->width;
54 st->codec->height = s->height;
55 st->codec->pix_fmt = ctx->iformat->raw_codec_id == AV_CODEC_ID_V210 ?
56 AV_PIX_FMT_YUV422P10 : AV_PIX_FMT_YUV422P16;
57 st->codec->bit_rate = av_rescale_q(GET_PACKET_SIZE(s->width, s->height),
58 (AVRational){8,1}, st->time_base);
64 static int v210_read_packet(AVFormatContext *s, AVPacket *pkt)
66 int packet_size, ret, width, height;
67 AVStream *st = s->streams[0];
69 width = st->codec->width;
70 height = st->codec->height;
72 packet_size = GET_PACKET_SIZE(width, height);
76 ret = av_get_packet(s->pb, pkt, packet_size);
77 pkt->pts = pkt->dts = pkt->pos / packet_size;
79 pkt->stream_index = 0;
85 #define OFFSET(x) offsetof(V210DemuxerContext, x)
86 #define DEC AV_OPT_FLAG_DECODING_PARAM
87 static const AVOption v210_options[] = {
88 { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
89 { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC },
93 #if CONFIG_V210_DEMUXER
94 static const AVClass v210_demuxer_class = {
95 .class_name = "v210 demuxer",
96 .item_name = av_default_item_name,
97 .option = v210_options,
98 .version = LIBAVUTIL_VERSION_INT,
101 AVInputFormat ff_v210_demuxer = {
103 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
104 .priv_data_size = sizeof(V210DemuxerContext),
105 .read_header = v210_read_header,
106 .read_packet = v210_read_packet,
107 .flags = AVFMT_GENERIC_INDEX,
108 .extensions = "v210",
109 .raw_codec_id = AV_CODEC_ID_V210,
110 .priv_class = &v210_demuxer_class,
112 #endif // CONFIG_V210_DEMUXER
114 #if CONFIG_V210X_DEMUXER
115 static const AVClass v210x_demuxer_class = {
116 .class_name = "v210x demuxer",
117 .item_name = av_default_item_name,
118 .option = v210_options,
119 .version = LIBAVUTIL_VERSION_INT,
122 AVInputFormat ff_v210x_demuxer = {
124 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
125 .priv_data_size = sizeof(V210DemuxerContext),
126 .read_header = v210_read_header,
127 .read_packet = v210_read_packet,
128 .flags = AVFMT_GENERIC_INDEX,
129 .extensions = "yuv10",
130 .raw_codec_id = AV_CODEC_ID_V210X,
131 .priv_class = &v210x_demuxer_class,
133 #endif // CONFIG_V210X_DEMUXER