avformat.h 50 KB

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