avformat.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /*
  2. * copyright (c) 2001 Fabrice Bellard
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVFORMAT_AVFORMAT_H
  21. #define AVFORMAT_AVFORMAT_H
  22. #define LIBAVFORMAT_VERSION_MAJOR 52
  23. #define LIBAVFORMAT_VERSION_MINOR 45
  24. #define LIBAVFORMAT_VERSION_MICRO 0
  25. #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
  26. LIBAVFORMAT_VERSION_MINOR, \
  27. LIBAVFORMAT_VERSION_MICRO)
  28. #define LIBAVFORMAT_VERSION AV_VERSION(LIBAVFORMAT_VERSION_MAJOR, \
  29. LIBAVFORMAT_VERSION_MINOR, \
  30. LIBAVFORMAT_VERSION_MICRO)
  31. #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
  32. #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
  33. /**
  34. * Returns the LIBAVFORMAT_VERSION_INT constant.
  35. */
  36. unsigned avformat_version(void);
  37. /**
  38. * Returns the libavformat build-time configuration.
  39. */
  40. const char * avformat_configuration(void);
  41. /**
  42. * Returns the libavformat license.
  43. */
  44. const char * avformat_license(void);
  45. #include <time.h>
  46. #include <stdio.h> /* FILE */
  47. #include "libavcodec/avcodec.h"
  48. #include "avio.h"
  49. struct AVFormatContext;
  50. /*
  51. * Public Metadata API.
  52. * The metadata API allows libavformat to export metadata tags to a client
  53. * application using a sequence of key/value pairs.
  54. * Important concepts to keep in mind:
  55. * 1. Keys are unique; there can never be 2 tags with the same key. This is
  56. * also meant semantically, i.e., a demuxer should not knowingly produce
  57. * several keys that are literally different but semantically identical.
  58. * E.g., key=Author5, key=Author6. In this example, all authors must be
  59. * placed in the same tag.
  60. * 2. Metadata is flat, not hierarchical; there are no subtags. If you
  61. * want to store, e.g., the email address of the child of producer Alice
  62. * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
  63. * 3. A tag whose value is localized for a particular language is appended
  64. * with a dash character ('-') and the ISO 639-2/B 3-letter language code.
  65. * For example: Author-ger=Michael, Author-eng=Mike
  66. * The original/default language is in the unqualified "Author" tag.
  67. * A demuxer should set a default if it sets any translated tag.
  68. */
  69. #define AV_METADATA_MATCH_CASE 1
  70. #define AV_METADATA_IGNORE_SUFFIX 2
  71. #define AV_METADATA_DONT_STRDUP_KEY 4
  72. #define AV_METADATA_DONT_STRDUP_VAL 8
  73. typedef struct {
  74. char *key;
  75. char *value;
  76. }AVMetadataTag;
  77. typedef struct AVMetadata AVMetadata;
  78. typedef struct AVMetadataConv AVMetadataConv;
  79. /**
  80. * Gets a metadata element with matching key.
  81. * @param prev Set to the previous matching element to find the next.
  82. * @param flags Allows case as well as suffix-insensitive comparisons.
  83. * @return Found tag or NULL, changing key or value leads to undefined behavior.
  84. */
  85. AVMetadataTag *
  86. av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
  87. #if LIBAVFORMAT_VERSION_MAJOR == 52
  88. /**
  89. * Sets the given tag in m, overwriting an existing tag.
  90. * @param key tag key to add to m (will be av_strduped)
  91. * @param value tag value to add to m (will be av_strduped)
  92. * @return >= 0 on success otherwise an error code <0
  93. */
  94. int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
  95. #endif
  96. /**
  97. * Sets the given tag in m, overwriting an existing tag.
  98. * @param key tag key to add to m (will be av_strduped depending on flags)
  99. * @param value tag value to add to m (will be av_strduped depending on flags)
  100. * @return >= 0 on success otherwise an error code <0
  101. */
  102. int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
  103. /**
  104. * Converts all the metadata sets from ctx according to the source and
  105. * destination conversion tables.
  106. * @param d_conv destination tags format conversion table
  107. * @param s_conv source tags format conversion table
  108. */
  109. void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
  110. const AVMetadataConv *s_conv);
  111. /**
  112. * Frees all the memory allocated for an AVMetadata struct.
  113. */
  114. void av_metadata_free(AVMetadata **m);
  115. /* packet functions */
  116. /**
  117. * Allocates and reads the payload of a packet and initializes its
  118. * fields with default values.
  119. *
  120. * @param pkt packet
  121. * @param size desired payload size
  122. * @return >0 (read size) if OK, AVERROR_xxx otherwise
  123. */
  124. int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
  125. /*************************************************/
  126. /* fractional numbers for exact pts handling */
  127. /**
  128. * The exact value of the fractional number is: 'val + num / den'.
  129. * num is assumed to be 0 <= num < den.
  130. */
  131. typedef struct AVFrac {
  132. int64_t val, num, den;
  133. } AVFrac;
  134. /*************************************************/
  135. /* input/output formats */
  136. struct AVCodecTag;
  137. /** This structure contains the data a format has to probe a file. */
  138. typedef struct AVProbeData {
  139. const char *filename;
  140. unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
  141. int buf_size; /**< Size of buf except extra allocated bytes */
  142. } AVProbeData;
  143. #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
  144. #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
  145. typedef struct AVFormatParameters {
  146. AVRational time_base;
  147. int sample_rate;
  148. int channels;
  149. int width;
  150. int height;
  151. enum PixelFormat pix_fmt;
  152. int channel; /**< Used to select DV channel. */
  153. const char *standard; /**< TV standard, NTSC, PAL, SECAM */
  154. unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */
  155. unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
  156. stream packet (only meaningful if
  157. mpeg2ts_raw is TRUE). */
  158. unsigned int initial_pause:1; /**< Do not begin to play the stream
  159. immediately (RTSP only). */
  160. unsigned int prealloced_context:1;
  161. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  162. enum CodecID video_codec_id;
  163. enum CodecID audio_codec_id;
  164. #endif
  165. } AVFormatParameters;
  166. //! Demuxer will use url_fopen, no opened file should be provided by the caller.
  167. #define AVFMT_NOFILE 0x0001
  168. #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
  169. #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
  170. #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
  171. raw picture data. */
  172. #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
  173. #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
  174. #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
  175. #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
  176. #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
  177. typedef struct AVOutputFormat {
  178. const char *name;
  179. /**
  180. * Descriptive name for the format, meant to be more human-readable
  181. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  182. * to define it.
  183. */
  184. const char *long_name;
  185. const char *mime_type;
  186. const char *extensions; /**< comma-separated filename extensions */
  187. /** size of private data so that it can be allocated in the wrapper */
  188. int priv_data_size;
  189. /* output support */
  190. enum CodecID audio_codec; /**< default audio codec */
  191. enum CodecID video_codec; /**< default video codec */
  192. int (*write_header)(struct AVFormatContext *);
  193. int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
  194. int (*write_trailer)(struct AVFormatContext *);
  195. /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
  196. int flags;
  197. /** Currently only used to set pixel format if not YUV420P. */
  198. int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
  199. int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
  200. AVPacket *in, int flush);
  201. /**
  202. * List of supported codec_id-codec_tag pairs, ordered by "better
  203. * choice first". The arrays are all terminated by CODEC_ID_NONE.
  204. */
  205. const struct AVCodecTag * const *codec_tag;
  206. enum CodecID subtitle_codec; /**< default subtitle codec */
  207. const AVMetadataConv *metadata_conv;
  208. /* private fields */
  209. struct AVOutputFormat *next;
  210. } AVOutputFormat;
  211. typedef struct AVInputFormat {
  212. const char *name;
  213. /**
  214. * Descriptive name for the format, meant to be more human-readable
  215. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  216. * to define it.
  217. */
  218. const char *long_name;
  219. /** Size of private data so that it can be allocated in the wrapper. */
  220. int priv_data_size;
  221. /**
  222. * Tell if a given file has a chance of being parsed as this format.
  223. * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
  224. * big so you do not have to check for that unless you need more.
  225. */
  226. int (*read_probe)(AVProbeData *);
  227. /** Read the format header and initialize the AVFormatContext
  228. structure. Return 0 if OK. 'ap' if non-NULL contains
  229. additional parameters. Only used in raw format right
  230. now. 'av_new_stream' should be called to create new streams. */
  231. int (*read_header)(struct AVFormatContext *,
  232. AVFormatParameters *ap);
  233. /** Read one packet and put it in 'pkt'. pts and flags are also
  234. set. 'av_new_stream' can be called only if the flag
  235. AVFMTCTX_NOHEADER is used.
  236. @return 0 on success, < 0 on error.
  237. When returning an error, pkt must not have been allocated
  238. or must be freed before returning */
  239. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  240. /** Close the stream. The AVFormatContext and AVStreams are not
  241. freed by this function */
  242. int (*read_close)(struct AVFormatContext *);
  243. #if LIBAVFORMAT_VERSION_MAJOR < 53
  244. /**
  245. * Seek to a given timestamp relative to the frames in
  246. * stream component stream_index.
  247. * @param stream_index Must not be -1.
  248. * @param flags Selects which direction should be preferred if no exact
  249. * match is available.
  250. * @return >= 0 on success (but not necessarily the new offset)
  251. */
  252. int (*read_seek)(struct AVFormatContext *,
  253. int stream_index, int64_t timestamp, int flags);
  254. #endif
  255. /**
  256. * Gets the next timestamp in stream[stream_index].time_base units.
  257. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  258. */
  259. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  260. int64_t *pos, int64_t pos_limit);
  261. /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
  262. int flags;
  263. /** If extensions are defined, then no probe is done. You should
  264. usually not use extension format guessing because it is not
  265. reliable enough */
  266. const char *extensions;
  267. /** General purpose read-only value that the format can use. */
  268. int value;
  269. /** Starts/resumes playing - only meaningful if using a network-based format
  270. (RTSP). */
  271. int (*read_play)(struct AVFormatContext *);
  272. /** Pauses playing - only meaningful if using a network-based format
  273. (RTSP). */
  274. int (*read_pause)(struct AVFormatContext *);
  275. const struct AVCodecTag * const *codec_tag;
  276. /**
  277. * Seeks to timestamp ts.
  278. * Seeking will be done so that the point from which all active streams
  279. * can be presented successfully will be closest to ts and within min/max_ts.
  280. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  281. */
  282. int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  283. const AVMetadataConv *metadata_conv;
  284. /* private fields */
  285. struct AVInputFormat *next;
  286. } AVInputFormat;
  287. enum AVStreamParseType {
  288. AVSTREAM_PARSE_NONE,
  289. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  290. AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
  291. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
  292. };
  293. typedef struct AVIndexEntry {
  294. int64_t pos;
  295. int64_t timestamp;
  296. #define AVINDEX_KEYFRAME 0x0001
  297. int flags:2;
  298. int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
  299. int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
  300. } AVIndexEntry;
  301. #define AV_DISPOSITION_DEFAULT 0x0001
  302. #define AV_DISPOSITION_DUB 0x0002
  303. #define AV_DISPOSITION_ORIGINAL 0x0004
  304. #define AV_DISPOSITION_COMMENT 0x0008
  305. #define AV_DISPOSITION_LYRICS 0x0010
  306. #define AV_DISPOSITION_KARAOKE 0x0020
  307. /**
  308. * Stream structure.
  309. * New fields can be added to the end with minor version bumps.
  310. * Removal, reordering and changes to existing fields require a major
  311. * version bump.
  312. * sizeof(AVStream) must not be used outside libav*.
  313. */
  314. typedef struct AVStream {
  315. int index; /**< stream index in AVFormatContext */
  316. int id; /**< format-specific stream ID */
  317. AVCodecContext *codec; /**< codec context */
  318. /**
  319. * Real base framerate of the stream.
  320. * This is the lowest framerate with which all timestamps can be
  321. * represented accurately (it is the least common multiple of all
  322. * framerates in the stream). Note, this value is just a guess!
  323. * For example, if the time base is 1/90000 and all frames have either
  324. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  325. */
  326. AVRational r_frame_rate;
  327. void *priv_data;
  328. /* internal data used in av_find_stream_info() */
  329. int64_t first_dts;
  330. /** encoding: pts generation when outputting stream */
  331. struct AVFrac pts;
  332. /**
  333. * This is the fundamental unit of time (in seconds) in terms
  334. * of which frame timestamps are represented. For fixed-fps content,
  335. * time base should be 1/framerate and timestamp increments should be 1.
  336. */
  337. AVRational time_base;
  338. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  339. /* ffmpeg.c private use */
  340. int stream_copy; /**< If set, just copy stream. */
  341. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  342. //FIXME move stuff to a flags field?
  343. /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
  344. * MN: dunno if that is the right place for it */
  345. float quality;
  346. /**
  347. * Decoding: pts of the first frame of the stream, in stream time base.
  348. * Only set this if you are absolutely 100% sure that the value you set
  349. * it to really is the pts of the first frame.
  350. * This may be undefined (AV_NOPTS_VALUE).
  351. * @note The ASF header does NOT contain a correct start_time the ASF
  352. * demuxer must NOT set this.
  353. */
  354. int64_t start_time;
  355. /**
  356. * Decoding: duration of the stream, in stream time base.
  357. * If a source file does not specify a duration, but does specify
  358. * a bitrate, this value will be estimated from bitrate and file size.
  359. */
  360. int64_t duration;
  361. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  362. char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */
  363. #endif
  364. /* av_read_frame() support */
  365. enum AVStreamParseType need_parsing;
  366. struct AVCodecParserContext *parser;
  367. int64_t cur_dts;
  368. int last_IP_duration;
  369. int64_t last_IP_pts;
  370. /* av_seek_frame() support */
  371. AVIndexEntry *index_entries; /**< Only used if the format does not
  372. support seeking natively. */
  373. int nb_index_entries;
  374. unsigned int index_entries_allocated_size;
  375. int64_t nb_frames; ///< number of frames in this stream if known or 0
  376. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  377. int64_t unused[4+1];
  378. char *filename; /**< source filename of the stream */
  379. #endif
  380. int disposition; /**< AV_DISPOSITION_* bit field */
  381. AVProbeData probe_data;
  382. #define MAX_REORDER_DELAY 16
  383. int64_t pts_buffer[MAX_REORDER_DELAY+1];
  384. /**
  385. * sample aspect ratio (0 if unknown)
  386. * - encoding: Set by user.
  387. * - decoding: Set by libavformat.
  388. */
  389. AVRational sample_aspect_ratio;
  390. AVMetadata *metadata;
  391. /* av_read_frame() support */
  392. const uint8_t *cur_ptr;
  393. int cur_len;
  394. AVPacket cur_pkt;
  395. // Timestamp generation support:
  396. /**
  397. * Timestamp corresponding to the last dts sync point.
  398. *
  399. * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
  400. * a DTS is received from the underlying container. Otherwise set to
  401. * AV_NOPTS_VALUE by default.
  402. */
  403. int64_t reference_dts;
  404. /**
  405. * Number of packets to buffer for codec probing
  406. * NOT PART OF PUBLIC API
  407. */
  408. #define MAX_PROBE_PACKETS 2500
  409. int probe_packets;
  410. /**
  411. * last packet in packet_buffer for this stream when muxing.
  412. * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
  413. */
  414. struct AVPacketList *last_in_packet_buffer;
  415. /**
  416. * Average framerate
  417. */
  418. AVRational avg_frame_rate;
  419. } AVStream;
  420. #define AV_PROGRAM_RUNNING 1
  421. /**
  422. * New fields can be added to the end with minor version bumps.
  423. * Removal, reordering and changes to existing fields require a major
  424. * version bump.
  425. * sizeof(AVProgram) must not be used outside libav*.
  426. */
  427. typedef struct AVProgram {
  428. int id;
  429. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  430. char *provider_name; ///< network name for DVB streams
  431. char *name; ///< service name for DVB streams
  432. #endif
  433. int flags;
  434. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  435. unsigned int *stream_index;
  436. unsigned int nb_stream_indexes;
  437. AVMetadata *metadata;
  438. } AVProgram;
  439. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  440. (streams are added dynamically) */
  441. typedef struct AVChapter {
  442. int id; ///< unique ID to identify the chapter
  443. AVRational time_base; ///< time base in which the start/end timestamps are specified
  444. int64_t start, end; ///< chapter start/end time in time_base units
  445. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  446. char *title; ///< chapter title
  447. #endif
  448. AVMetadata *metadata;
  449. } AVChapter;
  450. #define MAX_STREAMS 20
  451. /**
  452. * Format I/O context.
  453. * New fields can be added to the end with minor version bumps.
  454. * Removal, reordering and changes to existing fields require a major
  455. * version bump.
  456. * sizeof(AVFormatContext) must not be used outside libav*.
  457. */
  458. typedef struct AVFormatContext {
  459. const AVClass *av_class; /**< Set by avformat_alloc_context. */
  460. /* Can only be iformat or oformat, not both at the same time. */
  461. struct AVInputFormat *iformat;
  462. struct AVOutputFormat *oformat;
  463. void *priv_data;
  464. ByteIOContext *pb;
  465. unsigned int nb_streams;
  466. AVStream *streams[MAX_STREAMS];
  467. char filename[1024]; /**< input or output filename */
  468. /* stream info */
  469. int64_t timestamp;
  470. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  471. char title[512];
  472. char author[512];
  473. char copyright[512];
  474. char comment[512];
  475. char album[512];
  476. int year; /**< ID3 year, 0 if none */
  477. int track; /**< track number, 0 if none */
  478. char genre[32]; /**< ID3 genre */
  479. #endif
  480. int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
  481. /* private data for pts handling (do not modify directly). */
  482. /** This buffer is only needed when packets were already buffered but
  483. not decoded, for example to get the codec parameters in MPEG
  484. streams. */
  485. struct AVPacketList *packet_buffer;
  486. /** Decoding: position of the first frame of the component, in
  487. AV_TIME_BASE fractional seconds. NEVER set this value directly:
  488. It is deduced from the AVStream values. */
  489. int64_t start_time;
  490. /** Decoding: duration of the stream, in AV_TIME_BASE fractional
  491. seconds. NEVER set this value directly: it is deduced from the
  492. AVStream values. */
  493. int64_t duration;
  494. /** decoding: total file size, 0 if unknown */
  495. int64_t file_size;
  496. /** Decoding: total stream bitrate in bit/s, 0 if not
  497. available. Never set it directly if the file_size and the
  498. duration are known as FFmpeg can compute it automatically. */
  499. int bit_rate;
  500. /* av_read_frame() support */
  501. AVStream *cur_st;
  502. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  503. const uint8_t *cur_ptr_deprecated;
  504. int cur_len_deprecated;
  505. AVPacket cur_pkt_deprecated;
  506. #endif
  507. /* av_seek_frame() support */
  508. int64_t data_offset; /** offset of the first packet */
  509. int index_built;
  510. int mux_rate;
  511. unsigned int packet_size;
  512. int preload;
  513. int max_delay;
  514. #define AVFMT_NOOUTPUTLOOP -1
  515. #define AVFMT_INFINITEOUTPUTLOOP 0
  516. /** number of times to loop output in formats that support it */
  517. int loop_output;
  518. int flags;
  519. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  520. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  521. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  522. int loop_input;
  523. /** decoding: size of data to probe; encoding: unused. */
  524. unsigned int probesize;
  525. /**
  526. * Maximum time (in AV_TIME_BASE units) during which the input should
  527. * be analyzed in av_find_stream_info().
  528. */
  529. int max_analyze_duration;
  530. const uint8_t *key;
  531. int keylen;
  532. unsigned int nb_programs;
  533. AVProgram **programs;
  534. /**
  535. * Forced video codec_id.
  536. * Demuxing: Set by user.
  537. */
  538. enum CodecID video_codec_id;
  539. /**
  540. * Forced audio codec_id.
  541. * Demuxing: Set by user.
  542. */
  543. enum CodecID audio_codec_id;
  544. /**
  545. * Forced subtitle codec_id.
  546. * Demuxing: Set by user.
  547. */
  548. enum CodecID subtitle_codec_id;
  549. /**
  550. * Maximum amount of memory in bytes to use for the index of each stream.
  551. * If the index exceeds this size, entries will be discarded as
  552. * needed to maintain a smaller size. This can lead to slower or less
  553. * accurate seeking (depends on demuxer).
  554. * Demuxers for which a full in-memory index is mandatory will ignore
  555. * this.
  556. * muxing : unused
  557. * demuxing: set by user
  558. */
  559. unsigned int max_index_size;
  560. /**
  561. * Maximum amount of memory in bytes to use for buffering frames
  562. * obtained from realtime capture devices.
  563. */
  564. unsigned int max_picture_buffer;
  565. unsigned int nb_chapters;
  566. AVChapter **chapters;
  567. /**
  568. * Flags to enable debugging.
  569. */
  570. int debug;
  571. #define FF_FDEBUG_TS 0x0001
  572. /**
  573. * Raw packets from the demuxer, prior to parsing and decoding.
  574. * This buffer is used for buffering packets until the codec can
  575. * be identified, as parsing cannot be done without knowing the
  576. * codec.
  577. */
  578. struct AVPacketList *raw_packet_buffer;
  579. struct AVPacketList *raw_packet_buffer_end;
  580. struct AVPacketList *packet_buffer_end;
  581. AVMetadata *metadata;
  582. /**
  583. * Remaining size available for raw_packet_buffer, in bytes.
  584. * NOT PART OF PUBLIC API
  585. */
  586. #define RAW_PACKET_BUFFER_SIZE 2500000
  587. int raw_packet_buffer_remaining_size;
  588. } AVFormatContext;
  589. typedef struct AVPacketList {
  590. AVPacket pkt;
  591. struct AVPacketList *next;
  592. } AVPacketList;
  593. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  594. extern AVInputFormat *first_iformat;
  595. extern AVOutputFormat *first_oformat;
  596. #endif
  597. /**
  598. * If f is NULL, returns the first registered input format,
  599. * if f is non-NULL, returns the next registered input format after f
  600. * or NULL if f is the last one.
  601. */
  602. AVInputFormat *av_iformat_next(AVInputFormat *f);
  603. /**
  604. * If f is NULL, returns the first registered output format,
  605. * if f is non-NULL, returns the next registered output format after f
  606. * or NULL if f is the last one.
  607. */
  608. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  609. enum CodecID av_guess_image2_codec(const char *filename);
  610. /* XXX: Use automatic init with either ELF sections or C file parser */
  611. /* modules. */
  612. /* utils.c */
  613. void av_register_input_format(AVInputFormat *format);
  614. void av_register_output_format(AVOutputFormat *format);
  615. #if LIBAVFORMAT_VERSION_MAJOR < 53
  616. attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
  617. const char *filename,
  618. const char *mime_type);
  619. /**
  620. * @deprecated Use av_guess_format() instead.
  621. */
  622. attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
  623. const char *filename,
  624. const char *mime_type);
  625. #endif
  626. /**
  627. * Returns the output format in the list of registered output formats
  628. * which best matches the provided parameters, or returns NULL if
  629. * there is no match.
  630. *
  631. * @param short_name if non-NULL checks if short_name matches with the
  632. * names of the registered formats
  633. * @param filename if non-NULL checks if filename terminates with the
  634. * extensions of the registered formats
  635. * @param mime_type if non-NULL checks if mime_type matches with the
  636. * MIME type of the registered formats
  637. */
  638. AVOutputFormat *av_guess_format(const char *short_name,
  639. const char *filename,
  640. const char *mime_type);
  641. /**
  642. * Guesses the codec ID based upon muxer and filename.
  643. */
  644. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  645. const char *filename, const char *mime_type,
  646. enum CodecType type);
  647. /**
  648. * Sends a nice hexadecimal dump of a buffer to the specified file stream.
  649. *
  650. * @param f The file stream pointer where the dump should be sent to.
  651. * @param buf buffer
  652. * @param size buffer size
  653. *
  654. * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
  655. */
  656. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  657. /**
  658. * Sends a nice hexadecimal dump of a buffer to the log.
  659. *
  660. * @param avcl A pointer to an arbitrary struct of which the first field is a
  661. * pointer to an AVClass struct.
  662. * @param level The importance level of the message, lower values signifying
  663. * higher importance.
  664. * @param buf buffer
  665. * @param size buffer size
  666. *
  667. * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
  668. */
  669. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  670. /**
  671. * Sends a nice dump of a packet to the specified file stream.
  672. *
  673. * @param f The file stream pointer where the dump should be sent to.
  674. * @param pkt packet to dump
  675. * @param dump_payload True if the payload must be displayed, too.
  676. */
  677. void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  678. /**
  679. * Sends a nice dump of a packet to the log.
  680. *
  681. * @param avcl A pointer to an arbitrary struct of which the first field is a
  682. * pointer to an AVClass struct.
  683. * @param level The importance level of the message, lower values signifying
  684. * higher importance.
  685. * @param pkt packet to dump
  686. * @param dump_payload True if the payload must be displayed, too.
  687. */
  688. void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
  689. /**
  690. * Initializes libavformat and registers all the muxers, demuxers and
  691. * protocols. If you do not call this function, then you can select
  692. * exactly which formats you want to support.
  693. *
  694. * @see av_register_input_format()
  695. * @see av_register_output_format()
  696. * @see av_register_protocol()
  697. */
  698. void av_register_all(void);
  699. /** codec tag <-> codec id */
  700. enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  701. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
  702. /* media file input */
  703. /**
  704. * Finds AVInputFormat based on the short name of the input format.
  705. */
  706. AVInputFormat *av_find_input_format(const char *short_name);
  707. /**
  708. * Guesses the file format.
  709. *
  710. * @param is_opened Whether the file is already opened; determines whether
  711. * demuxers with or without AVFMT_NOFILE are probed.
  712. */
  713. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  714. /**
  715. * Allocates all the structures needed to read an input stream.
  716. * This does not open the needed codecs for decoding the stream[s].
  717. */
  718. int av_open_input_stream(AVFormatContext **ic_ptr,
  719. ByteIOContext *pb, const char *filename,
  720. AVInputFormat *fmt, AVFormatParameters *ap);
  721. /**
  722. * Opens a media file as input. The codecs are not opened. Only the file
  723. * header (if present) is read.
  724. *
  725. * @param ic_ptr The opened media file handle is put here.
  726. * @param filename filename to open
  727. * @param fmt If non-NULL, force the file format to use.
  728. * @param buf_size optional buffer size (zero if default is OK)
  729. * @param ap Additional parameters needed when opening the file
  730. * (NULL if default).
  731. * @return 0 if OK, AVERROR_xxx otherwise
  732. */
  733. int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  734. AVInputFormat *fmt,
  735. int buf_size,
  736. AVFormatParameters *ap);
  737. #if LIBAVFORMAT_VERSION_MAJOR < 53
  738. /**
  739. * @deprecated Use avformat_alloc_context() instead.
  740. */
  741. attribute_deprecated AVFormatContext *av_alloc_format_context(void);
  742. #endif
  743. /**
  744. * Allocates an AVFormatContext.
  745. * Can be freed with av_free() but do not forget to free everything you
  746. * explicitly allocated as well!
  747. */
  748. AVFormatContext *avformat_alloc_context(void);
  749. /**
  750. * Reads packets of a media file to get stream information. This
  751. * is useful for file formats with no headers such as MPEG. This
  752. * function also computes the real framerate in case of MPEG-2 repeat
  753. * frame mode.
  754. * The logical file position is not changed by this function;
  755. * examined packets may be buffered for later processing.
  756. *
  757. * @param ic media file handle
  758. * @return >=0 if OK, AVERROR_xxx on error
  759. * @todo Let the user decide somehow what information is needed so that
  760. * we do not waste time getting stuff the user does not need.
  761. */
  762. int av_find_stream_info(AVFormatContext *ic);
  763. /**
  764. * Reads a transport packet from a media file.
  765. *
  766. * This function is obsolete and should never be used.
  767. * Use av_read_frame() instead.
  768. *
  769. * @param s media file handle
  770. * @param pkt is filled
  771. * @return 0 if OK, AVERROR_xxx on error
  772. */
  773. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  774. /**
  775. * Returns the next frame of a stream.
  776. *
  777. * The returned packet is valid
  778. * until the next av_read_frame() or until av_close_input_file() and
  779. * must be freed with av_free_packet. For video, the packet contains
  780. * exactly one frame. For audio, it contains an integer number of
  781. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  782. * data). If the audio frames have a variable size (e.g. MPEG audio),
  783. * then it contains one frame.
  784. *
  785. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  786. * values in AVStream.time_base units (and guessed if the format cannot
  787. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  788. * has B-frames, so it is better to rely on pkt->dts if you do not
  789. * decompress the payload.
  790. *
  791. * @return 0 if OK, < 0 on error or end of file
  792. */
  793. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  794. /**
  795. * Seeks to the keyframe at timestamp.
  796. * 'timestamp' in 'stream_index'.
  797. * @param stream_index If stream_index is (-1), a default
  798. * stream is selected, and timestamp is automatically converted
  799. * from AV_TIME_BASE units to the stream specific time_base.
  800. * @param timestamp Timestamp in AVStream.time_base units
  801. * or, if no stream is specified, in AV_TIME_BASE units.
  802. * @param flags flags which select direction and seeking mode
  803. * @return >= 0 on success
  804. */
  805. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  806. int flags);
  807. /**
  808. * Seeks to timestamp ts.
  809. * Seeking will be done so that the point from which all active streams
  810. * can be presented successfully will be closest to ts and within min/max_ts.
  811. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  812. *
  813. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  814. * are the file position (this may not be supported by all demuxers).
  815. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  816. * in the stream with stream_index (this may not be supported by all demuxers).
  817. * Otherwise all timestamps are in units of the stream selected by stream_index
  818. * or if stream_index is -1, in AV_TIME_BASE units.
  819. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  820. * keyframes (this may not be supported by all demuxers).
  821. *
  822. * @param stream_index index of the stream which is used as time base reference
  823. * @param min_ts smallest acceptable timestamp
  824. * @param ts target timestamp
  825. * @param max_ts largest acceptable timestamp
  826. * @param flags flags
  827. * @returns >=0 on success, error code otherwise
  828. *
  829. * @NOTE This is part of the new seek API which is still under construction.
  830. * Thus do not use this yet. It may change at any time, do not expect
  831. * ABI compatibility yet!
  832. */
  833. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  834. /**
  835. * Starts playing a network-based stream (e.g. RTSP stream) at the
  836. * current position.
  837. */
  838. int av_read_play(AVFormatContext *s);
  839. /**
  840. * Pauses a network-based stream (e.g. RTSP stream).
  841. *
  842. * Use av_read_play() to resume it.
  843. */
  844. int av_read_pause(AVFormatContext *s);
  845. /**
  846. * Frees a AVFormatContext allocated by av_open_input_stream.
  847. * @param s context to free
  848. */
  849. void av_close_input_stream(AVFormatContext *s);
  850. /**
  851. * Closes a media file (but not its codecs).
  852. *
  853. * @param s media file handle
  854. */
  855. void av_close_input_file(AVFormatContext *s);
  856. /**
  857. * Adds a new stream to a media file.
  858. *
  859. * Can only be called in the read_header() function. If the flag
  860. * AVFMTCTX_NOHEADER is in the format context, then new streams
  861. * can be added in read_packet too.
  862. *
  863. * @param s media file handle
  864. * @param id file-format-dependent stream ID
  865. */
  866. AVStream *av_new_stream(AVFormatContext *s, int id);
  867. AVProgram *av_new_program(AVFormatContext *s, int id);
  868. /**
  869. * Adds a new chapter.
  870. * This function is NOT part of the public API
  871. * and should ONLY be used by demuxers.
  872. *
  873. * @param s media file handle
  874. * @param id unique ID for this chapter
  875. * @param start chapter start time in time_base units
  876. * @param end chapter end time in time_base units
  877. * @param title chapter title
  878. *
  879. * @return AVChapter or NULL on error
  880. */
  881. AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
  882. int64_t start, int64_t end, const char *title);
  883. /**
  884. * Sets the pts for a given stream.
  885. *
  886. * @param s stream
  887. * @param pts_wrap_bits number of bits effectively used by the pts
  888. * (used for wrap control, 33 is the value for MPEG)
  889. * @param pts_num numerator to convert to seconds (MPEG: 1)
  890. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  891. */
  892. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  893. unsigned int pts_num, unsigned int pts_den);
  894. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  895. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  896. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  897. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  898. int av_find_default_stream_index(AVFormatContext *s);
  899. /**
  900. * Gets the index for a specific timestamp.
  901. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  902. * to the timestamp which is <= the requested one, if backward
  903. * is 0, then it will be >=
  904. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  905. * @return < 0 if no such timestamp could be found
  906. */
  907. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  908. /**
  909. * Ensures the index uses less memory than the maximum specified in
  910. * AVFormatContext.max_index_size by discarding entries if it grows
  911. * too large.
  912. * This function is not part of the public API and should only be called
  913. * by demuxers.
  914. */
  915. void ff_reduce_index(AVFormatContext *s, int stream_index);
  916. /**
  917. * Adds an index entry into a sorted list. Updates the entry if the list
  918. * already contains it.
  919. *
  920. * @param timestamp timestamp in the time base of the given stream
  921. */
  922. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  923. int size, int distance, int flags);
  924. /**
  925. * Does a binary search using av_index_search_timestamp() and
  926. * AVCodec.read_timestamp().
  927. * This is not supposed to be called directly by a user application,
  928. * but by demuxers.
  929. * @param target_ts target timestamp in the time base of the given stream
  930. * @param stream_index stream number
  931. */
  932. int av_seek_frame_binary(AVFormatContext *s, int stream_index,
  933. int64_t target_ts, int flags);
  934. /**
  935. * Updates cur_dts of all streams based on the given timestamp and AVStream.
  936. *
  937. * Stream ref_st unchanged, others set cur_dts in their native time base.
  938. * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
  939. * @param timestamp new dts expressed in time_base of param ref_st
  940. * @param ref_st reference stream giving time_base of param timestamp
  941. */
  942. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  943. /**
  944. * Does a binary search using read_timestamp().
  945. * This is not supposed to be called directly by a user application,
  946. * but by demuxers.
  947. * @param target_ts target timestamp in the time base of the given stream
  948. * @param stream_index stream number
  949. */
  950. int64_t av_gen_search(AVFormatContext *s, int stream_index,
  951. int64_t target_ts, int64_t pos_min,
  952. int64_t pos_max, int64_t pos_limit,
  953. int64_t ts_min, int64_t ts_max,
  954. int flags, int64_t *ts_ret,
  955. int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  956. /** media file output */
  957. int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  958. /**
  959. * Allocates the stream private data and writes the stream header to an
  960. * output media file.
  961. *
  962. * @param s media file handle
  963. * @return 0 if OK, AVERROR_xxx on error
  964. */
  965. int av_write_header(AVFormatContext *s);
  966. /**
  967. * Writes a packet to an output media file.
  968. *
  969. * The packet shall contain one audio or video frame.
  970. * The packet must be correctly interleaved according to the container
  971. * specification, if not then av_interleaved_write_frame must be used.
  972. *
  973. * @param s media file handle
  974. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  975. dts/pts, ...
  976. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  977. */
  978. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  979. /**
  980. * Writes a packet to an output media file ensuring correct interleaving.
  981. *
  982. * The packet must contain one audio or video frame.
  983. * If the packets are already correctly interleaved, the application should
  984. * call av_write_frame() instead as it is slightly faster. It is also important
  985. * to keep in mind that completely non-interleaved input will need huge amounts
  986. * of memory to interleave with this, so it is preferable to interleave at the
  987. * demuxer level.
  988. *
  989. * @param s media file handle
  990. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  991. dts/pts, ...
  992. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  993. */
  994. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  995. /**
  996. * Interleaves a packet per dts in an output media file.
  997. *
  998. * Packets with pkt->destruct == av_destruct_packet will be freed inside this
  999. * function, so they cannot be used after it. Note that calling av_free_packet()
  1000. * on them is still safe.
  1001. *
  1002. * @param s media file handle
  1003. * @param out the interleaved packet will be output here
  1004. * @param in the input packet
  1005. * @param flush 1 if no further packets are available as input and all
  1006. * remaining packets should be output
  1007. * @return 1 if a packet was output, 0 if no packet could be output,
  1008. * < 0 if an error occurred
  1009. */
  1010. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1011. AVPacket *pkt, int flush);
  1012. /**
  1013. * Writes the stream trailer to an output media file and frees the
  1014. * file private data.
  1015. *
  1016. * May only be called after a successful call to av_write_header.
  1017. *
  1018. * @param s media file handle
  1019. * @return 0 if OK, AVERROR_xxx on error
  1020. */
  1021. int av_write_trailer(AVFormatContext *s);
  1022. void dump_format(AVFormatContext *ic,
  1023. int index,
  1024. const char *url,
  1025. int is_output);
  1026. #if LIBAVFORMAT_VERSION_MAJOR < 53
  1027. /**
  1028. * Parses width and height out of string str.
  1029. * @deprecated Use av_parse_video_frame_size instead.
  1030. */
  1031. attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
  1032. const char *str);
  1033. /**
  1034. * Converts framerate from a string to a fraction.
  1035. * @deprecated Use av_parse_video_frame_rate instead.
  1036. */
  1037. attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
  1038. const char *arg);
  1039. #endif
  1040. /**
  1041. * Parses datestr and returns a corresponding number of microseconds.
  1042. * @param datestr String representing a date or a duration.
  1043. * - If a date the syntax is:
  1044. * @code
  1045. * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
  1046. * @endcode
  1047. * Time is local time unless Z is appended, in which case it is
  1048. * interpreted as UTC.
  1049. * If the year-month-day part is not specified it takes the current
  1050. * year-month-day.
  1051. * Returns the number of microseconds since 1st of January, 1970 up to
  1052. * the time of the parsed date or INT64_MIN if datestr cannot be
  1053. * successfully parsed.
  1054. * - If a duration the syntax is:
  1055. * @code
  1056. * [-]HH[:MM[:SS[.m...]]]
  1057. * [-]S+[.m...]
  1058. * @endcode
  1059. * Returns the number of microseconds contained in a time interval
  1060. * with the specified duration or INT64_MIN if datestr cannot be
  1061. * successfully parsed.
  1062. * @param duration Flag which tells how to interpret datestr, if
  1063. * not zero datestr is interpreted as a duration, otherwise as a
  1064. * date.
  1065. */
  1066. int64_t parse_date(const char *datestr, int duration);
  1067. /** Gets the current time in microseconds. */
  1068. int64_t av_gettime(void);
  1069. /* ffm-specific for ffserver */
  1070. #define FFM_PACKET_SIZE 4096
  1071. int64_t ffm_read_write_index(int fd);
  1072. int ffm_write_write_index(int fd, int64_t pos);
  1073. void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
  1074. /**
  1075. * Attempts to find a specific tag in a URL.
  1076. *
  1077. * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
  1078. * Return 1 if found.
  1079. */
  1080. int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  1081. /**
  1082. * Returns in 'buf' the path with '%d' replaced by a number.
  1083. *
  1084. * Also handles the '%0nd' format where 'n' is the total number
  1085. * of digits and '%%'.
  1086. *
  1087. * @param buf destination buffer
  1088. * @param buf_size destination buffer size
  1089. * @param path numbered sequence string
  1090. * @param number frame number
  1091. * @return 0 if OK, -1 on format error
  1092. */
  1093. int av_get_frame_filename(char *buf, int buf_size,
  1094. const char *path, int number);
  1095. /**
  1096. * Checks whether filename actually is a numbered sequence generator.
  1097. *
  1098. * @param filename possible numbered sequence string
  1099. * @return 1 if a valid numbered sequence string, 0 otherwise
  1100. */
  1101. int av_filename_number_test(const char *filename);
  1102. /**
  1103. * Generates an SDP for an RTP session.
  1104. *
  1105. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1106. * array is composed by only one context, such context can contain
  1107. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1108. * all the contexts in the array (an AVCodecContext per RTP stream)
  1109. * must contain only one AVStream.
  1110. * @param n_files number of AVCodecContexts contained in ac
  1111. * @param buff buffer where the SDP will be stored (must be allocated by
  1112. * the caller)
  1113. * @param size the size of the buffer
  1114. * @return 0 if OK, AVERROR_xxx on error
  1115. */
  1116. int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  1117. #ifdef HAVE_AV_CONFIG_H
  1118. void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
  1119. #ifdef __GNUC__
  1120. #define dynarray_add(tab, nb_ptr, elem)\
  1121. do {\
  1122. __typeof__(tab) _tab = (tab);\
  1123. __typeof__(elem) _elem = (elem);\
  1124. (void)sizeof(**_tab == _elem); /* check that types are compatible */\
  1125. ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
  1126. } while(0)
  1127. #else
  1128. #define dynarray_add(tab, nb_ptr, elem)\
  1129. do {\
  1130. ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
  1131. } while(0)
  1132. #endif
  1133. time_t mktimegm(struct tm *tm);
  1134. struct tm *brktimegm(time_t secs, struct tm *tm);
  1135. const char *small_strptime(const char *p, const char *fmt,
  1136. struct tm *dt);
  1137. struct in_addr;
  1138. int resolve_host(struct in_addr *sin_addr, const char *hostname);
  1139. void url_split(char *proto, int proto_size,
  1140. char *authorization, int authorization_size,
  1141. char *hostname, int hostname_size,
  1142. int *port_ptr,
  1143. char *path, int path_size,
  1144. const char *url);
  1145. /**
  1146. * Returns a positive value if the given filename has one of the given
  1147. * extensions, 0 otherwise.
  1148. *
  1149. * @param extensions a comma-separated list of filename extensions
  1150. */
  1151. int match_ext(const char *filename, const char *extensions);
  1152. #endif /* HAVE_AV_CONFIG_H */
  1153. #endif /* AVFORMAT_AVFORMAT_H */