avformat.h 50 KB

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