22
22
#define AVFORMAT_AVFORMAT_H
24
24
#define LIBAVFORMAT_VERSION_MAJOR 52
25
#define LIBAVFORMAT_VERSION_MINOR 25
25
#define LIBAVFORMAT_VERSION_MINOR 31
26
26
#define LIBAVFORMAT_VERSION_MICRO 0
28
28
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
49
struct AVFormatContext;
51
53
* Public Metadata API.
52
* !!WARNING!! This is a work in progress. Don't use outside FFmpeg for now.
53
54
* The metadata API allows libavformat to export metadata tags to a client
54
55
* application using a sequence of key/value pairs.
55
56
* Important concepts to keep in mind:
79
80
typedef struct AVMetadata AVMetadata;
81
typedef struct AVMetadataConv AVMetadataConv;
82
* gets a metadata element with matching key.
83
* @param prev set to the previous matching element to find the next.
84
* @param flags allows case as well as suffix insensitive comparisons.
85
* @return found tag or NULL, changing key or value leads to undefined behavior.
84
* Gets a metadata element with matching key.
85
* @param prev Set to the previous matching element to find the next.
86
* @param flags Allows case as well as suffix-insensitive comparisons.
87
* @return Found tag or NULL, changing key or value leads to undefined behavior.
88
90
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
91
* sets the given tag in m, overwriting an existing tag.
92
* @param key tag key to add to m (will be av_strduped).
93
* @param value tag value to add to m (will be av_strduped).
94
* @return >= 0 if success otherwise error code that is <0.
93
* Sets the given tag in m, overwriting an existing tag.
94
* @param key tag key to add to m (will be av_strduped)
95
* @param value tag value to add to m (will be av_strduped)
96
* @return >= 0 on success otherwise an error code <0
96
98
int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
99
* Free all the memory allocated for an AVMetadata struct.
101
* Convert all the metadata sets from ctx according to the source and
102
* destination conversion tables.
103
* @param d_conv destination tags format conversion table
104
* @param s_conv source tags format conversion table
106
void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
107
const AVMetadataConv *s_conv);
110
* Frees all the memory allocated for an AVMetadata struct.
101
112
void av_metadata_free(AVMetadata **m);
106
117
typedef struct AVPacket {
108
* Presentation timestamp in time_base units.
109
* This is the time at which the decompressed packet will be presented
119
* Presentation timestamp in time_base units; the time at which the
120
* decompressed packet will be presented to the user.
111
121
* Can be AV_NOPTS_VALUE if it is not stored in the file.
112
122
* pts MUST be larger or equal to dts as presentation cannot happen before
113
123
* decompression, unless one wants to view hex dumps. Some formats misuse
114
* the terms dts and pts/cts to mean something different, these timestamps
124
* the terms dts and pts/cts to mean something different. Such timestamps
115
125
* must be converted to true pts/dts before they are stored in AVPacket.
119
* Decompression timestamp in time_base units.
120
* This is the time at which the packet is decompressed.
129
* Decompression timestamp in time_base units; the time at which the
130
* packet is decompressed.
121
131
* Can be AV_NOPTS_VALUE if it is not stored in the file.
234
#define AVPROBE_SCORE_MAX 100 ///< Maximum score, half of that is used for file-extension-based detection.
241
#define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
235
242
#define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
237
244
typedef struct AVFormatParameters {
266
273
#define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
267
274
#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
268
275
#define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
276
#define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
270
278
typedef struct AVOutputFormat {
271
279
const char *name;
277
285
const char *long_name;
278
286
const char *mime_type;
279
287
const char *extensions; /**< comma-separated filename extensions */
280
/** Size of private data so that it can be allocated in the wrapper. */
288
/** size of private data so that it can be allocated in the wrapper */
281
289
int priv_data_size;
282
290
/* output support */
283
291
enum CodecID audio_codec; /**< default audio codec */
296
304
* List of supported codec_id-codec_tag pairs, ordered by "better
297
* choice first". The arrays are all CODEC_ID_NONE terminated.
305
* choice first". The arrays are all terminated by CODEC_ID_NONE.
299
307
const struct AVCodecTag * const *codec_tag;
301
309
enum CodecID subtitle_codec; /**< default subtitle codec */
311
const AVMetadataConv *metadata_conv;
303
313
/* private fields */
304
314
struct AVOutputFormat *next;
305
315
} AVOutputFormat;
315
325
/** Size of private data so that it can be allocated in the wrapper. */
316
326
int priv_data_size;
318
* Tell if a given file has a chance of being parsed by this format.
328
* Tell if a given file has a chance of being parsed as this format.
319
329
* The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
320
330
* big so you do not have to check for that unless you need more.
333
343
/** Close the stream. The AVFormatContext and AVStreams are not
334
344
freed by this function */
335
345
int (*read_close)(struct AVFormatContext *);
347
#if LIBAVFORMAT_VERSION_MAJOR < 53
337
349
* Seek to a given timestamp relative to the frames in
338
350
* stream component stream_index.
339
* @param stream_index must not be -1
340
* @param flags selects which direction should be preferred if no exact
351
* @param stream_index Must not be -1.
352
* @param flags Selects which direction should be preferred if no exact
353
* match is available.
342
354
* @return >= 0 on success (but not necessarily the new offset)
344
356
int (*read_seek)(struct AVFormatContext *,
345
357
int stream_index, int64_t timestamp, int flags);
347
360
* Gets the next timestamp in stream[stream_index].time_base units.
348
361
* @return the timestamp or AV_NOPTS_VALUE if an error occurred
369
382
const struct AVCodecTag * const *codec_tag;
385
* Seek to timestamp ts.
386
* Seeking will be done so that the point from which all active streams
387
* can be presented successfully will be closest to ts and within min/max_ts.
388
* Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
390
int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
392
const AVMetadataConv *metadata_conv;
371
394
/* private fields */
372
395
struct AVInputFormat *next;
407
430
int id; /**< format-specific stream ID */
408
431
AVCodecContext *codec; /**< codec context */
410
* Real base frame rate of the stream.
411
* This is the lowest frame rate with which all timestamps can be
433
* Real base framerate of the stream.
434
* This is the lowest framerate with which all timestamps can be
412
435
* represented accurately (it is the least common multiple of all
413
* frame rates in the stream). Note, this value is just a guess!
414
* For example if the time base is 1/90000 and all frames have either
436
* framerates in the stream). Note, this value is just a guess!
437
* For example, if the time base is 1/90000 and all frames have either
415
438
* approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
417
440
AVRational r_frame_rate;
426
449
* This is the fundamental unit of time (in seconds) in terms
427
450
* of which frame timestamps are represented. For fixed-fps content,
428
* time base should be 1/frame rate and timestamp increments should be 1.
451
* time base should be 1/framerate and timestamp increments should be 1.
430
453
AVRational time_base;
431
454
int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
494
519
const uint8_t *cur_ptr;
496
521
AVPacket cur_pkt;
523
// Timestamp generation support:
525
* Timestamp corresponding to the last dts sync point.
527
* Initialized when AVCodecParserContext.dts_sync_point >= 0 and
528
* a DTS is received from the underlying container. Otherwise set to
529
* AV_NOPTS_VALUE by default.
531
int64_t reference_dts;
499
534
#define AV_PROGRAM_RUNNING 1
507
542
typedef struct AVProgram {
544
#if LIBAVFORMAT_VERSION_INT < (53<<16)
509
545
char *provider_name; ///< network name for DVB streams
510
546
char *name; ///< service name for DVB streams
512
549
enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
513
550
unsigned int *stream_index;
522
559
int id; ///< unique ID to identify the chapter
523
560
AVRational time_base; ///< time base in which the start/end timestamps are specified
524
561
int64_t start, end; ///< chapter start/end time in time_base units
562
#if LIBAVFORMAT_VERSION_INT < (53<<16)
525
563
char *title; ///< chapter title
526
565
AVMetadata *metadata;
536
575
* sizeof(AVFormatContext) must not be used outside libav*.
538
577
typedef struct AVFormatContext {
539
const AVClass *av_class; /**< Set by av_alloc_format_context. */
578
const AVClass *av_class; /**< Set by avformat_alloc_context. */
540
579
/* Can only be iformat or oformat, not both at the same time. */
541
580
struct AVInputFormat *iformat;
542
581
struct AVOutputFormat *oformat;
555
595
int year; /**< ID3 year, 0 if none */
556
596
int track; /**< track number, 0 if none */
557
597
char genre[32]; /**< ID3 genre */
559
600
int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
560
601
/* private data for pts handling (do not modify directly). */
575
616
int64_t file_size;
576
617
/** Decoding: total stream bitrate in bit/s, 0 if not
577
618
available. Never set it directly if the file_size and the
578
duration are known as ffmpeg can compute it automatically. */
619
duration are known as FFmpeg can compute it automatically. */
581
622
/* av_read_frame() support */
604
#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate pts if missing even if it requires parsing future frames.
645
#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
605
646
#define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
606
647
#define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
609
/** Decoding: size of data to probe; encoding: unused. */
650
/** decoding: size of data to probe; encoding: unused. */
610
651
unsigned int probesize;
638
679
enum CodecID subtitle_codec_id;
641
* Maximum amount of memory in bytes to use per stream for the index.
642
* If the needed index exceeds this size, entries will be discarded as
682
* Maximum amount of memory in bytes to use for the index of each stream.
683
* If the index exceeds this size, entries will be discarded as
643
684
* needed to maintain a smaller size. This can lead to slower or less
644
685
* accurate seeking (depends on demuxer).
645
686
* Demuxers for which a full in-memory index is mandatory will ignore
688
729
extern AVOutputFormat *first_oformat;
733
* If f is NULL, returns the first registered input format,
734
* if f is non-NULL, returns the next registered input format after f
735
* or NULL if f is the last one.
691
737
AVInputFormat *av_iformat_next(AVInputFormat *f);
740
* If f is NULL, returns the first registered output format,
741
* if f is non-NULL, returns the next registered output format after f
742
* or NULL if f is the last one.
692
744
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
694
746
enum CodecID av_guess_image2_codec(const char *filename);
696
/* XXX: use automatic init with either ELF sections or C file parser */
748
/* XXX: Use automatic init with either ELF sections or C file parser */
700
752
void av_register_input_format(AVInputFormat *format);
767
819
* @see av_register_input_format()
768
820
* @see av_register_output_format()
769
* @see register_protocol()
821
* @see av_register_protocol()
771
823
void av_register_all(void);
813
865
AVInputFormat *fmt,
815
867
AVFormatParameters *ap);
869
#if LIBAVFORMAT_VERSION_MAJOR < 53
871
* @deprecated Use avformat_alloc_context() instead.
873
attribute_deprecated AVFormatContext *av_alloc_format_context(void);
817
877
* Allocate an AVFormatContext.
818
878
* Can be freed with av_free() but do not forget to free everything you
819
879
* explicitly allocated as well!
821
AVFormatContext *av_alloc_format_context(void);
881
AVFormatContext *avformat_alloc_context(void);
824
884
* Read packets of a media file to get stream information. This
825
885
* is useful for file formats with no headers such as MPEG. This
826
* function also computes the real frame rate in case of MPEG-2 repeat
886
* function also computes the real framerate in case of MPEG-2 repeat
828
888
* The logical file position is not changed by this function;
829
889
* examined packets may be buffered for later processing.
859
919
* then it contains one frame.
861
921
* pkt->pts, pkt->dts and pkt->duration are always set to correct
862
* values in AVStream.timebase units (and guessed if the format cannot
922
* values in AVStream.time_base units (and guessed if the format cannot
863
923
* provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
864
924
* has B-frames, so it is better to rely on pkt->dts if you do not
865
925
* decompress the payload.
869
929
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
872
* Seek to the key frame at timestamp.
932
* Seek to the keyframe at timestamp.
873
933
* 'timestamp' in 'stream_index'.
874
934
* @param stream_index If stream_index is (-1), a default
875
935
* stream is selected, and timestamp is automatically converted
886
* Start playing a network based stream (e.g. RTSP stream) at the
946
* Seek to timestamp ts.
947
* Seeking will be done so that the point from which all active streams
948
* can be presented successfully will be closest to ts and within min/max_ts.
949
* Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
951
* If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
952
* are the file position (this may not be supported by all demuxers).
953
* If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
954
* in the stream with stream_index (this may not be supported by all demuxers).
955
* Otherwise all timestamps are in units of the stream selected by stream_index
956
* or if stream_index is -1, in AV_TIME_BASE units.
957
* If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
958
* keyframes (this may not be supported by all demuxers).
960
* @param stream_index index of the stream which is used as time base reference
961
* @param min_ts smallest acceptable timestamp
962
* @param ts target timestamp
963
* @param max_ts largest acceptable timestamp
965
* @returns >=0 on success, error code otherwise
967
* @NOTE This is part of the new seek API which is still under construction.
968
* Thus do not use this yet. It may change at any time, do not expect
969
* ABI compatibility yet!
971
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
974
* Start playing a network-based stream (e.g. RTSP stream) at the
887
975
* current position.
889
977
int av_read_play(AVFormatContext *s);
892
* Pause a network based stream (e.g. RTSP stream).
980
* Pause a network-based stream (e.g. RTSP stream).
894
982
* Use av_read_play() to resume it.
969
1057
* Ensures the index uses less memory than the maximum specified in
970
* AVFormatContext.max_index_size, by discarding entries if it grows
1058
* AVFormatContext.max_index_size by discarding entries if it grows
972
1060
* This function is not part of the public API and should only be called
1048
1136
* Writes a packet to an output media file ensuring correct interleaving.
1050
1138
* The packet must contain one audio or video frame.
1051
* If the packets are already correctly interleaved the application should
1139
* If the packets are already correctly interleaved, the application should
1052
1140
* call av_write_frame() instead as it is slightly faster. It is also important
1053
1141
* to keep in mind that completely non-interleaved input will need huge amounts
1054
1142
* of memory to interleave with this, so it is preferable to interleave at the
1065
1153
* Interleave a packet per dts in an output media file.
1067
1155
* Packets with pkt->destruct == av_destruct_packet will be freed inside this
1068
* function, so they cannot be used after it, note calling av_free_packet()
1156
* function, so they cannot be used after it. Note that calling av_free_packet()
1069
1157
* on them is still safe.
1071
1159
* @param s media file handle
1104
1192
const char *str);
1107
* Converts frame rate from string to a fraction.
1195
* Converts framerate from a string to a fraction.
1108
1196
* @deprecated Use av_parse_video_frame_rate instead.
1110
1198
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1145
1233
/* ffm-specific for ffserver */
1146
1234
#define FFM_PACKET_SIZE 4096
1147
1235
int64_t ffm_read_write_index(int fd);
1148
void ffm_write_write_index(int fd, int64_t pos);
1236
int ffm_write_write_index(int fd, int64_t pos);
1149
1237
void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1157
1245
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1160
* Returns in 'buf' the path with '%d' replaced by number.
1248
* Returns in 'buf' the path with '%d' replaced by a number.
1162
1250
* Also handles the '%0nd' format where 'n' is the total number
1163
1251
* of digits and '%%'.
1198
1286
#ifdef HAVE_AV_CONFIG_H
1200
void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
1288
void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
1202
1290
#ifdef __GNUC__
1203
1291
#define dynarray_add(tab, nb_ptr, elem)\
1205
1293
__typeof__(tab) _tab = (tab);\
1206
1294
__typeof__(elem) _elem = (elem);\
1207
1295
(void)sizeof(**_tab == _elem); /* check that types are compatible */\
1208
ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
1296
ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
1211
1299
#define dynarray_add(tab, nb_ptr, elem)\
1213
ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
1301
ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\