Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

avformat.h 47 KiB

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