avformat.h 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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. /**
  23. * Return the LIBAVFORMAT_VERSION_INT constant.
  24. */
  25. unsigned avformat_version(void);
  26. /**
  27. * Return the libavformat build-time configuration.
  28. */
  29. const char *avformat_configuration(void);
  30. /**
  31. * Return the libavformat license.
  32. */
  33. const char *avformat_license(void);
  34. #include <time.h>
  35. #include <stdio.h> /* FILE */
  36. #include "libavcodec/avcodec.h"
  37. #include "libavutil/dict.h"
  38. #include "avio.h"
  39. #include "libavformat/version.h"
  40. struct AVFormatContext;
  41. /**
  42. * @defgroup metadata_api Public Metadata API
  43. * @{
  44. * The metadata API allows libavformat to export metadata tags to a client
  45. * application using a sequence of key/value pairs. Like all strings in FFmpeg,
  46. * metadata must be stored as UTF-8 encoded Unicode. Note that metadata
  47. * exported by demuxers isn't checked to be valid UTF-8 in most cases.
  48. * Important concepts to keep in mind:
  49. * - Keys are unique; there can never be 2 tags with the same key. This is
  50. * also meant semantically, i.e., a demuxer should not knowingly produce
  51. * several keys that are literally different but semantically identical.
  52. * E.g., key=Author5, key=Author6. In this example, all authors must be
  53. * placed in the same tag.
  54. * - Metadata is flat, not hierarchical; there are no subtags. If you
  55. * want to store, e.g., the email address of the child of producer Alice
  56. * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
  57. * - Several modifiers can be applied to the tag name. This is done by
  58. * appending a dash character ('-') and the modifier name in the order
  59. * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
  60. * - language -- a tag whose value is localized for a particular language
  61. * is appended with the ISO 639-2/B 3-letter language code.
  62. * For example: Author-ger=Michael, Author-eng=Mike
  63. * The original/default language is in the unqualified "Author" tag.
  64. * A demuxer should set a default if it sets any translated tag.
  65. * - sorting -- a modified version of a tag that should be used for
  66. * sorting will have '-sort' appended. E.g. artist="The Beatles",
  67. * artist-sort="Beatles, The".
  68. *
  69. * - Demuxers attempt to export metadata in a generic format, however tags
  70. * with no generic equivalents are left as they are stored in the container.
  71. * Follows a list of generic tag names:
  72. *
  73. @verbatim
  74. album -- name of the set this work belongs to
  75. album_artist -- main creator of the set/album, if different from artist.
  76. e.g. "Various Artists" for compilation albums.
  77. artist -- main creator of the work
  78. comment -- any additional description of the file.
  79. composer -- who composed the work, if different from artist.
  80. copyright -- name of copyright holder.
  81. creation_time-- date when the file was created, preferably in ISO 8601.
  82. date -- date when the work was created, preferably in ISO 8601.
  83. disc -- number of a subset, e.g. disc in a multi-disc collection.
  84. encoder -- name/settings of the software/hardware that produced the file.
  85. encoded_by -- person/group who created the file.
  86. filename -- original name of the file.
  87. genre -- <self-evident>.
  88. language -- main language in which the work is performed, preferably
  89. in ISO 639-2 format. Multiple languages can be specified by
  90. separating them with commas.
  91. performer -- artist who performed the work, if different from artist.
  92. E.g for "Also sprach Zarathustra", artist would be "Richard
  93. Strauss" and performer "London Philharmonic Orchestra".
  94. publisher -- name of the label/publisher.
  95. service_name -- name of the service in broadcasting (channel name).
  96. service_provider -- name of the service provider in broadcasting.
  97. title -- name of the work.
  98. track -- number of this work in the set, can be in form current/total.
  99. variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
  100. @endverbatim
  101. *
  102. * Look in the examples section for an application example how to use the Metadata API.
  103. *
  104. * @}
  105. */
  106. #if FF_API_OLD_METADATA2
  107. /**
  108. * @defgroup old_metadata Old metadata API
  109. * The following functions are deprecated, use
  110. * their equivalents from libavutil/dict.h instead.
  111. * @{
  112. */
  113. #define AV_METADATA_MATCH_CASE AV_DICT_MATCH_CASE
  114. #define AV_METADATA_IGNORE_SUFFIX AV_DICT_IGNORE_SUFFIX
  115. #define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY
  116. #define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL
  117. #define AV_METADATA_DONT_OVERWRITE AV_DICT_DONT_OVERWRITE
  118. typedef attribute_deprecated AVDictionary AVMetadata;
  119. typedef attribute_deprecated AVDictionaryEntry AVMetadataTag;
  120. typedef struct AVMetadataConv AVMetadataConv;
  121. /**
  122. * Get a metadata element with matching key.
  123. *
  124. * @param prev Set to the previous matching element to find the next.
  125. * If set to NULL the first matching element is returned.
  126. * @param flags Allows case as well as suffix-insensitive comparisons.
  127. * @return Found tag or NULL, changing key or value leads to undefined behavior.
  128. */
  129. attribute_deprecated AVDictionaryEntry *
  130. av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags);
  131. /**
  132. * Set the given tag in *pm, overwriting an existing tag.
  133. *
  134. * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
  135. * a metadata struct is allocated and put in *pm.
  136. * @param key tag key to add to *pm (will be av_strduped depending on flags)
  137. * @param value tag value to add to *pm (will be av_strduped depending on flags).
  138. * Passing a NULL value will cause an existing tag to be deleted.
  139. * @return >= 0 on success otherwise an error code <0
  140. */
  141. attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags);
  142. /**
  143. * This function is provided for compatibility reason and currently does nothing.
  144. */
  145. attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
  146. const AVMetadataConv *s_conv);
  147. /**
  148. * Copy metadata from one AVDictionary struct into another.
  149. * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
  150. * this function will allocate a struct for you and put it in *dst
  151. * @param src pointer to source AVDictionary struct
  152. * @param flags flags to use when setting metadata in *dst
  153. * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag
  154. */
  155. attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags);
  156. /**
  157. * Free all the memory allocated for an AVDictionary struct.
  158. */
  159. attribute_deprecated void av_metadata_free(AVDictionary **m);
  160. /**
  161. * @}
  162. */
  163. #endif
  164. /* packet functions */
  165. /**
  166. * Allocate and read the payload of a packet and initialize its
  167. * fields with default values.
  168. *
  169. * @param pkt packet
  170. * @param size desired payload size
  171. * @return >0 (read size) if OK, AVERROR_xxx otherwise
  172. */
  173. int av_get_packet(AVIOContext *s, AVPacket *pkt, int size);
  174. /**
  175. * Read data and append it to the current content of the AVPacket.
  176. * If pkt->size is 0 this is identical to av_get_packet.
  177. * Note that this uses av_grow_packet and thus involves a realloc
  178. * which is inefficient. Thus this function should only be used
  179. * when there is no reasonable way to know (an upper bound of)
  180. * the final size.
  181. *
  182. * @param pkt packet
  183. * @param size amount of data to read
  184. * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
  185. * will not be lost even if an error occurs.
  186. */
  187. int av_append_packet(AVIOContext *s, AVPacket *pkt, int size);
  188. /*************************************************/
  189. /* fractional numbers for exact pts handling */
  190. /**
  191. * The exact value of the fractional number is: 'val + num / den'.
  192. * num is assumed to be 0 <= num < den.
  193. */
  194. typedef struct AVFrac {
  195. int64_t val, num, den;
  196. } AVFrac;
  197. /*************************************************/
  198. /* input/output formats */
  199. struct AVCodecTag;
  200. /**
  201. * This structure contains the data a format has to probe a file.
  202. */
  203. typedef struct AVProbeData {
  204. const char *filename;
  205. unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
  206. int buf_size; /**< Size of buf except extra allocated bytes */
  207. } AVProbeData;
  208. #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
  209. #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
  210. typedef struct AVFormatParameters {
  211. #if FF_API_FORMAT_PARAMETERS
  212. attribute_deprecated AVRational time_base;
  213. attribute_deprecated int sample_rate;
  214. attribute_deprecated int channels;
  215. attribute_deprecated int width;
  216. attribute_deprecated int height;
  217. attribute_deprecated enum PixelFormat pix_fmt;
  218. attribute_deprecated int channel; /**< Used to select DV channel. */
  219. attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */
  220. attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */
  221. /**< deprecated, use mpegtsraw demuxer-specific options instead */
  222. attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
  223. attribute_deprecated unsigned int initial_pause:1; /**< Do not begin to play the stream
  224. immediately (RTSP only). */
  225. attribute_deprecated unsigned int prealloced_context:1;
  226. #endif
  227. } AVFormatParameters;
  228. //! Demuxer will use avio_open, no opened file should be provided by the caller.
  229. #define AVFMT_NOFILE 0x0001
  230. #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
  231. #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
  232. #define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
  233. raw picture data. */
  234. #define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
  235. #define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
  236. #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
  237. #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
  238. #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
  239. #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */
  240. #define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */
  241. #define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */
  242. #define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */
  243. #define AVFMT_TS_NONSTRICT 0x8000 /**< Format does not require strictly
  244. increasing timestamps, but they must
  245. still be monotonic */
  246. typedef struct AVOutputFormat {
  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. const char *mime_type;
  255. const char *extensions; /**< comma-separated filename extensions */
  256. /**
  257. * size of private data so that it can be allocated in the wrapper
  258. */
  259. int priv_data_size;
  260. /* output support */
  261. enum CodecID audio_codec; /**< default audio codec */
  262. enum CodecID video_codec; /**< default video codec */
  263. int (*write_header)(struct AVFormatContext *);
  264. int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
  265. int (*write_trailer)(struct AVFormatContext *);
  266. /**
  267. * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE,
  268. * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
  269. * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS
  270. */
  271. int flags;
  272. void *dummy;
  273. int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
  274. AVPacket *in, int flush);
  275. /**
  276. * List of supported codec_id-codec_tag pairs, ordered by "better
  277. * choice first". The arrays are all terminated by CODEC_ID_NONE.
  278. */
  279. const struct AVCodecTag * const *codec_tag;
  280. enum CodecID subtitle_codec; /**< default subtitle codec */
  281. #if FF_API_OLD_METADATA2
  282. const AVMetadataConv *metadata_conv;
  283. #endif
  284. const AVClass *priv_class; ///< AVClass for the private context
  285. /* private fields */
  286. struct AVOutputFormat *next;
  287. } AVOutputFormat;
  288. typedef struct AVInputFormat {
  289. /**
  290. * A comma separated list of short names for the format. New names
  291. * may be appended with a minor bump.
  292. */
  293. const char *name;
  294. /**
  295. * Descriptive name for the format, meant to be more human-readable
  296. * than name. You should use the NULL_IF_CONFIG_SMALL() macro
  297. * to define it.
  298. */
  299. const char *long_name;
  300. /**
  301. * Size of private data so that it can be allocated in the wrapper.
  302. */
  303. int priv_data_size;
  304. /**
  305. * Tell if a given file has a chance of being parsed as this format.
  306. * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
  307. * big so you do not have to check for that unless you need more.
  308. */
  309. int (*read_probe)(AVProbeData *);
  310. /**
  311. * Read the format header and initialize the AVFormatContext
  312. * structure. Return 0 if OK. 'ap' if non-NULL contains
  313. * additional parameters. Only used in raw format right
  314. * now. 'av_new_stream' should be called to create new streams.
  315. */
  316. int (*read_header)(struct AVFormatContext *,
  317. AVFormatParameters *ap);
  318. /**
  319. * Read one packet and put it in 'pkt'. pts and flags are also
  320. * set. 'av_new_stream' can be called only if the flag
  321. * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
  322. * background thread).
  323. * @return 0 on success, < 0 on error.
  324. * When returning an error, pkt must not have been allocated
  325. * or must be freed before returning
  326. */
  327. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  328. /**
  329. * Close the stream. The AVFormatContext and AVStreams are not
  330. * freed by this function
  331. */
  332. int (*read_close)(struct AVFormatContext *);
  333. #if FF_API_READ_SEEK
  334. /**
  335. * Seek to a given timestamp relative to the frames in
  336. * stream component stream_index.
  337. * @param stream_index Must not be -1.
  338. * @param flags Selects which direction should be preferred if no exact
  339. * match is available.
  340. * @return >= 0 on success (but not necessarily the new offset)
  341. */
  342. attribute_deprecated int (*read_seek)(struct AVFormatContext *,
  343. int stream_index, int64_t timestamp, int flags);
  344. #endif
  345. /**
  346. * Gets the next timestamp in stream[stream_index].time_base units.
  347. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  348. */
  349. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  350. int64_t *pos, int64_t pos_limit);
  351. /**
  352. * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
  353. */
  354. int flags;
  355. /**
  356. * If extensions are defined, then no probe is done. You should
  357. * usually not use extension format guessing because it is not
  358. * reliable enough
  359. */
  360. const char *extensions;
  361. /**
  362. * General purpose read-only value that the format can use.
  363. */
  364. int value;
  365. /**
  366. * Start/resume playing - only meaningful if using a network-based format
  367. * (RTSP).
  368. */
  369. int (*read_play)(struct AVFormatContext *);
  370. /**
  371. * Pause playing - only meaningful if using a network-based format
  372. * (RTSP).
  373. */
  374. int (*read_pause)(struct AVFormatContext *);
  375. const struct AVCodecTag * const *codec_tag;
  376. /**
  377. * Seek to timestamp ts.
  378. * Seeking will be done so that the point from which all active streams
  379. * can be presented successfully will be closest to ts and within min/max_ts.
  380. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  381. */
  382. int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  383. #if FF_API_OLD_METADATA2
  384. const AVMetadataConv *metadata_conv;
  385. #endif
  386. const AVClass *priv_class; ///< AVClass for the private context
  387. /* private fields */
  388. struct AVInputFormat *next;
  389. } AVInputFormat;
  390. enum AVStreamParseType {
  391. AVSTREAM_PARSE_NONE,
  392. AVSTREAM_PARSE_FULL, /**< full parsing and repack */
  393. AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
  394. AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
  395. AVSTREAM_PARSE_FULL_ONCE, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
  396. };
  397. typedef struct AVIndexEntry {
  398. int64_t pos;
  399. int64_t timestamp;
  400. #define AVINDEX_KEYFRAME 0x0001
  401. int flags:2;
  402. 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).
  403. int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
  404. } AVIndexEntry;
  405. #define AV_DISPOSITION_DEFAULT 0x0001
  406. #define AV_DISPOSITION_DUB 0x0002
  407. #define AV_DISPOSITION_ORIGINAL 0x0004
  408. #define AV_DISPOSITION_COMMENT 0x0008
  409. #define AV_DISPOSITION_LYRICS 0x0010
  410. #define AV_DISPOSITION_KARAOKE 0x0020
  411. /**
  412. * Track should be used during playback by default.
  413. * Useful for subtitle track that should be displayed
  414. * even when user did not explicitly ask for subtitles.
  415. */
  416. #define AV_DISPOSITION_FORCED 0x0040
  417. #define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */
  418. #define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */
  419. #define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */
  420. /**
  421. * Stream structure.
  422. * New fields can be added to the end with minor version bumps.
  423. * Removal, reordering and changes to existing fields require a major
  424. * version bump.
  425. * sizeof(AVStream) must not be used outside libav*.
  426. */
  427. typedef struct AVStream {
  428. int index; /**< stream index in AVFormatContext */
  429. int id; /**< format-specific stream ID */
  430. AVCodecContext *codec; /**< codec context */
  431. /**
  432. * Real base framerate of the stream.
  433. * This is the lowest framerate with which all timestamps can be
  434. * represented accurately (it is the least common multiple of all
  435. * framerates in the stream). Note, this value is just a guess!
  436. * For example, if the time base is 1/90000 and all frames have either
  437. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  438. */
  439. AVRational r_frame_rate;
  440. void *priv_data;
  441. /* internal data used in av_find_stream_info() */
  442. int64_t first_dts;
  443. /**
  444. * encoding: pts generation when outputting stream
  445. */
  446. struct AVFrac pts;
  447. /**
  448. * This is the fundamental unit of time (in seconds) in terms
  449. * of which frame timestamps are represented. For fixed-fps content,
  450. * time base should be 1/framerate and timestamp increments should be 1.
  451. * decoding: set by libavformat
  452. * encoding: set by libavformat in av_write_header
  453. */
  454. AVRational time_base;
  455. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  456. /* ffmpeg.c private use */
  457. int stream_copy; /**< If set, just copy stream. */
  458. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  459. //FIXME move stuff to a flags field?
  460. /**
  461. * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
  462. * MN: dunno if that is the right place for it
  463. */
  464. float quality;
  465. /**
  466. * Decoding: pts of the first frame of the stream, in stream time base.
  467. * Only set this if you are absolutely 100% sure that the value you set
  468. * it to really is the pts of the first frame.
  469. * This may be undefined (AV_NOPTS_VALUE).
  470. * @note The ASF header does NOT contain a correct start_time the ASF
  471. * demuxer must NOT set this.
  472. */
  473. int64_t start_time;
  474. /**
  475. * Decoding: duration of the stream, in stream time base.
  476. * If a source file does not specify a duration, but does specify
  477. * a bitrate, this value will be estimated from bitrate and file size.
  478. */
  479. int64_t duration;
  480. /* av_read_frame() support */
  481. enum AVStreamParseType need_parsing;
  482. struct AVCodecParserContext *parser;
  483. int64_t cur_dts;
  484. int last_IP_duration;
  485. int64_t last_IP_pts;
  486. /* av_seek_frame() support */
  487. AVIndexEntry *index_entries; /**< Only used if the format does not
  488. support seeking natively. */
  489. int nb_index_entries;
  490. unsigned int index_entries_allocated_size;
  491. int64_t nb_frames; ///< number of frames in this stream if known or 0
  492. int disposition; /**< AV_DISPOSITION_* bit field */
  493. AVProbeData probe_data;
  494. #define MAX_REORDER_DELAY 16
  495. int64_t pts_buffer[MAX_REORDER_DELAY+1];
  496. /**
  497. * sample aspect ratio (0 if unknown)
  498. * - encoding: Set by user.
  499. * - decoding: Set by libavformat.
  500. */
  501. AVRational sample_aspect_ratio;
  502. AVDictionary *metadata;
  503. /* Intended mostly for av_read_frame() support. Not supposed to be used by */
  504. /* external applications; try to use something else if at all possible. */
  505. const uint8_t *cur_ptr;
  506. int cur_len;
  507. AVPacket cur_pkt;
  508. // Timestamp generation support:
  509. /**
  510. * Timestamp corresponding to the last dts sync point.
  511. *
  512. * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
  513. * a DTS is received from the underlying container. Otherwise set to
  514. * AV_NOPTS_VALUE by default.
  515. */
  516. int64_t reference_dts;
  517. /**
  518. * Number of packets to buffer for codec probing
  519. * NOT PART OF PUBLIC API
  520. */
  521. #define MAX_PROBE_PACKETS 2500
  522. int probe_packets;
  523. /**
  524. * last packet in packet_buffer for this stream when muxing.
  525. * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
  526. */
  527. struct AVPacketList *last_in_packet_buffer;
  528. /**
  529. * Average framerate
  530. */
  531. AVRational avg_frame_rate;
  532. /**
  533. * Number of frames that have been demuxed during av_find_stream_info()
  534. */
  535. int codec_info_nb_frames;
  536. /**
  537. * Stream Identifier
  538. * This is the MPEG-TS stream identifier +1
  539. * 0 means unknown
  540. */
  541. int stream_identifier;
  542. /**
  543. * Stream informations used internally by av_find_stream_info()
  544. */
  545. #define MAX_STD_TIMEBASES (60*12+5)
  546. struct {
  547. int64_t last_dts;
  548. int64_t duration_gcd;
  549. int duration_count;
  550. double duration_error[MAX_STD_TIMEBASES];
  551. int64_t codec_info_duration;
  552. } *info;
  553. /**
  554. * flag to indicate that probing is requested
  555. * NOT PART OF PUBLIC API
  556. */
  557. int request_probe;
  558. } AVStream;
  559. #define AV_PROGRAM_RUNNING 1
  560. /**
  561. * New fields can be added to the end with minor version bumps.
  562. * Removal, reordering and changes to existing fields require a major
  563. * version bump.
  564. * sizeof(AVProgram) must not be used outside libav*.
  565. */
  566. typedef struct AVProgram {
  567. int id;
  568. int flags;
  569. enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
  570. unsigned int *stream_index;
  571. unsigned int nb_stream_indexes;
  572. AVDictionary *metadata;
  573. int program_num;
  574. int pmt_pid;
  575. int pcr_pid;
  576. } AVProgram;
  577. #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
  578. (streams are added dynamically) */
  579. typedef struct AVChapter {
  580. int id; ///< unique ID to identify the chapter
  581. AVRational time_base; ///< time base in which the start/end timestamps are specified
  582. int64_t start, end; ///< chapter start/end time in time_base units
  583. AVDictionary *metadata;
  584. } AVChapter;
  585. /**
  586. * Format I/O context.
  587. * New fields can be added to the end with minor version bumps.
  588. * Removal, reordering and changes to existing fields require a major
  589. * version bump.
  590. * sizeof(AVFormatContext) must not be used outside libav*.
  591. */
  592. typedef struct AVFormatContext {
  593. const AVClass *av_class; /**< Set by avformat_alloc_context. */
  594. /* Can only be iformat or oformat, not both at the same time. */
  595. struct AVInputFormat *iformat;
  596. struct AVOutputFormat *oformat;
  597. void *priv_data;
  598. AVIOContext *pb;
  599. unsigned int nb_streams;
  600. AVStream **streams;
  601. char filename[1024]; /**< input or output filename */
  602. /* stream info */
  603. int64_t timestamp;
  604. int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
  605. /* private data for pts handling (do not modify directly). */
  606. /**
  607. * This buffer is only needed when packets were already buffered but
  608. * not decoded, for example to get the codec parameters in MPEG
  609. * streams.
  610. */
  611. struct AVPacketList *packet_buffer;
  612. /**
  613. * Decoding: position of the first frame of the component, in
  614. * AV_TIME_BASE fractional seconds. NEVER set this value directly:
  615. * It is deduced from the AVStream values.
  616. */
  617. int64_t start_time;
  618. /**
  619. * Decoding: duration of the stream, in AV_TIME_BASE fractional
  620. * seconds. Only set this value if you know none of the individual stream
  621. * durations and also dont set any of them. This is deduced from the
  622. * AVStream values if not set.
  623. */
  624. int64_t duration;
  625. /**
  626. * decoding: total file size, 0 if unknown
  627. */
  628. int64_t file_size;
  629. /**
  630. * Decoding: total stream bitrate in bit/s, 0 if not
  631. * available. Never set it directly if the file_size and the
  632. * duration are known as FFmpeg can compute it automatically.
  633. */
  634. int bit_rate;
  635. /* av_read_frame() support */
  636. AVStream *cur_st;
  637. /* av_seek_frame() support */
  638. int64_t data_offset; /**< offset of the first packet */
  639. int mux_rate;
  640. unsigned int packet_size;
  641. int preload;
  642. int max_delay;
  643. #define AVFMT_NOOUTPUTLOOP -1
  644. #define AVFMT_INFINITEOUTPUTLOOP 0
  645. /**
  646. * number of times to loop output in formats that support it
  647. */
  648. int loop_output;
  649. int flags;
  650. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  651. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  652. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  653. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  654. #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
  655. #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
  656. #if FF_API_FLAG_RTP_HINT
  657. #define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead
  658. #endif
  659. #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
  660. #define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload
  661. #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
  662. #define AVFMT_FLAG_PRIV_OPT 0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is converted)
  663. #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Dont merge side data but keep it seperate.
  664. int loop_input;
  665. /**
  666. * decoding: size of data to probe; encoding: unused.
  667. */
  668. unsigned int probesize;
  669. /**
  670. * Maximum time (in AV_TIME_BASE units) during which the input should
  671. * be analyzed in av_find_stream_info().
  672. */
  673. int max_analyze_duration;
  674. const uint8_t *key;
  675. int keylen;
  676. unsigned int nb_programs;
  677. AVProgram **programs;
  678. /**
  679. * Forced video codec_id.
  680. * Demuxing: Set by user.
  681. */
  682. enum CodecID video_codec_id;
  683. /**
  684. * Forced audio codec_id.
  685. * Demuxing: Set by user.
  686. */
  687. enum CodecID audio_codec_id;
  688. /**
  689. * Forced subtitle codec_id.
  690. * Demuxing: Set by user.
  691. */
  692. enum CodecID subtitle_codec_id;
  693. /**
  694. * Maximum amount of memory in bytes to use for the index of each stream.
  695. * If the index exceeds this size, entries will be discarded as
  696. * needed to maintain a smaller size. This can lead to slower or less
  697. * accurate seeking (depends on demuxer).
  698. * Demuxers for which a full in-memory index is mandatory will ignore
  699. * this.
  700. * muxing : unused
  701. * demuxing: set by user
  702. */
  703. unsigned int max_index_size;
  704. /**
  705. * Maximum amount of memory in bytes to use for buffering frames
  706. * obtained from realtime capture devices.
  707. */
  708. unsigned int max_picture_buffer;
  709. unsigned int nb_chapters;
  710. AVChapter **chapters;
  711. /**
  712. * Flags to enable debugging.
  713. */
  714. int debug;
  715. #define FF_FDEBUG_TS 0x0001
  716. /**
  717. * Raw packets from the demuxer, prior to parsing and decoding.
  718. * This buffer is used for buffering packets until the codec can
  719. * be identified, as parsing cannot be done without knowing the
  720. * codec.
  721. */
  722. struct AVPacketList *raw_packet_buffer;
  723. struct AVPacketList *raw_packet_buffer_end;
  724. struct AVPacketList *packet_buffer_end;
  725. AVDictionary *metadata;
  726. /**
  727. * Remaining size available for raw_packet_buffer, in bytes.
  728. * NOT PART OF PUBLIC API
  729. */
  730. #define RAW_PACKET_BUFFER_SIZE 2500000
  731. int raw_packet_buffer_remaining_size;
  732. /**
  733. * Start time of the stream in real world time, in microseconds
  734. * since the unix epoch (00:00 1st January 1970). That is, pts=0
  735. * in the stream was captured at this real world time.
  736. * - encoding: Set by user.
  737. * - decoding: Unused.
  738. */
  739. int64_t start_time_realtime;
  740. /**
  741. * decoding: number of frames used to probe fps
  742. */
  743. int fps_probe_size;
  744. /**
  745. * Transport stream id.
  746. * This will be moved into demuxer private options. Thus no API/ABI compatibility
  747. */
  748. int ts_id;
  749. } AVFormatContext;
  750. typedef struct AVPacketList {
  751. AVPacket pkt;
  752. struct AVPacketList *next;
  753. } AVPacketList;
  754. /**
  755. * If f is NULL, returns the first registered input format,
  756. * if f is non-NULL, returns the next registered input format after f
  757. * or NULL if f is the last one.
  758. */
  759. AVInputFormat *av_iformat_next(AVInputFormat *f);
  760. /**
  761. * If f is NULL, returns the first registered output format,
  762. * if f is non-NULL, returns the next registered output format after f
  763. * or NULL if f is the last one.
  764. */
  765. AVOutputFormat *av_oformat_next(AVOutputFormat *f);
  766. #if FF_API_GUESS_IMG2_CODEC
  767. attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename);
  768. #endif
  769. /* XXX: Use automatic init with either ELF sections or C file parser */
  770. /* modules. */
  771. /* utils.c */
  772. void av_register_input_format(AVInputFormat *format);
  773. void av_register_output_format(AVOutputFormat *format);
  774. /**
  775. * Return the output format in the list of registered output formats
  776. * which best matches the provided parameters, or return NULL if
  777. * there is no match.
  778. *
  779. * @param short_name if non-NULL checks if short_name matches with the
  780. * names of the registered formats
  781. * @param filename if non-NULL checks if filename terminates with the
  782. * extensions of the registered formats
  783. * @param mime_type if non-NULL checks if mime_type matches with the
  784. * MIME type of the registered formats
  785. */
  786. AVOutputFormat *av_guess_format(const char *short_name,
  787. const char *filename,
  788. const char *mime_type);
  789. /**
  790. * Guess the codec ID based upon muxer and filename.
  791. */
  792. enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
  793. const char *filename, const char *mime_type,
  794. enum AVMediaType type);
  795. /**
  796. * Send a nice hexadecimal dump of a buffer to the specified file stream.
  797. *
  798. * @param f The file stream pointer where the dump should be sent to.
  799. * @param buf buffer
  800. * @param size buffer size
  801. *
  802. * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2
  803. */
  804. void av_hex_dump(FILE *f, uint8_t *buf, int size);
  805. /**
  806. * Send a nice hexadecimal dump of a buffer to the log.
  807. *
  808. * @param avcl A pointer to an arbitrary struct of which the first field is a
  809. * pointer to an AVClass struct.
  810. * @param level The importance level of the message, lower values signifying
  811. * higher importance.
  812. * @param buf buffer
  813. * @param size buffer size
  814. *
  815. * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2
  816. */
  817. void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
  818. /**
  819. * Send a nice dump of a packet to the specified file stream.
  820. *
  821. * @param f The file stream pointer where the dump should be sent to.
  822. * @param pkt packet to dump
  823. * @param dump_payload True if the payload must be displayed, too.
  824. * @param st AVStream that the packet belongs to
  825. */
  826. void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st);
  827. /**
  828. * Send a nice dump of a packet to the log.
  829. *
  830. * @param avcl A pointer to an arbitrary struct of which the first field is a
  831. * pointer to an AVClass struct.
  832. * @param level The importance level of the message, lower values signifying
  833. * higher importance.
  834. * @param pkt packet to dump
  835. * @param dump_payload True if the payload must be displayed, too.
  836. * @param st AVStream that the packet belongs to
  837. */
  838. void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload,
  839. AVStream *st);
  840. #if FF_API_PKT_DUMP
  841. attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
  842. attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt,
  843. int dump_payload);
  844. #endif
  845. /**
  846. * Initialize libavformat and register all the muxers, demuxers and
  847. * protocols. If you do not call this function, then you can select
  848. * exactly which formats you want to support.
  849. *
  850. * @see av_register_input_format()
  851. * @see av_register_output_format()
  852. * @see av_register_protocol()
  853. */
  854. void av_register_all(void);
  855. /**
  856. * Get the CodecID for the given codec tag tag.
  857. * If no codec id is found returns CODEC_ID_NONE.
  858. *
  859. * @param tags list of supported codec_id-codec_tag pairs, as stored
  860. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  861. */
  862. enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
  863. /**
  864. * Get the codec tag for the given codec id id.
  865. * If no codec tag is found returns 0.
  866. *
  867. * @param tags list of supported codec_id-codec_tag pairs, as stored
  868. * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
  869. */
  870. unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
  871. /* media file input */
  872. /**
  873. * Find AVInputFormat based on the short name of the input format.
  874. */
  875. AVInputFormat *av_find_input_format(const char *short_name);
  876. /**
  877. * Guess the file format.
  878. *
  879. * @param is_opened Whether the file is already opened; determines whether
  880. * demuxers with or without AVFMT_NOFILE are probed.
  881. */
  882. AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
  883. /**
  884. * Guess the file format.
  885. *
  886. * @param is_opened Whether the file is already opened; determines whether
  887. * demuxers with or without AVFMT_NOFILE are probed.
  888. * @param score_max A probe score larger that this is required to accept a
  889. * detection, the variable is set to the actual detection
  890. * score afterwards.
  891. * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
  892. * to retry with a larger probe buffer.
  893. */
  894. AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
  895. /**
  896. * Guess the file format.
  897. *
  898. * @param is_opened Whether the file is already opened; determines whether
  899. * demuxers with or without AVFMT_NOFILE are probed.
  900. * @param score_ret The score of the best detection.
  901. */
  902. AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret);
  903. /**
  904. * Probe a bytestream to determine the input format. Each time a probe returns
  905. * with a score that is too low, the probe buffer size is increased and another
  906. * attempt is made. When the maximum probe size is reached, the input format
  907. * with the highest score is returned.
  908. *
  909. * @param pb the bytestream to probe
  910. * @param fmt the input format is put here
  911. * @param filename the filename of the stream
  912. * @param logctx the log context
  913. * @param offset the offset within the bytestream to probe from
  914. * @param max_probe_size the maximum probe buffer size (zero for default)
  915. * @return 0 in case of success, a negative value corresponding to an
  916. * AVERROR code otherwise
  917. */
  918. int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt,
  919. const char *filename, void *logctx,
  920. unsigned int offset, unsigned int max_probe_size);
  921. #if FF_API_FORMAT_PARAMETERS
  922. /**
  923. * Allocate all the structures needed to read an input stream.
  924. * This does not open the needed codecs for decoding the stream[s].
  925. * @deprecated use avformat_open_input instead.
  926. */
  927. attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr,
  928. AVIOContext *pb, const char *filename,
  929. AVInputFormat *fmt, AVFormatParameters *ap);
  930. /**
  931. * Open a media file as input. The codecs are not opened. Only the file
  932. * header (if present) is read.
  933. *
  934. * @param ic_ptr The opened media file handle is put here.
  935. * @param filename filename to open
  936. * @param fmt If non-NULL, force the file format to use.
  937. * @param buf_size optional buffer size (zero if default is OK)
  938. * @param ap Additional parameters needed when opening the file
  939. * (NULL if default).
  940. * @return 0 if OK, AVERROR_xxx otherwise
  941. *
  942. * @deprecated use avformat_open_input instead.
  943. */
  944. attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
  945. AVInputFormat *fmt,
  946. int buf_size,
  947. AVFormatParameters *ap);
  948. #endif
  949. /**
  950. * Open an input stream and read the header. The codecs are not opened.
  951. * The stream must be closed with av_close_input_file().
  952. *
  953. * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context).
  954. * May be a pointer to NULL, in which case an AVFormatContext is allocated by this
  955. * function and written into ps.
  956. * Note that a user-supplied AVFormatContext will be freed on failure.
  957. * @param filename Name of the stream to open.
  958. * @param fmt If non-NULL, this parameter forces a specific input format.
  959. * Otherwise the format is autodetected.
  960. * @param options A dictionary filled with AVFormatContext and demuxer-private options.
  961. * On return this parameter will be destroyed and replaced with a dict containing
  962. * options that were not found. May be NULL.
  963. *
  964. * @return 0 on success, a negative AVERROR on failure.
  965. *
  966. * @note If you want to use custom IO, preallocate the format context and set its pb field.
  967. */
  968. int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
  969. int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap);
  970. /**
  971. * Allocate an AVFormatContext.
  972. * avformat_free_context() can be used to free the context and everything
  973. * allocated by the framework within it.
  974. */
  975. AVFormatContext *avformat_alloc_context(void);
  976. #if FF_API_ALLOC_OUTPUT_CONTEXT
  977. /**
  978. * @deprecated deprecated in favor of avformat_alloc_output_context2()
  979. */
  980. attribute_deprecated
  981. AVFormatContext *avformat_alloc_output_context(const char *format,
  982. AVOutputFormat *oformat,
  983. const char *filename);
  984. #endif
  985. /**
  986. * Allocate an AVFormatContext for an output format.
  987. * avformat_free_context() can be used to free the context and
  988. * everything allocated by the framework within it.
  989. *
  990. * @param *ctx is set to the created format context, or to NULL in
  991. * case of failure
  992. * @param oformat format to use for allocating the context, if NULL
  993. * format_name and filename are used instead
  994. * @param format_name the name of output format to use for allocating the
  995. * context, if NULL filename is used instead
  996. * @param filename the name of the filename to use for allocating the
  997. * context, may be NULL
  998. * @return >= 0 in case of success, a negative AVERROR code in case of
  999. * failure
  1000. */
  1001. int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat,
  1002. const char *format_name, const char *filename);
  1003. #if FF_API_FORMAT_PARAMETERS
  1004. /**
  1005. * Read packets of a media file to get stream information. This
  1006. * is useful for file formats with no headers such as MPEG. This
  1007. * function also computes the real framerate in case of MPEG-2 repeat
  1008. * frame mode.
  1009. * The logical file position is not changed by this function;
  1010. * examined packets may be buffered for later processing.
  1011. *
  1012. * @param ic media file handle
  1013. * @return >=0 if OK, AVERROR_xxx on error
  1014. * @todo Let the user decide somehow what information is needed so that
  1015. * we do not waste time getting stuff the user does not need.
  1016. *
  1017. * @deprecated use avformat_find_stream_info.
  1018. */
  1019. int av_find_stream_info(AVFormatContext *ic);
  1020. #endif
  1021. /**
  1022. * Read packets of a media file to get stream information. This
  1023. * is useful for file formats with no headers such as MPEG. This
  1024. * function also computes the real framerate in case of MPEG-2 repeat
  1025. * frame mode.
  1026. * The logical file position is not changed by this function;
  1027. * examined packets may be buffered for later processing.
  1028. *
  1029. * @param ic media file handle
  1030. * @param options If non-NULL, an ic.nb_streams long array of pointers to
  1031. * dictionaries, where i-th member contains options for
  1032. * codec corresponding to i-th stream.
  1033. * On return each dictionary will be filled with options that were not found.
  1034. * @return >=0 if OK, AVERROR_xxx on error
  1035. *
  1036. * @note this function isn't guaranteed to open all the codecs, so
  1037. * options being non-empty at return is a perfectly normal behavior.
  1038. *
  1039. * @todo Let the user decide somehow what information is needed so that
  1040. * we do not waste time getting stuff the user does not need.
  1041. */
  1042. int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
  1043. /**
  1044. * Find the "best" stream in the file.
  1045. * The best stream is determined according to various heuristics as the most
  1046. * likely to be what the user expects.
  1047. * If the decoder parameter is non-NULL, av_find_best_stream will find the
  1048. * default decoder for the stream's codec; streams for which no decoder can
  1049. * be found are ignored.
  1050. *
  1051. * @param ic media file handle
  1052. * @param type stream type: video, audio, subtitles, etc.
  1053. * @param wanted_stream_nb user-requested stream number,
  1054. * or -1 for automatic selection
  1055. * @param related_stream try to find a stream related (eg. in the same
  1056. * program) to this one, or -1 if none
  1057. * @param decoder_ret if non-NULL, returns the decoder for the
  1058. * selected stream
  1059. * @param flags flags; none are currently defined
  1060. * @return the non-negative stream number in case of success,
  1061. * AVERROR_STREAM_NOT_FOUND if no stream with the requested type
  1062. * could be found,
  1063. * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
  1064. * @note If av_find_best_stream returns successfully and decoder_ret is not
  1065. * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
  1066. */
  1067. int av_find_best_stream(AVFormatContext *ic,
  1068. enum AVMediaType type,
  1069. int wanted_stream_nb,
  1070. int related_stream,
  1071. AVCodec **decoder_ret,
  1072. int flags);
  1073. /**
  1074. * Read a transport packet from a media file.
  1075. *
  1076. * This function is obsolete and should never be used.
  1077. * Use av_read_frame() instead.
  1078. *
  1079. * @param s media file handle
  1080. * @param pkt is filled
  1081. * @return 0 if OK, AVERROR_xxx on error
  1082. */
  1083. int av_read_packet(AVFormatContext *s, AVPacket *pkt);
  1084. /**
  1085. * Return the next frame of a stream.
  1086. * This function returns what is stored in the file, and does not validate
  1087. * that what is there are valid frames for the decoder. It will split what is
  1088. * stored in the file into frames and return one for each call. It will not
  1089. * omit invalid data between valid frames so as to give the decoder the maximum
  1090. * information possible for decoding.
  1091. *
  1092. * The returned packet is valid
  1093. * until the next av_read_frame() or until av_close_input_file() and
  1094. * must be freed with av_free_packet. For video, the packet contains
  1095. * exactly one frame. For audio, it contains an integer number of
  1096. * frames if each frame has a known fixed size (e.g. PCM or ADPCM
  1097. * data). If the audio frames have a variable size (e.g. MPEG audio),
  1098. * then it contains one frame.
  1099. *
  1100. * pkt->pts, pkt->dts and pkt->duration are always set to correct
  1101. * values in AVStream.time_base units (and guessed if the format cannot
  1102. * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
  1103. * has B-frames, so it is better to rely on pkt->dts if you do not
  1104. * decompress the payload.
  1105. *
  1106. * @return 0 if OK, < 0 on error or end of file
  1107. */
  1108. int av_read_frame(AVFormatContext *s, AVPacket *pkt);
  1109. /**
  1110. * Seek to the keyframe at timestamp.
  1111. * 'timestamp' in 'stream_index'.
  1112. * @param stream_index If stream_index is (-1), a default
  1113. * stream is selected, and timestamp is automatically converted
  1114. * from AV_TIME_BASE units to the stream specific time_base.
  1115. * @param timestamp Timestamp in AVStream.time_base units
  1116. * or, if no stream is specified, in AV_TIME_BASE units.
  1117. * @param flags flags which select direction and seeking mode
  1118. * @return >= 0 on success
  1119. */
  1120. int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
  1121. int flags);
  1122. /**
  1123. * Seek to timestamp ts.
  1124. * Seeking will be done so that the point from which all active streams
  1125. * can be presented successfully will be closest to ts and within min/max_ts.
  1126. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  1127. *
  1128. * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
  1129. * are the file position (this may not be supported by all demuxers).
  1130. * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
  1131. * in the stream with stream_index (this may not be supported by all demuxers).
  1132. * Otherwise all timestamps are in units of the stream selected by stream_index
  1133. * or if stream_index is -1, in AV_TIME_BASE units.
  1134. * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
  1135. * keyframes (this may not be supported by all demuxers).
  1136. *
  1137. * @param stream_index index of the stream which is used as time base reference
  1138. * @param min_ts smallest acceptable timestamp
  1139. * @param ts target timestamp
  1140. * @param max_ts largest acceptable timestamp
  1141. * @param flags flags
  1142. * @return >=0 on success, error code otherwise
  1143. *
  1144. * @note This is part of the new seek API which is still under construction.
  1145. * Thus do not use this yet. It may change at any time, do not expect
  1146. * ABI compatibility yet!
  1147. */
  1148. int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  1149. /**
  1150. * Start playing a network-based stream (e.g. RTSP stream) at the
  1151. * current position.
  1152. */
  1153. int av_read_play(AVFormatContext *s);
  1154. /**
  1155. * Pause a network-based stream (e.g. RTSP stream).
  1156. *
  1157. * Use av_read_play() to resume it.
  1158. */
  1159. int av_read_pause(AVFormatContext *s);
  1160. /**
  1161. * Free a AVFormatContext allocated by av_open_input_stream.
  1162. * @param s context to free
  1163. */
  1164. void av_close_input_stream(AVFormatContext *s);
  1165. /**
  1166. * Close a media file (but not its codecs).
  1167. *
  1168. * @param s media file handle
  1169. */
  1170. void av_close_input_file(AVFormatContext *s);
  1171. /**
  1172. * Free an AVFormatContext and all its streams.
  1173. * @param s context to free
  1174. */
  1175. void avformat_free_context(AVFormatContext *s);
  1176. /**
  1177. * Add a new stream to a media file.
  1178. *
  1179. * Can only be called in the read_header() function. If the flag
  1180. * AVFMTCTX_NOHEADER is in the format context, then new streams
  1181. * can be added in read_packet too.
  1182. *
  1183. * @param s media file handle
  1184. * @param id file-format-dependent stream ID
  1185. */
  1186. AVStream *av_new_stream(AVFormatContext *s, int id);
  1187. AVProgram *av_new_program(AVFormatContext *s, int id);
  1188. /**
  1189. * Set the pts for a given stream. If the new values would be invalid
  1190. * (<= 0), it leaves the AVStream unchanged.
  1191. *
  1192. * @param s stream
  1193. * @param pts_wrap_bits number of bits effectively used by the pts
  1194. * (used for wrap control, 33 is the value for MPEG)
  1195. * @param pts_num numerator to convert to seconds (MPEG: 1)
  1196. * @param pts_den denominator to convert to seconds (MPEG: 90000)
  1197. */
  1198. void av_set_pts_info(AVStream *s, int pts_wrap_bits,
  1199. unsigned int pts_num, unsigned int pts_den);
  1200. #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
  1201. #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
  1202. #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
  1203. #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
  1204. int av_find_default_stream_index(AVFormatContext *s);
  1205. /**
  1206. * Get the index for a specific timestamp.
  1207. * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
  1208. * to the timestamp which is <= the requested one, if backward
  1209. * is 0, then it will be >=
  1210. * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
  1211. * @return < 0 if no such timestamp could be found
  1212. */
  1213. int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
  1214. /**
  1215. * Add an index entry into a sorted list. Update the entry if the list
  1216. * already contains it.
  1217. *
  1218. * @param timestamp timestamp in the time base of the given stream
  1219. */
  1220. int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
  1221. int size, int distance, int flags);
  1222. /**
  1223. * Perform a binary search using av_index_search_timestamp() and
  1224. * AVInputFormat.read_timestamp().
  1225. * This is not supposed to be called directly by a user application,
  1226. * but by demuxers.
  1227. * @param target_ts target timestamp in the time base of the given stream
  1228. * @param stream_index stream number
  1229. */
  1230. int av_seek_frame_binary(AVFormatContext *s, int stream_index,
  1231. int64_t target_ts, int flags);
  1232. /**
  1233. * Update cur_dts of all streams based on the given timestamp and AVStream.
  1234. *
  1235. * Stream ref_st unchanged, others set cur_dts in their native time base.
  1236. * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
  1237. * @param timestamp new dts expressed in time_base of param ref_st
  1238. * @param ref_st reference stream giving time_base of param timestamp
  1239. */
  1240. void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
  1241. /**
  1242. * Perform a binary search using read_timestamp().
  1243. * This is not supposed to be called directly by a user application,
  1244. * but by demuxers.
  1245. * @param target_ts target timestamp in the time base of the given stream
  1246. * @param stream_index stream number
  1247. */
  1248. int64_t av_gen_search(AVFormatContext *s, int stream_index,
  1249. int64_t target_ts, int64_t pos_min,
  1250. int64_t pos_max, int64_t pos_limit,
  1251. int64_t ts_min, int64_t ts_max,
  1252. int flags, int64_t *ts_ret,
  1253. int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
  1254. /**
  1255. * media file output
  1256. */
  1257. #if FF_API_FORMAT_PARAMETERS
  1258. /**
  1259. * @deprecated pass the options to avformat_write_header directly.
  1260. */
  1261. attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
  1262. #endif
  1263. /**
  1264. * Split a URL string into components.
  1265. *
  1266. * The pointers to buffers for storing individual components may be null,
  1267. * in order to ignore that component. Buffers for components not found are
  1268. * set to empty strings. If the port is not found, it is set to a negative
  1269. * value.
  1270. *
  1271. * @param proto the buffer for the protocol
  1272. * @param proto_size the size of the proto buffer
  1273. * @param authorization the buffer for the authorization
  1274. * @param authorization_size the size of the authorization buffer
  1275. * @param hostname the buffer for the host name
  1276. * @param hostname_size the size of the hostname buffer
  1277. * @param port_ptr a pointer to store the port number in
  1278. * @param path the buffer for the path
  1279. * @param path_size the size of the path buffer
  1280. * @param url the URL to split
  1281. */
  1282. void av_url_split(char *proto, int proto_size,
  1283. char *authorization, int authorization_size,
  1284. char *hostname, int hostname_size,
  1285. int *port_ptr,
  1286. char *path, int path_size,
  1287. const char *url);
  1288. /**
  1289. * Allocate the stream private data and write the stream header to
  1290. * an output media file.
  1291. *
  1292. * @param s Media file handle, must be allocated with avformat_alloc_context().
  1293. * Its oformat field must be set to the desired output format;
  1294. * Its pb field must be set to an already openened AVIOContext.
  1295. * @param options An AVDictionary filled with AVFormatContext and muxer-private options.
  1296. * On return this parameter will be destroyed and replaced with a dict containing
  1297. * options that were not found. May be NULL.
  1298. *
  1299. * @return 0 on success, negative AVERROR on failure.
  1300. *
  1301. * @see av_opt_find, av_dict_set, avio_open, av_oformat_next.
  1302. */
  1303. int avformat_write_header(AVFormatContext *s, AVDictionary **options);
  1304. #if FF_API_FORMAT_PARAMETERS
  1305. /**
  1306. * Allocate the stream private data and write the stream header to an
  1307. * output media file.
  1308. * @note: this sets stream time-bases, if possible to stream->codec->time_base
  1309. * but for some formats it might also be some other time base
  1310. *
  1311. * @param s media file handle
  1312. * @return 0 if OK, AVERROR_xxx on error
  1313. *
  1314. * @deprecated use avformat_write_header.
  1315. */
  1316. attribute_deprecated int av_write_header(AVFormatContext *s);
  1317. #endif
  1318. /**
  1319. * Write a packet to an output media file.
  1320. *
  1321. * The packet shall contain one audio or video frame.
  1322. * The packet must be correctly interleaved according to the container
  1323. * specification, if not then av_interleaved_write_frame must be used.
  1324. *
  1325. * @param s media file handle
  1326. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1327. dts/pts, ...
  1328. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1329. */
  1330. int av_write_frame(AVFormatContext *s, AVPacket *pkt);
  1331. /**
  1332. * Write a packet to an output media file ensuring correct interleaving.
  1333. *
  1334. * The packet must contain one audio or video frame.
  1335. * If the packets are already correctly interleaved, the application should
  1336. * call av_write_frame() instead as it is slightly faster. It is also important
  1337. * to keep in mind that completely non-interleaved input will need huge amounts
  1338. * of memory to interleave with this, so it is preferable to interleave at the
  1339. * demuxer level.
  1340. *
  1341. * @param s media file handle
  1342. * @param pkt The packet, which contains the stream_index, buf/buf_size,
  1343. dts/pts, ...
  1344. * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
  1345. */
  1346. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
  1347. /**
  1348. * Interleave a packet per dts in an output media file.
  1349. *
  1350. * Packets with pkt->destruct == av_destruct_packet will be freed inside this
  1351. * function, so they cannot be used after it. Note that calling av_free_packet()
  1352. * on them is still safe.
  1353. *
  1354. * @param s media file handle
  1355. * @param out the interleaved packet will be output here
  1356. * @param pkt the input packet
  1357. * @param flush 1 if no further packets are available as input and all
  1358. * remaining packets should be output
  1359. * @return 1 if a packet was output, 0 if no packet could be output,
  1360. * < 0 if an error occurred
  1361. */
  1362. int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  1363. AVPacket *pkt, int flush);
  1364. /**
  1365. * Write the stream trailer to an output media file and free the
  1366. * file private data.
  1367. *
  1368. * May only be called after a successful call to av_write_header.
  1369. *
  1370. * @param s media file handle
  1371. * @return 0 if OK, AVERROR_xxx on error
  1372. */
  1373. int av_write_trailer(AVFormatContext *s);
  1374. #if FF_API_DUMP_FORMAT
  1375. /**
  1376. * @deprecated Deprecated in favor of av_dump_format().
  1377. */
  1378. attribute_deprecated void dump_format(AVFormatContext *ic,
  1379. int index,
  1380. const char *url,
  1381. int is_output);
  1382. #endif
  1383. void av_dump_format(AVFormatContext *ic,
  1384. int index,
  1385. const char *url,
  1386. int is_output);
  1387. #if FF_API_PARSE_DATE
  1388. /**
  1389. * Parse datestr and return a corresponding number of microseconds.
  1390. *
  1391. * @param datestr String representing a date or a duration.
  1392. * See av_parse_time() for the syntax of the provided string.
  1393. * @deprecated in favor of av_parse_time()
  1394. */
  1395. attribute_deprecated
  1396. int64_t parse_date(const char *datestr, int duration);
  1397. #endif
  1398. /**
  1399. * Get the current time in microseconds.
  1400. */
  1401. int64_t av_gettime(void);
  1402. #if FF_API_FIND_INFO_TAG
  1403. /**
  1404. * @deprecated use av_find_info_tag in libavutil instead.
  1405. */
  1406. attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
  1407. #endif
  1408. /**
  1409. * Return in 'buf' the path with '%d' replaced by a number.
  1410. *
  1411. * Also handles the '%0nd' format where 'n' is the total number
  1412. * of digits and '%%'.
  1413. *
  1414. * @param buf destination buffer
  1415. * @param buf_size destination buffer size
  1416. * @param path numbered sequence string
  1417. * @param number frame number
  1418. * @return 0 if OK, -1 on format error
  1419. */
  1420. int av_get_frame_filename(char *buf, int buf_size,
  1421. const char *path, int number);
  1422. /**
  1423. * Check whether filename actually is a numbered sequence generator.
  1424. *
  1425. * @param filename possible numbered sequence string
  1426. * @return 1 if a valid numbered sequence string, 0 otherwise
  1427. */
  1428. int av_filename_number_test(const char *filename);
  1429. /**
  1430. * Generate an SDP for an RTP session.
  1431. *
  1432. * @param ac array of AVFormatContexts describing the RTP streams. If the
  1433. * array is composed by only one context, such context can contain
  1434. * multiple AVStreams (one AVStream per RTP stream). Otherwise,
  1435. * all the contexts in the array (an AVCodecContext per RTP stream)
  1436. * must contain only one AVStream.
  1437. * @param n_files number of AVCodecContexts contained in ac
  1438. * @param buf buffer where the SDP will be stored (must be allocated by
  1439. * the caller)
  1440. * @param size the size of the buffer
  1441. * @return 0 if OK, AVERROR_xxx on error
  1442. */
  1443. int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size);
  1444. #if FF_API_SDP_CREATE
  1445. attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
  1446. #endif
  1447. /**
  1448. * Return a positive value if the given filename has one of the given
  1449. * extensions, 0 otherwise.
  1450. *
  1451. * @param extensions a comma-separated list of filename extensions
  1452. */
  1453. int av_match_ext(const char *filename, const char *extensions);
  1454. #endif /* AVFORMAT_AVFORMAT_H */