avformat.h 44 KB

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