rawvideodec.c
Go to the documentation of this file.
1 /*
2  * RAW video demuxer
3  * Copyright (c) 2001 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #include "libavutil/parseutils.h"
23 #include "libavutil/pixdesc.h"
24 #include "libavutil/opt.h"
25 #include "internal.h"
26 #include "avformat.h"
27 
28 typedef struct RawVideoDemuxerContext {
29  const AVClass *class; /**< Class for private options. */
30  int width, height; /**< Integers describing video size, set by a private option. */
31  char *pixel_format; /**< Set by a private option. */
32  AVRational framerate; /**< AVRational describing framerate, set by a private option. */
34 
35 
37 {
40  AVStream *st;
41 
42  st = avformat_new_stream(ctx, NULL);
43  if (!st)
44  return AVERROR(ENOMEM);
45 
47 
48  st->codec->codec_id = ctx->iformat->raw_codec_id;
49 
50  if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
51  av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n",
52  s->pixel_format);
53  return AVERROR(EINVAL);
54  }
55 
57 
58  st->codec->width = s->width;
59  st->codec->height = s->height;
60  st->codec->pix_fmt = pix_fmt;
62  (AVRational){8,1}, st->time_base);
63 
64  return 0;
65 }
66 
67 
69 {
70  int packet_size, ret, width, height;
71  AVStream *st = s->streams[0];
72 
73  width = st->codec->width;
74  height = st->codec->height;
75 
76  packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
77  if (packet_size < 0)
78  return -1;
79 
80  ret = av_get_packet(s->pb, pkt, packet_size);
81  pkt->pts = pkt->dts = pkt->pos / packet_size;
82 
83  pkt->stream_index = 0;
84  if (ret < 0)
85  return ret;
86  return 0;
87 }
88 
89 #define OFFSET(x) offsetof(RawVideoDemuxerContext, x)
90 #define DEC AV_OPT_FLAG_DECODING_PARAM
91 static const AVOption rawvideo_options[] = {
92  { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
93  { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
94  { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC },
95  { NULL },
96 };
97 
99  .class_name = "rawvideo demuxer",
100  .item_name = av_default_item_name,
101  .option = rawvideo_options,
102  .version = LIBAVUTIL_VERSION_INT,
103 };
104 
106  .name = "rawvideo",
107  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
108  .priv_data_size = sizeof(RawVideoDemuxerContext),
112  .extensions = "yuv,cif,qcif,rgb",
113  .raw_codec_id = AV_CODEC_ID_RAWVIDEO,
114  .priv_class = &rawvideo_demuxer_class,
115 };
const char * s
Definition: avisynth_c.h:668
AVOption.
Definition: opt.h:251
av_default_item_name
int64_t pos
byte position in stream, -1 if unknown
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
int num
numerator
Definition: rational.h:44
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static const AVOption rawvideo_options[]
Definition: rawvideodec.c:91
static const AVClass rawvideo_demuxer_class
Definition: rawvideodec.c:98
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawvideodec.c:68
Format I/O context.
Definition: avformat.h:944
#define OFFSET(x)
Definition: rawvideodec.c:89
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
AVOptions.
static AVPacket pkt
Definition: demuxing.c:56
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
AVRational framerate
AVRational describing framerate, set by a private option.
Definition: rawvideodec.c:32
enum AVPixelFormat pix_fmt
Definition: v4l.c:63
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
int bit_rate
the average bitrate
ret
Definition: avfilter.c:821
int width
picture width / height.
static int rawvideo_read_header(AVFormatContext *ctx)
Definition: rawvideodec.c:36
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
AVIOContext * pb
I/O context.
Definition: avformat.h:977
int height
Integers describing video size, set by a private option.
Definition: rawvideodec.c:30
AVInputFormat ff_rawvideo_demuxer
Definition: rawvideodec.c:105
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
Describe the class of an AVClass context structure.
Definition: log.h:50
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:353
rational number numerator/denominator
Definition: rational.h:43
offset must point to AVRational
Definition: opt.h:233
char * pixel_format
Set by a private option.
Definition: rawvideodec.c:31
struct RawVideoDemuxerContext RawVideoDemuxerContext
offset must point to two consecutive integers
Definition: opt.h:230
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
misc parsing utilities
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:500
static int flags
Definition: cpu.c:23
Main libavformat public API header.
int den
denominator
Definition: rational.h:45
struct AVInputFormat * iformat
Can only be iformat or oformat, not both at the same time.
Definition: avformat.h:957
#define DEC
Definition: rawvideodec.c:90
void * priv_data
Format private data.
Definition: avformat.h:964
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
Definition: avpicture.c:49
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:1712
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...