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;
44 st = avformat_new_stream(ctx, NULL);
46 return AVERROR(ENOMEM);
48 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
50 st->codecpar->codec_id = ctx->iformat->raw_codec_id;
52 avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
54 ret = av_image_check_size(s->width, s->height, 0, ctx);
57 st->codecpar->width = s->width;
58 st->codecpar->height = s->height;
59 st->codecpar->format = ctx->iformat->raw_codec_id == AV_CODEC_ID_V210 ?
60 AV_PIX_FMT_YUV422P10 : AV_PIX_FMT_YUV422P16;
61 ctx->packet_size = GET_PACKET_SIZE(s->width, s->height);
62 st->codecpar->bit_rate = av_rescale_q(ctx->packet_size,
63 (AVRational){8,1}, st->time_base);
69 static int v210_read_packet(AVFormatContext *s, AVPacket *pkt)
73 ret = av_get_packet(s->pb, pkt, s->packet_size);
74 pkt->pts = pkt->dts = pkt->pos / s->packet_size;
76 pkt->stream_index = 0;
82 #define OFFSET(x) offsetof(V210DemuxerContext, x)
83 #define DEC AV_OPT_FLAG_DECODING_PARAM
84 static const AVOption v210_options[] = {
85 { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
86 { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
90 #if CONFIG_V210_DEMUXER
91 static const AVClass v210_demuxer_class = {
92 .class_name = "v210 demuxer",
93 .item_name = av_default_item_name,
94 .option = v210_options,
95 .version = LIBAVUTIL_VERSION_INT,
98 AVInputFormat ff_v210_demuxer = {
100 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
101 .priv_data_size = sizeof(V210DemuxerContext),
102 .read_header = v210_read_header,
103 .read_packet = v210_read_packet,
104 .flags = AVFMT_GENERIC_INDEX,
105 .extensions = "v210",
106 .raw_codec_id = AV_CODEC_ID_V210,
107 .priv_class = &v210_demuxer_class,
109 #endif // CONFIG_V210_DEMUXER
111 #if CONFIG_V210X_DEMUXER
112 static const AVClass v210x_demuxer_class = {
113 .class_name = "v210x demuxer",
114 .item_name = av_default_item_name,
115 .option = v210_options,
116 .version = LIBAVUTIL_VERSION_INT,
119 AVInputFormat ff_v210x_demuxer = {
121 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
122 .priv_data_size = sizeof(V210DemuxerContext),
123 .read_header = v210_read_header,
124 .read_packet = v210_read_packet,
125 .flags = AVFMT_GENERIC_INDEX,
126 .extensions = "yuv10",
127 .raw_codec_id = AV_CODEC_ID_V210X,
128 .priv_class = &v210x_demuxer_class,
130 #endif // CONFIG_V210X_DEMUXER