19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "libavutil/parseutils.h"
23
#include "libavutil/pixdesc.h"
24
#include "libavutil/opt.h"
22
26
#include "avformat.h"
28
typedef struct RawVideoDemuxerContext {
29
const AVClass *class; /**< Class for private options. */
30
char *video_size; /**< String describing video size, set by a private option. */
31
char *pixel_format; /**< Set by a private option. */
32
char *framerate; /**< String describing framerate, set by a private option. */
33
} RawVideoDemuxerContext;
36
static int rawvideo_read_header(AVFormatContext *ctx)
38
RawVideoDemuxerContext *s = ctx->priv_data;
39
int width = 0, height = 0, ret = 0;
40
enum AVPixelFormat pix_fmt;
44
st = avformat_new_stream(ctx, NULL);
46
return AVERROR(ENOMEM);
48
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
50
st->codec->codec_id = ctx->iformat->raw_codec_id;
53
(ret = av_parse_video_size(&width, &height, s->video_size)) < 0) {
54
av_log(ctx, AV_LOG_ERROR, "Couldn't parse video size.\n");
58
if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
59
av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n",
61
return AVERROR(EINVAL);
64
if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) {
65
av_log(ctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n",
70
avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
72
st->codec->width = width;
73
st->codec->height = height;
74
st->codec->pix_fmt = pix_fmt;
25
80
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
34
89
if (packet_size < 0)
37
ret= av_get_packet(s->pb, pkt, packet_size);
39
pkt->dts= pkt->pos / packet_size;
92
ret = av_get_packet(s->pb, pkt, packet_size);
93
pkt->pts = pkt->dts = pkt->pos / packet_size;
41
95
pkt->stream_index = 0;
47
#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
101
#define OFFSET(x) offsetof(RawVideoDemuxerContext, x)
48
102
#define DEC AV_OPT_FLAG_DECODING_PARAM
49
103
static const AVOption rawvideo_options[] = {
50
104
{ "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
63
117
AVInputFormat ff_rawvideo_demuxer = {
64
118
.name = "rawvideo",
65
.long_name = NULL_IF_CONFIG_SMALL("raw video format"),
66
.priv_data_size = sizeof(FFRawVideoDemuxerContext),
67
.read_header = ff_raw_read_header,
119
.long_name = NULL_IF_CONFIG_SMALL("raw video"),
120
.priv_data_size = sizeof(RawVideoDemuxerContext),
121
.read_header = rawvideo_read_header,
68
122
.read_packet = rawvideo_read_packet,
69
.flags= AVFMT_GENERIC_INDEX,
70
.extensions = "yuv,cif,qcif,rgb",
71
.value = CODEC_ID_RAWVIDEO,
72
.priv_class = &rawvideo_demuxer_class,
123
.flags = AVFMT_GENERIC_INDEX,
124
.extensions = "yuv,cif,qcif,rgb",
125
.raw_codec_id = AV_CODEC_ID_RAWVIDEO,
126
.priv_class = &rawvideo_demuxer_class,