FFmpeg: libavformat/rawvideodec.c Source File

FFmpeg
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/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"
28 
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. */
34 } RawVideoDemuxerContext;
35 
36 
37  static int rawvideo_read_header(AVFormatContext *ctx)
38 {
39  RawVideoDemuxerContext *s = ctx->priv_data;
40  enum AVPixelFormat pix_fmt;
41  AVStream *st;
42  int packet_size;
43 
44  st = avformat_new_stream(ctx, NULL);
45  if (!st)
46  return AVERROR(ENOMEM);
47 
48  st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
49 
50  st->codec->codec_id = ctx->iformat->raw_codec_id;
51 
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  }
57 
58  avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
59 
60  st->codec->width = s->width;
61  st->codec->height = s->height;
62  st->codec->pix_fmt = pix_fmt;
63  packet_size = av_image_get_buffer_size(st->codec->pix_fmt, s->width, s->height, 1);
64  if (packet_size < 0)
65  return packet_size;
66  ctx->packet_size = packet_size;
67  st->codec->bit_rate = av_rescale_q(ctx->packet_size,
68  (AVRational){8,1}, st->time_base);
69 
70  return 0;
71 }
72 
73 
74  static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
75 {
76  int ret;
77 
78  ret = av_get_packet(s->pb, pkt, s->packet_size);
79  pkt->pts = pkt->dts = pkt->pos / s->packet_size;
80 
81  pkt->stream_index = 0;
82  if (ret < 0)
83  return ret;
84  return 0;
85 }
86 
87  #define OFFSET(x) offsetof(RawVideoDemuxerContext, x)
88  #define DEC AV_OPT_FLAG_DECODING_PARAM
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, 0, DEC },
93  { NULL },
94 };
95 
96  static const AVClass rawvideo_demuxer_class = {
97  .class_name = "rawvideo demuxer",
98  .item_name = av_default_item_name,
99  .option = rawvideo_options,
100  .version = LIBAVUTIL_VERSION_INT,
101 };
102 
103  AVInputFormat ff_rawvideo_demuxer = {
104  .name = "rawvideo",
105  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
106  .priv_data_size = sizeof(RawVideoDemuxerContext),
107  .read_header = rawvideo_read_header,
108  .read_packet = rawvideo_read_packet,
109  .flags = AVFMT_GENERIC_INDEX,
110  .extensions = "yuv,cif,qcif,rgb",
111  .raw_codec_id = AV_CODEC_ID_RAWVIDEO,
112  .priv_class = &rawvideo_demuxer_class,
113 };
AVFormatContext::packet_size
unsigned int packet_size
Definition: avformat.h:1418
NULL
#define NULL
Definition: coverity.c:32
s
const char * s
Definition: avisynth_c.h:631
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:40
AVOption
AVOption.
Definition: opt.h:245
ctx
AVFormatContext * ctx
Definition: movenc-test.c:48
imgutils.h
misc image utilities
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1597
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1487
avpriv_set_pts_info
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:4149
AVRational::num
int num
numerator
Definition: rational.h:44
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1752
rawvideo_options
static const AVOption rawvideo_options[]
Definition: rawvideodec.c:89
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
rawvideo_demuxer_class
static const AVClass rawvideo_demuxer_class
Definition: rawvideodec.c:96
rawvideo_read_packet
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawvideodec.c:74
AVFormatContext
Format I/O context.
Definition: avformat.h:1314
OFFSET
#define OFFSET(x)
Definition: rawvideodec.c:87
AVClass::class_name
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
opt.h
AVOptions.
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3805
RawVideoDemuxerContext::framerate
AVRational framerate
AVRational describing framerate, set by a private option.
Definition: rawvideodec.c:33
av_get_packet
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:252
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
av_rescale_q
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
av_image_get_buffer_size
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:361
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_default_item_name
av_default_item_name
Definition: libopenh264enc.c:68
AVERROR
#define AVERROR(e)
Definition: error.h:43
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
AVStream::codec
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:896
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:1711
rawvideo_read_header
static int rawvideo_read_header(AVFormatContext *ctx)
Definition: rawvideodec.c:37
AVCodecContext::height
int height
Definition: avcodec.h:1711
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:638
AVStream
Stream structure.
Definition: avformat.h:877
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:1540
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:1549
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1356
RawVideoDemuxerContext::height
int height
Integers describing video size, set by a private option.
Definition: rawvideodec.c:31
ff_rawvideo_demuxer
AVInputFormat ff_rawvideo_demuxer
Definition: rawvideodec.c:103
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:486
AVRational
rational number numerator/denominator
Definition: rational.h:43
AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:235
RawVideoDemuxerContext::pixel_format
char * pixel_format
Set by a private option.
Definition: rawvideodec.c:32
AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:232
parseutils.h
misc parsing utilities
AVInputFormat::raw_codec_id
int raw_codec_id
Raw demuxers store their codec ID here.
Definition: avformat.h:707
flags
static int flags
Definition: cpu.c:47
avformat.h
Main libavformat public API header.
AVRational::den
int den
denominator
Definition: rational.h:45
AVFormatContext::iformat
struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1326
DEC
#define DEC
Definition: rawvideodec.c:88
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1342
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1466
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2090
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1469
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1444
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1460
width
static int width
Definition: demuxing_decoding.c:39

Generated on Mon Feb 15 2016 15:20:47 for FFmpeg by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /