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.

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