avformat.h 40 KB

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