You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1484 lines
52KB

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