8
#define LIBAVFORMAT_BUILD 4608
28
#define LIBAVFORMAT_VERSION_INT ((51<<16)+(10<<8)+0)
29
#define LIBAVFORMAT_VERSION 51.10.0
30
#define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
10
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
11
#define LIBAVFORMAT_VERSION FFMPEG_VERSION
12
#define LIBAVFORMAT_IDENT "FFmpeg" FFMPEG_VERSION "b" AV_STRINGIFY(LIBAVFORMAT_BUILD)
32
#define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
35
#include <stdio.h> /* FILE */
16
36
#include "avcodec.h"
20
40
/* packet functions */
23
#define MAXINT64 int64_t_C(0x7fffffffffffffff)
27
#define MININT64 int64_t_C(0x8000000000000000)
30
#define AV_NOPTS_VALUE MININT64
31
#define AV_TIME_BASE 1000000
33
42
typedef struct AVPacket {
34
int64_t pts; /* presentation time stamp in stream units (set av_set_pts_info) */
43
int64_t pts; ///< presentation time stamp in time_base units
44
int64_t dts; ///< decompression time stamp in time_base units
49
int duration; ///< presentation duration in time_base units (0 if not available)
40
50
void (*destruct)(struct AVPacket *);
52
int64_t pos; ///< byte position in stream, -1 if unknown
43
54
#define PKT_FLAG_KEY 0x0001
56
void av_destruct_packet_nofree(AVPacket *pkt);
57
void av_destruct_packet(AVPacket *pkt);
59
/* initialize optional fields of a packet */
45
60
static inline void av_init_packet(AVPacket *pkt)
47
62
pkt->pts = AV_NOPTS_VALUE;
63
pkt->dts = AV_NOPTS_VALUE;
49
67
pkt->stream_index = 0;
68
pkt->destruct= av_destruct_packet_nofree;
52
71
int av_new_packet(AVPacket *pkt, int size);
72
int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
73
int av_dup_packet(AVPacket *pkt);
91
#define AVPROBE_SCORE_MAX 100
110
#define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection
93
112
typedef struct AVFormatParameters {
113
AVRational time_base;
100
118
enum PixelFormat pix_fmt;
101
struct AVImageFormat *image_format;
102
119
int channel; /* used to select dv channel */
103
const char *device; /* video4linux, audio or DV device */
120
#if LIBAVFORMAT_VERSION_INT < (52<<16)
121
const char *device; /* video, audio or DV device */
104
123
const char *standard; /* tv standard, NTSC, PAL, SECAM */
124
int mpeg2ts_raw:1; /* force raw MPEG2 transport stream output, if possible */
125
int mpeg2ts_compute_pcr:1; /* compute exact PCR for each transport
126
stream packet (only meaningful if
127
mpeg2ts_raw is TRUE */
128
int initial_pause:1; /* do not begin to play the stream
129
immediately (RTSP only) */
130
int prealloced_context:1;
131
enum CodecID video_codec_id;
132
enum CodecID audio_codec_id;
105
133
} AVFormatParameters;
107
#define AVFMT_NOFILE 0x0001 /* no file should be opened */
108
#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
109
#define AVFMT_NOHEADER 0x0004 /* signal that no header is present
110
(streams are added dynamically) */
135
//! demuxer will use url_fopen, no opened file should be provided by the caller
136
#define AVFMT_NOFILE 0x0001
137
#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
111
138
#define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
112
139
#define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
113
140
raw picture data */
141
#define AVFMT_GLOBALHEADER 0x0040 /* format wants global header */
142
#define AVFMT_NOTIMESTAMPS 0x0080 /* format doesnt need / has any timestamps */
143
#define AVFMT_GENERIC_INDEX 0x0100 /* use generic index building code */
115
145
typedef struct AVOutputFormat {
116
146
const char *name;
150
186
AVFormatParameters *ap);
151
187
/* read one packet and put it in 'pkt'. pts and flags are also
152
188
set. 'av_new_stream' can be called only if the flag
153
AVFMT_NOHEADER is used. */
189
AVFMTCTX_NOHEADER is used. */
154
190
int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
155
191
/* close the stream. The AVFormatContext and AVStreams are not
156
192
freed by this function */
157
193
int (*read_close)(struct AVFormatContext *);
158
/* seek at or before a given pts (given in microsecond). The pts
159
origin is defined by the stream */
160
int (*read_seek)(struct AVFormatContext *, int64_t pts);
161
/* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
195
* seek to a given timestamp relative to the frames in
196
* stream component stream_index
197
* @param stream_index must not be -1
198
* @param flags selects which direction should be preferred if no exact
201
int (*read_seek)(struct AVFormatContext *,
202
int stream_index, int64_t timestamp, int flags);
204
* gets the next timestamp in AV_TIME_BASE units.
206
int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
207
int64_t *pos, int64_t pos_limit);
208
/* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
163
210
/* if extensions are defined, then no probe is done. You should
164
211
usually not use extension format guessing because it is not
166
213
const char *extensions;
167
214
/* general purpose read only value that the format can use */
217
/* start/resume playing - only meaningful if using a network based format
219
int (*read_play)(struct AVFormatContext *);
221
/* pause playing - only meaningful if using a network based format
223
int (*read_pause)(struct AVFormatContext *);
225
const struct AVCodecTag **codec_tag;
169
227
/* private fields */
170
228
struct AVInputFormat *next;
231
typedef struct AVIndexEntry {
234
#define AVINDEX_KEYFRAME 0x0001
236
int size:30; //yeah trying to keep the size of this small to reduce memory requirements (its 24 vs 32 byte due to possible 8byte align)
237
int min_distance; /* min distance between this and the previous keyframe, used to avoid unneeded searching */
173
240
typedef struct AVStream {
174
241
int index; /* stream index in AVFormatContext */
175
242
int id; /* format specific stream id */
176
AVCodecContext codec; /* codec context */
177
int r_frame_rate; /* real frame rate of the stream */
178
int r_frame_rate_base;/* real frame rate base of the stream */
243
AVCodecContext *codec; /* codec context */
245
* real base frame rate of the stream.
246
* this is the lowest framerate with which all timestamps can be
247
* represented accurately (its the least common multiple of all
248
* framerates in the stream), Note, this value is just a guess!
249
* for example if the timebase is 1/90000 and all frames have either
250
* approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1
252
AVRational r_frame_rate;
180
254
/* internal data used in av_find_stream_info() */
181
int codec_info_state;
182
int codec_info_nb_repeat_frames;
183
int codec_info_nb_real_frames;
184
/* PTS generation when outputing stream */
255
int64_t codec_info_duration;
256
int codec_info_nb_frames;
257
/* encoding: PTS generation when outputing stream */
261
* this is the fundamental unit of time (in seconds) in terms
262
* of which frame timestamps are represented. for fixed-fps content,
263
* timebase should be 1/framerate and timestamp increments should be
266
AVRational time_base;
267
int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
186
268
/* ffmpeg.c private use */
187
269
int stream_copy; /* if TRUE, just copy stream */
270
enum AVDiscard discard; ///< selects which packets can be discarded at will and dont need to be demuxed
271
//FIXME move stuff to a flags field?
188
272
/* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
189
273
* MN:dunno if thats the right place, for it */
191
275
/* decoding: position of the first frame of the component, in
192
276
AV_TIME_BASE fractional seconds. */
194
278
/* decoding: duration of the stream, in AV_TIME_BASE fractional
196
280
int64_t duration;
282
char language[4]; /* ISO 639 3-letter language code (empty string if undefined) */
284
/* av_read_frame() support */
285
int need_parsing; ///< 1->full parsing needed, 2->only parse headers dont repack
286
struct AVCodecParserContext *parser;
289
int last_IP_duration;
291
/* av_seek_frame() support */
292
AVIndexEntry *index_entries; /* only used if the format does not
293
support seeking natively */
294
int nb_index_entries;
295
unsigned int index_entries_allocated_size;
297
int64_t nb_frames; ///< number of frames in this stream if known or 0
299
#define MAX_REORDER_DELAY 4
300
int64_t pts_buffer[MAX_REORDER_DELAY+1];
303
#define AVFMTCTX_NOHEADER 0x0001 /* signal that no header is present
304
(streams are added dynamically) */
199
306
#define MAX_STREAMS 20
201
308
/* format I/O context */
202
309
typedef struct AVFormatContext {
310
const AVClass *av_class; /* set by av_alloc_format_context */
203
311
/* can only be iformat or oformat, not both at the same time */
204
312
struct AVInputFormat *iformat;
205
313
struct AVOutputFormat *oformat;
207
315
ByteIOContext pb;
316
unsigned int nb_streams;
209
317
AVStream *streams[MAX_STREAMS];
210
318
char filename[1024]; /* input or output filename */
211
319
/* stream info */
213
322
char author[512];
214
323
char copyright[512];
251
394
extern AVInputFormat *first_iformat;
252
395
extern AVOutputFormat *first_oformat;
254
/* still image support */
255
struct AVInputImageContext;
256
typedef struct AVInputImageContext AVInputImageContext;
258
typedef struct AVImageInfo {
259
enum PixelFormat pix_fmt; /* requested pixel format */
260
int width; /* requested width */
261
int height; /* requested height */
262
int interleaved; /* image is interleaved (e.g. interleaved GIF) */
263
AVPicture pict; /* returned allocated image */
266
/* AVImageFormat.flags field constants */
267
#define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
269
typedef struct AVImageFormat {
271
const char *extensions;
272
/* tell if a given file has a chance of being parsing by this format */
273
int (*img_probe)(AVProbeData *);
274
/* read a whole image. 'alloc_cb' is called when the image size is
275
known so that the caller can allocate the image. If 'allo_cb'
276
returns non zero, then the parsing is aborted. Return '0' if
278
int (*img_read)(ByteIOContext *,
279
int (*alloc_cb)(void *, AVImageInfo *info), void *);
280
/* write the image */
281
int supported_pixel_formats; /* mask of supported formats for output */
282
int (*img_write)(ByteIOContext *, AVImageInfo *);
284
struct AVImageFormat *next;
287
void av_register_image_format(AVImageFormat *img_fmt);
288
AVImageFormat *av_probe_image_format(AVProbeData *pd);
289
AVImageFormat *guess_image_format(const char *filename);
290
int av_read_image(ByteIOContext *pb, const char *filename,
292
int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
293
int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
295
extern AVImageFormat *first_image_format;
297
extern AVImageFormat pnm_image_format;
298
extern AVImageFormat pbm_image_format;
299
extern AVImageFormat pgm_image_format;
300
extern AVImageFormat ppm_image_format;
301
extern AVImageFormat pam_image_format;
302
extern AVImageFormat pgmyuv_image_format;
303
extern AVImageFormat yuv_image_format;
305
extern AVImageFormat png_image_format;
307
extern AVImageFormat jpeg_image_format;
308
extern AVImageFormat gif_image_format;
397
enum CodecID av_guess_image2_codec(const char *filename);
310
399
/* XXX: use automatic init with either ELF sections or C file parser */
314
extern AVInputFormat mpegps_demux;
315
int mpegps_init(void);
318
extern AVInputFormat mpegts_demux;
319
int mpegts_init(void);
334
int avienc_init(void);
337
int avidec_init(void);
346
int movenc_init(void);
349
int flvenc_init(void);
352
int flvdec_init(void);
376
int yuv4mpeg_init(void);
388
extern AVInputFormat redir_demux;
389
int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
392
int fourxm_init(void);
401
int ipmovie_init(void);
411
404
#include "rtsp.h"
414
extern AVOutputFormat yuv4mpegpipe_oformat;
417
407
void av_register_input_format(AVInputFormat *format);
418
408
void av_register_output_format(AVOutputFormat *format);
419
AVOutputFormat *guess_stream_format(const char *short_name,
409
AVOutputFormat *guess_stream_format(const char *short_name,
420
410
const char *filename, const char *mime_type);
421
AVOutputFormat *guess_format(const char *short_name,
411
AVOutputFormat *guess_format(const char *short_name,
422
412
const char *filename, const char *mime_type);
413
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
414
const char *filename, const char *mime_type, enum CodecType type);
424
void av_hex_dump(uint8_t *buf, int size);
416
void av_hex_dump(FILE *f, uint8_t *buf, int size);
417
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
426
419
void av_register_all(void);
428
typedef struct FifoBuffer {
430
uint8_t *rptr, *wptr, *end;
433
int fifo_init(FifoBuffer *f, int size);
434
void fifo_free(FifoBuffer *f);
435
int fifo_size(FifoBuffer *f, uint8_t *rptr);
436
int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
437
void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
421
/* codec tag <-> codec id */
422
enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
423
unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
439
425
/* media file input */
440
426
AVInputFormat *av_find_input_format(const char *short_name);
441
427
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
442
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
428
int av_open_input_stream(AVFormatContext **ic_ptr,
429
ByteIOContext *pb, const char *filename,
430
AVInputFormat *fmt, AVFormatParameters *ap);
431
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
443
432
AVInputFormat *fmt,
445
434
AVFormatParameters *ap);
447
#define AVERROR_UNKNOWN (-1) /* unknown error */
448
#define AVERROR_IO (-2) /* i/o error */
449
#define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
450
#define AVERROR_INVALIDDATA (-4) /* invalid data found */
451
#define AVERROR_NOMEM (-5) /* not enough memory */
452
#define AVERROR_NOFMT (-6) /* unknown format */
435
/* no av_open for output, so applications will need this: */
436
AVFormatContext *av_alloc_format_context(void);
454
438
int av_find_stream_info(AVFormatContext *ic);
455
439
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
440
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
441
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
442
int av_read_play(AVFormatContext *s);
443
int av_read_pause(AVFormatContext *s);
456
444
void av_close_input_file(AVFormatContext *s);
457
445
AVStream *av_new_stream(AVFormatContext *s, int id);
458
void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
446
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
459
447
int pts_num, int pts_den);
449
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
450
#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
451
#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
453
int av_find_default_stream_index(AVFormatContext *s);
454
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
455
int av_add_index_entry(AVStream *st,
456
int64_t pos, int64_t timestamp, int size, int distance, int flags);
457
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
458
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
459
int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
461
461
/* media file output */
462
462
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
463
463
int av_write_header(AVFormatContext *s);
464
int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
464
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
465
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
466
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
466
468
int av_write_trailer(AVFormatContext *s);
468
470
void dump_format(AVFormatContext *ic,
472
474
int parse_image_size(int *width_ptr, int *height_ptr, const char *str);