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
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  */
22 #include "libavutil/imgutils.h"
23 #include "libavutil/parseutils.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/opt.h"
26 #include "internal.h"
27 #include "avformat.h"
29 typedef struct RawVideoDemuxerContext {
30  const AVClass *class; /**< Class for private options. */
31  int width, height; /**< Integers describing video size, set by a private option. */
32  char *pixel_format; /**< Set by a private option. */
33  AVRational framerate; /**< AVRational describing framerate, set by a private option. */
38 {
41  AVStream *st;
42  int packet_size;
44  st = avformat_new_stream(ctx, NULL);
45  if (!st)
46  return AVERROR(ENOMEM);
52  if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
53  av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n",
54  s->pixel_format);
55  return AVERROR(EINVAL);
56  }
60  st->codecpar->width = s->width;
61  st->codecpar->height = s->height;
62  st->codecpar->format = pix_fmt;
63  packet_size = av_image_get_buffer_size(st->codecpar->format, s->width, s->height, 1);
64  if (packet_size < 0)
65  return packet_size;
66  ctx->packet_size = packet_size;
68  (AVRational){8,1}, st->time_base);
70  return 0;
71 }
75 {
76  int ret;
78  ret = av_get_packet(s->pb, pkt, s->packet_size);
79  pkt->pts = pkt->dts = pkt->pos / s->packet_size;
81  pkt->stream_index = 0;
82  if (ret < 0)
83  return ret;
84  return 0;
85 }
87 #define OFFSET(x) offsetof(RawVideoDemuxerContext, x)
89 static const AVOption rawvideo_options[] = {
90  { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
91  { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
92  { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC },
93  { NULL },
94 };
97  .class_name = "rawvideo demuxer",
98  .item_name = av_default_item_name,
99  .option = rawvideo_options,
100  .version = LIBAVUTIL_VERSION_INT,
101 };
104  .name = "rawvideo",
105  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
106  .priv_data_size = sizeof(RawVideoDemuxerContext),
110  .extensions = "yuv,cif,qcif,rgb",
111  .raw_codec_id = AV_CODEC_ID_RAWVIDEO,
112  .priv_class = &rawvideo_demuxer_class,
113 };
unsigned int packet_size
Definition: avformat.h:1371
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat pix_fmt
Definition: opt.h:248
misc image utilities
Definition: version.h:85
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:389
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.
Definition: utils.c:4999
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
int num
Definition: rational.h:59
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
static const AVOption rawvideo_options[]
Definition: rawvideodec.c:89
static const AVClass rawvideo_demuxer_class
Definition: rawvideodec.c:96
AVPacket * pkt
Definition: movenc.c:59
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawvideodec.c:74
Format I/O context.
Definition: avformat.h:1247
#define OFFSET(x)
Definition: rawvideodec.c:87
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:72
int width
Video only.
Definition: codec_par.h:126
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4553
AVRational framerate
AVRational describing framerate, set by a private option.
Definition: rawvideodec.c:33
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.
Definition: utils.c:310
#define av_log(a,...)
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:89
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
Definition: imgutils.c:466
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:117
ff_const59 struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1259
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
static int rawvideo_read_header(AVFormatContext *ctx)
Definition: rawvideodec.c:37
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
Stream structure.
Definition: avformat.h:884
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVIOContext * pb
I/O context.
Definition: avformat.h:1289
int height
Integers describing video size, set by a private option.
Definition: rawvideodec.c:31
AVInputFormat ff_rawvideo_demuxer
Definition: rawvideodec.c:103
Describe the class of an AVClass context structure.
Definition: log.h:67
Use generic index building code.
Definition: avformat.h:463
Rational number (pair of numerator and denominator).
Definition: rational.h:58
offset must point to AVRational
Definition: opt.h:238
char * pixel_format
Set by a private option.
Definition: rawvideodec.c:32
offset must point to two consecutive integers
Definition: opt.h:235
misc parsing utilities
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:702
#define flags(name, subs,...)
Definition: cbs_av1.c:561
Main libavformat public API header.
int den
Definition: rational.h:60
#define DEC
Definition: rawvideodec.c:88
void * priv_data
Format private data.
Definition: avformat.h:1275
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:368
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:654
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1049
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2501
int stream_index
Definition: packet.h:371
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:913
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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.Frame references ownership and permissions
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: packet.h:346
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362