avformat.h 48 KB

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