avcodec.h 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087
  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 AVCODEC_AVCODEC_H
  21. #define AVCODEC_AVCODEC_H
  22. /**
  23. * @file
  24. * @ingroup libavc
  25. * Libavcodec external API header
  26. */
  27. #include "libavutil/samplefmt.h"
  28. #include "libavutil/attributes.h"
  29. #include "libavutil/avutil.h"
  30. #include "libavutil/buffer.h"
  31. #include "libavutil/channel_layout.h"
  32. #include "libavutil/dict.h"
  33. #include "libavutil/frame.h"
  34. #include "libavutil/log.h"
  35. #include "libavutil/pixfmt.h"
  36. #include "libavutil/rational.h"
  37. #include "codec.h"
  38. #include "codec_id.h"
  39. #include "defs.h"
  40. #include "packet.h"
  41. #include "version_major.h"
  42. #ifndef HAVE_AV_CONFIG_H
  43. /* When included as part of the ffmpeg build, only include the major version
  44. * to avoid unnecessary rebuilds. When included externally, keep including
  45. * the full version information. */
  46. #include "version.h"
  47. #include "codec_desc.h"
  48. #include "codec_par.h"
  49. #endif
  50. struct AVCodecParameters;
  51. /**
  52. * @defgroup libavc libavcodec
  53. * Encoding/Decoding Library
  54. *
  55. * @{
  56. *
  57. * @defgroup lavc_decoding Decoding
  58. * @{
  59. * @}
  60. *
  61. * @defgroup lavc_encoding Encoding
  62. * @{
  63. * @}
  64. *
  65. * @defgroup lavc_codec Codecs
  66. * @{
  67. * @defgroup lavc_codec_native Native Codecs
  68. * @{
  69. * @}
  70. * @defgroup lavc_codec_wrappers External library wrappers
  71. * @{
  72. * @}
  73. * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
  74. * @{
  75. * @}
  76. * @}
  77. * @defgroup lavc_internal Internal
  78. * @{
  79. * @}
  80. * @}
  81. */
  82. /**
  83. * @ingroup libavc
  84. * @defgroup lavc_encdec send/receive encoding and decoding API overview
  85. * @{
  86. *
  87. * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/
  88. * avcodec_receive_packet() functions provide an encode/decode API, which
  89. * decouples input and output.
  90. *
  91. * The API is very similar for encoding/decoding and audio/video, and works as
  92. * follows:
  93. * - Set up and open the AVCodecContext as usual.
  94. * - Send valid input:
  95. * - For decoding, call avcodec_send_packet() to give the decoder raw
  96. * compressed data in an AVPacket.
  97. * - For encoding, call avcodec_send_frame() to give the encoder an AVFrame
  98. * containing uncompressed audio or video.
  99. *
  100. * In both cases, it is recommended that AVPackets and AVFrames are
  101. * refcounted, or libavcodec might have to copy the input data. (libavformat
  102. * always returns refcounted AVPackets, and av_frame_get_buffer() allocates
  103. * refcounted AVFrames.)
  104. * - Receive output in a loop. Periodically call one of the avcodec_receive_*()
  105. * functions and process their output:
  106. * - For decoding, call avcodec_receive_frame(). On success, it will return
  107. * an AVFrame containing uncompressed audio or video data.
  108. * - For encoding, call avcodec_receive_packet(). On success, it will return
  109. * an AVPacket with a compressed frame.
  110. *
  111. * Repeat this call until it returns AVERROR(EAGAIN) or an error. The
  112. * AVERROR(EAGAIN) return value means that new input data is required to
  113. * return new output. In this case, continue with sending input. For each
  114. * input frame/packet, the codec will typically return 1 output frame/packet,
  115. * but it can also be 0 or more than 1.
  116. *
  117. * At the beginning of decoding or encoding, the codec might accept multiple
  118. * input frames/packets without returning a frame, until its internal buffers
  119. * are filled. This situation is handled transparently if you follow the steps
  120. * outlined above.
  121. *
  122. * In theory, sending input can result in EAGAIN - this should happen only if
  123. * not all output was received. You can use this to structure alternative decode
  124. * or encode loops other than the one suggested above. For example, you could
  125. * try sending new input on each iteration, and try to receive output if that
  126. * returns EAGAIN.
  127. *
  128. * End of stream situations. These require "flushing" (aka draining) the codec,
  129. * as the codec might buffer multiple frames or packets internally for
  130. * performance or out of necessity (consider B-frames).
  131. * This is handled as follows:
  132. * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding)
  133. * or avcodec_send_frame() (encoding) functions. This will enter draining
  134. * mode.
  135. * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet()
  136. * (encoding) in a loop until AVERROR_EOF is returned. The functions will
  137. * not return AVERROR(EAGAIN), unless you forgot to enter draining mode.
  138. * - Before decoding can be resumed again, the codec has to be reset with
  139. * avcodec_flush_buffers().
  140. *
  141. * Using the API as outlined above is highly recommended. But it is also
  142. * possible to call functions outside of this rigid schema. For example, you can
  143. * call avcodec_send_packet() repeatedly without calling
  144. * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed
  145. * until the codec's internal buffer has been filled up (which is typically of
  146. * size 1 per output frame, after initial input), and then reject input with
  147. * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to
  148. * read at least some output.
  149. *
  150. * Not all codecs will follow a rigid and predictable dataflow; the only
  151. * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on
  152. * one end implies that a receive/send call on the other end will succeed, or
  153. * at least will not fail with AVERROR(EAGAIN). In general, no codec will
  154. * permit unlimited buffering of input or output.
  155. *
  156. * A codec is not allowed to return AVERROR(EAGAIN) for both sending and receiving. This
  157. * would be an invalid state, which could put the codec user into an endless
  158. * loop. The API has no concept of time either: it cannot happen that trying to
  159. * do avcodec_send_packet() results in AVERROR(EAGAIN), but a repeated call 1 second
  160. * later accepts the packet (with no other receive/flush API calls involved).
  161. * The API is a strict state machine, and the passage of time is not supposed
  162. * to influence it. Some timing-dependent behavior might still be deemed
  163. * acceptable in certain cases. But it must never result in both send/receive
  164. * returning EAGAIN at the same time at any point. It must also absolutely be
  165. * avoided that the current state is "unstable" and can "flip-flop" between
  166. * the send/receive APIs allowing progress. For example, it's not allowed that
  167. * the codec randomly decides that it actually wants to consume a packet now
  168. * instead of returning a frame, after it just returned AVERROR(EAGAIN) on an
  169. * avcodec_send_packet() call.
  170. * @}
  171. */
  172. /**
  173. * @defgroup lavc_core Core functions/structures.
  174. * @ingroup libavc
  175. *
  176. * Basic definitions, functions for querying libavcodec capabilities,
  177. * allocating core structures, etc.
  178. * @{
  179. */
  180. #if FF_API_BUFFER_MIN_SIZE
  181. /**
  182. * @ingroup lavc_encoding
  183. * minimum encoding buffer size
  184. * Used to avoid some checks during header writing.
  185. * @deprecated Unused: avcodec_receive_packet() does not work
  186. * with preallocated packet buffers.
  187. */
  188. #define AV_INPUT_BUFFER_MIN_SIZE 16384
  189. #endif
  190. /**
  191. * @ingroup lavc_encoding
  192. */
  193. typedef struct RcOverride{
  194. int start_frame;
  195. int end_frame;
  196. int qscale; // If this is 0 then quality_factor will be used instead.
  197. float quality_factor;
  198. } RcOverride;
  199. /* encoding support
  200. These flags can be passed in AVCodecContext.flags before initialization.
  201. Note: Not everything is supported yet.
  202. */
  203. /**
  204. * Allow decoders to produce frames with data planes that are not aligned
  205. * to CPU requirements (e.g. due to cropping).
  206. */
  207. #define AV_CODEC_FLAG_UNALIGNED (1 << 0)
  208. /**
  209. * Use fixed qscale.
  210. */
  211. #define AV_CODEC_FLAG_QSCALE (1 << 1)
  212. /**
  213. * 4 MV per MB allowed / advanced prediction for H.263.
  214. */
  215. #define AV_CODEC_FLAG_4MV (1 << 2)
  216. /**
  217. * Output even those frames that might be corrupted.
  218. */
  219. #define AV_CODEC_FLAG_OUTPUT_CORRUPT (1 << 3)
  220. /**
  221. * Use qpel MC.
  222. */
  223. #define AV_CODEC_FLAG_QPEL (1 << 4)
  224. #if FF_API_DROPCHANGED
  225. /**
  226. * Don't output frames whose parameters differ from first
  227. * decoded frame in stream.
  228. *
  229. * @deprecated callers should implement this functionality in their own code
  230. */
  231. #define AV_CODEC_FLAG_DROPCHANGED (1 << 5)
  232. #endif
  233. /**
  234. * Request the encoder to output reconstructed frames, i.e.\ frames that would
  235. * be produced by decoding the encoded bistream. These frames may be retrieved
  236. * by calling avcodec_receive_frame() immediately after a successful call to
  237. * avcodec_receive_packet().
  238. *
  239. * Should only be used with encoders flagged with the
  240. * @ref AV_CODEC_CAP_ENCODER_RECON_FRAME capability.
  241. *
  242. * @note
  243. * Each reconstructed frame returned by the encoder corresponds to the last
  244. * encoded packet, i.e. the frames are returned in coded order rather than
  245. * presentation order.
  246. *
  247. * @note
  248. * Frame parameters (like pixel format or dimensions) do not have to match the
  249. * AVCodecContext values. Make sure to use the values from the returned frame.
  250. */
  251. #define AV_CODEC_FLAG_RECON_FRAME (1 << 6)
  252. /**
  253. * @par decoding
  254. * Request the decoder to propagate each packet's AVPacket.opaque and
  255. * AVPacket.opaque_ref to its corresponding output AVFrame.
  256. *
  257. * @par encoding:
  258. * Request the encoder to propagate each frame's AVFrame.opaque and
  259. * AVFrame.opaque_ref values to its corresponding output AVPacket.
  260. *
  261. * @par
  262. * May only be set on encoders that have the
  263. * @ref AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability flag.
  264. *
  265. * @note
  266. * While in typical cases one input frame produces exactly one output packet
  267. * (perhaps after a delay), in general the mapping of frames to packets is
  268. * M-to-N, so
  269. * - Any number of input frames may be associated with any given output packet.
  270. * This includes zero - e.g. some encoders may output packets that carry only
  271. * metadata about the whole stream.
  272. * - A given input frame may be associated with any number of output packets.
  273. * Again this includes zero - e.g. some encoders may drop frames under certain
  274. * conditions.
  275. * .
  276. * This implies that when using this flag, the caller must NOT assume that
  277. * - a given input frame's opaques will necessarily appear on some output packet;
  278. * - every output packet will have some non-NULL opaque value.
  279. * .
  280. * When an output packet contains multiple frames, the opaque values will be
  281. * taken from the first of those.
  282. *
  283. * @note
  284. * The converse holds for decoders, with frames and packets switched.
  285. */
  286. #define AV_CODEC_FLAG_COPY_OPAQUE (1 << 7)
  287. /**
  288. * Signal to the encoder that the values of AVFrame.duration are valid and
  289. * should be used (typically for transferring them to output packets).
  290. *
  291. * If this flag is not set, frame durations are ignored.
  292. */
  293. #define AV_CODEC_FLAG_FRAME_DURATION (1 << 8)
  294. /**
  295. * Use internal 2pass ratecontrol in first pass mode.
  296. */
  297. #define AV_CODEC_FLAG_PASS1 (1 << 9)
  298. /**
  299. * Use internal 2pass ratecontrol in second pass mode.
  300. */
  301. #define AV_CODEC_FLAG_PASS2 (1 << 10)
  302. /**
  303. * loop filter.
  304. */
  305. #define AV_CODEC_FLAG_LOOP_FILTER (1 << 11)
  306. /**
  307. * Only decode/encode grayscale.
  308. */
  309. #define AV_CODEC_FLAG_GRAY (1 << 13)
  310. /**
  311. * error[?] variables will be set during encoding.
  312. */
  313. #define AV_CODEC_FLAG_PSNR (1 << 15)
  314. /**
  315. * Use interlaced DCT.
  316. */
  317. #define AV_CODEC_FLAG_INTERLACED_DCT (1 << 18)
  318. /**
  319. * Force low delay.
  320. */
  321. #define AV_CODEC_FLAG_LOW_DELAY (1 << 19)
  322. /**
  323. * Place global headers in extradata instead of every keyframe.
  324. */
  325. #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
  326. /**
  327. * Use only bitexact stuff (except (I)DCT).
  328. */
  329. #define AV_CODEC_FLAG_BITEXACT (1 << 23)
  330. /* Fx : Flag for H.263+ extra options */
  331. /**
  332. * H.263 advanced intra coding / MPEG-4 AC prediction
  333. */
  334. #define AV_CODEC_FLAG_AC_PRED (1 << 24)
  335. /**
  336. * interlaced motion estimation
  337. */
  338. #define AV_CODEC_FLAG_INTERLACED_ME (1 << 29)
  339. #define AV_CODEC_FLAG_CLOSED_GOP (1U << 31)
  340. /**
  341. * Allow non spec compliant speedup tricks.
  342. */
  343. #define AV_CODEC_FLAG2_FAST (1 << 0)
  344. /**
  345. * Skip bitstream encoding.
  346. */
  347. #define AV_CODEC_FLAG2_NO_OUTPUT (1 << 2)
  348. /**
  349. * Place global headers at every keyframe instead of in extradata.
  350. */
  351. #define AV_CODEC_FLAG2_LOCAL_HEADER (1 << 3)
  352. /**
  353. * Input bitstream might be truncated at a packet boundaries
  354. * instead of only at frame boundaries.
  355. */
  356. #define AV_CODEC_FLAG2_CHUNKS (1 << 15)
  357. /**
  358. * Discard cropping information from SPS.
  359. */
  360. #define AV_CODEC_FLAG2_IGNORE_CROP (1 << 16)
  361. /**
  362. * Show all frames before the first keyframe
  363. */
  364. #define AV_CODEC_FLAG2_SHOW_ALL (1 << 22)
  365. /**
  366. * Export motion vectors through frame side data
  367. */
  368. #define AV_CODEC_FLAG2_EXPORT_MVS (1 << 28)
  369. /**
  370. * Do not skip samples and export skip information as frame side data
  371. */
  372. #define AV_CODEC_FLAG2_SKIP_MANUAL (1 << 29)
  373. /**
  374. * Do not reset ASS ReadOrder field on flush (subtitles decoding)
  375. */
  376. #define AV_CODEC_FLAG2_RO_FLUSH_NOOP (1 << 30)
  377. /**
  378. * Generate/parse ICC profiles on encode/decode, as appropriate for the type of
  379. * file. No effect on codecs which cannot contain embedded ICC profiles, or
  380. * when compiled without support for lcms2.
  381. */
  382. #define AV_CODEC_FLAG2_ICC_PROFILES (1U << 31)
  383. /* Exported side data.
  384. These flags can be passed in AVCodecContext.export_side_data before initialization.
  385. */
  386. /**
  387. * Export motion vectors through frame side data
  388. */
  389. #define AV_CODEC_EXPORT_DATA_MVS (1 << 0)
  390. /**
  391. * Export encoder Producer Reference Time through packet side data
  392. */
  393. #define AV_CODEC_EXPORT_DATA_PRFT (1 << 1)
  394. /**
  395. * Decoding only.
  396. * Export the AVVideoEncParams structure through frame side data.
  397. */
  398. #define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS (1 << 2)
  399. /**
  400. * Decoding only.
  401. * Do not apply film grain, export it instead.
  402. */
  403. #define AV_CODEC_EXPORT_DATA_FILM_GRAIN (1 << 3)
  404. /**
  405. * The decoder will keep a reference to the frame and may reuse it later.
  406. */
  407. #define AV_GET_BUFFER_FLAG_REF (1 << 0)
  408. /**
  409. * The encoder will keep a reference to the packet and may reuse it later.
  410. */
  411. #define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0)
  412. /**
  413. * main external API structure.
  414. * New fields can be added to the end with minor version bumps.
  415. * Removal, reordering and changes to existing fields require a major
  416. * version bump.
  417. * You can use AVOptions (av_opt* / av_set/get*()) to access these fields from user
  418. * applications.
  419. * The name string for AVOptions options matches the associated command line
  420. * parameter name and can be found in libavcodec/options_table.h
  421. * The AVOption/command line parameter names differ in some cases from the C
  422. * structure field names for historic reasons or brevity.
  423. * sizeof(AVCodecContext) must not be used outside libav*.
  424. */
  425. typedef struct AVCodecContext {
  426. /**
  427. * information on struct for av_log
  428. * - set by avcodec_alloc_context3
  429. */
  430. const AVClass *av_class;
  431. int log_level_offset;
  432. enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
  433. const struct AVCodec *codec;
  434. enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
  435. /**
  436. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  437. * This is used to work around some encoder bugs.
  438. * A demuxer should set this to what is stored in the field used to identify the codec.
  439. * If there are multiple such fields in a container then the demuxer should choose the one
  440. * which maximizes the information about the used codec.
  441. * If the codec tag field in a container is larger than 32 bits then the demuxer should
  442. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  443. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  444. * first.
  445. * - encoding: Set by user, if not then the default based on codec_id will be used.
  446. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  447. */
  448. unsigned int codec_tag;
  449. void *priv_data;
  450. /**
  451. * Private context used for internal data.
  452. *
  453. * Unlike priv_data, this is not codec-specific. It is used in general
  454. * libavcodec functions.
  455. */
  456. struct AVCodecInternal *internal;
  457. /**
  458. * Private data of the user, can be used to carry app specific stuff.
  459. * - encoding: Set by user.
  460. * - decoding: Set by user.
  461. */
  462. void *opaque;
  463. /**
  464. * the average bitrate
  465. * - encoding: Set by user; unused for constant quantizer encoding.
  466. * - decoding: Set by user, may be overwritten by libavcodec
  467. * if this info is available in the stream
  468. */
  469. int64_t bit_rate;
  470. /**
  471. * AV_CODEC_FLAG_*.
  472. * - encoding: Set by user.
  473. * - decoding: Set by user.
  474. */
  475. int flags;
  476. /**
  477. * AV_CODEC_FLAG2_*
  478. * - encoding: Set by user.
  479. * - decoding: Set by user.
  480. */
  481. int flags2;
  482. /**
  483. * some codecs need / can use extradata like Huffman tables.
  484. * MJPEG: Huffman tables
  485. * rv10: additional flags
  486. * MPEG-4: global headers (they can be in the bitstream or here)
  487. * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
  488. * than extradata_size to avoid problems if it is read with the bitstream reader.
  489. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  490. * Must be allocated with the av_malloc() family of functions.
  491. * - encoding: Set/allocated/freed by libavcodec.
  492. * - decoding: Set/allocated/freed by user.
  493. */
  494. uint8_t *extradata;
  495. int extradata_size;
  496. /**
  497. * This is the fundamental unit of time (in seconds) in terms
  498. * of which frame timestamps are represented. For fixed-fps content,
  499. * timebase should be 1/framerate and timestamp increments should be
  500. * identically 1.
  501. * This often, but not always is the inverse of the frame rate or field rate
  502. * for video. 1/time_base is not the average frame rate if the frame rate is not
  503. * constant.
  504. *
  505. * Like containers, elementary streams also can store timestamps, 1/time_base
  506. * is the unit in which these timestamps are specified.
  507. * As example of such codec time base see ISO/IEC 14496-2:2001(E)
  508. * vop_time_increment_resolution and fixed_vop_rate
  509. * (fixed_vop_rate == 0 implies that it is different from the framerate)
  510. *
  511. * - encoding: MUST be set by user.
  512. * - decoding: unused.
  513. */
  514. AVRational time_base;
  515. /**
  516. * Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
  517. * - encoding: unused.
  518. * - decoding: set by user.
  519. */
  520. AVRational pkt_timebase;
  521. /**
  522. * - decoding: For codecs that store a framerate value in the compressed
  523. * bitstream, the decoder may export it here. { 0, 1} when
  524. * unknown.
  525. * - encoding: May be used to signal the framerate of CFR content to an
  526. * encoder.
  527. */
  528. AVRational framerate;
  529. #if FF_API_TICKS_PER_FRAME
  530. /**
  531. * For some codecs, the time base is closer to the field rate than the frame rate.
  532. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
  533. * if no telecine is used ...
  534. *
  535. * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
  536. *
  537. * @deprecated
  538. * - decoding: Use AVCodecDescriptor.props & AV_CODEC_PROP_FIELDS
  539. * - encoding: Set AVCodecContext.framerate instead
  540. *
  541. */
  542. attribute_deprecated
  543. int ticks_per_frame;
  544. #endif
  545. /**
  546. * Codec delay.
  547. *
  548. * Encoding: Number of frames delay there will be from the encoder input to
  549. * the decoder output. (we assume the decoder matches the spec)
  550. * Decoding: Number of frames delay in addition to what a standard decoder
  551. * as specified in the spec would produce.
  552. *
  553. * Video:
  554. * Number of frames the decoded output will be delayed relative to the
  555. * encoded input.
  556. *
  557. * Audio:
  558. * For encoding, this field is unused (see initial_padding).
  559. *
  560. * For decoding, this is the number of samples the decoder needs to
  561. * output before the decoder's output is valid. When seeking, you should
  562. * start decoding this many samples prior to your desired seek point.
  563. *
  564. * - encoding: Set by libavcodec.
  565. * - decoding: Set by libavcodec.
  566. */
  567. int delay;
  568. /* video only */
  569. /**
  570. * picture width / height.
  571. *
  572. * @note Those fields may not match the values of the last
  573. * AVFrame output by avcodec_receive_frame() due frame
  574. * reordering.
  575. *
  576. * - encoding: MUST be set by user.
  577. * - decoding: May be set by the user before opening the decoder if known e.g.
  578. * from the container. Some decoders will require the dimensions
  579. * to be set by the caller. During decoding, the decoder may
  580. * overwrite those values as required while parsing the data.
  581. */
  582. int width, height;
  583. /**
  584. * Bitstream width / height, may be different from width/height e.g. when
  585. * the decoded frame is cropped before being output or lowres is enabled.
  586. *
  587. * @note Those field may not match the value of the last
  588. * AVFrame output by avcodec_receive_frame() due frame
  589. * reordering.
  590. *
  591. * - encoding: unused
  592. * - decoding: May be set by the user before opening the decoder if known
  593. * e.g. from the container. During decoding, the decoder may
  594. * overwrite those values as required while parsing the data.
  595. */
  596. int coded_width, coded_height;
  597. /**
  598. * sample aspect ratio (0 if unknown)
  599. * That is the width of a pixel divided by the height of the pixel.
  600. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  601. * - encoding: Set by user.
  602. * - decoding: Set by libavcodec.
  603. */
  604. AVRational sample_aspect_ratio;
  605. /**
  606. * Pixel format, see AV_PIX_FMT_xxx.
  607. * May be set by the demuxer if known from headers.
  608. * May be overridden by the decoder if it knows better.
  609. *
  610. * @note This field may not match the value of the last
  611. * AVFrame output by avcodec_receive_frame() due frame
  612. * reordering.
  613. *
  614. * - encoding: Set by user.
  615. * - decoding: Set by user if known, overridden by libavcodec while
  616. * parsing the data.
  617. */
  618. enum AVPixelFormat pix_fmt;
  619. /**
  620. * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
  621. * - encoding: unused.
  622. * - decoding: Set by libavcodec before calling get_format()
  623. */
  624. enum AVPixelFormat sw_pix_fmt;
  625. /**
  626. * Chromaticity coordinates of the source primaries.
  627. * - encoding: Set by user
  628. * - decoding: Set by libavcodec
  629. */
  630. enum AVColorPrimaries color_primaries;
  631. /**
  632. * Color Transfer Characteristic.
  633. * - encoding: Set by user
  634. * - decoding: Set by libavcodec
  635. */
  636. enum AVColorTransferCharacteristic color_trc;
  637. /**
  638. * YUV colorspace type.
  639. * - encoding: Set by user
  640. * - decoding: Set by libavcodec
  641. */
  642. enum AVColorSpace colorspace;
  643. /**
  644. * MPEG vs JPEG YUV range.
  645. * - encoding: Set by user to override the default output color range value,
  646. * If not specified, libavcodec sets the color range depending on the
  647. * output format.
  648. * - decoding: Set by libavcodec, can be set by the user to propagate the
  649. * color range to components reading from the decoder context.
  650. */
  651. enum AVColorRange color_range;
  652. /**
  653. * This defines the location of chroma samples.
  654. * - encoding: Set by user
  655. * - decoding: Set by libavcodec
  656. */
  657. enum AVChromaLocation chroma_sample_location;
  658. /** Field order
  659. * - encoding: set by libavcodec
  660. * - decoding: Set by user.
  661. */
  662. enum AVFieldOrder field_order;
  663. /**
  664. * number of reference frames
  665. * - encoding: Set by user.
  666. * - decoding: Set by lavc.
  667. */
  668. int refs;
  669. /**
  670. * Size of the frame reordering buffer in the decoder.
  671. * For MPEG-2 it is 1 IPB or 0 low delay IP.
  672. * - encoding: Set by libavcodec.
  673. * - decoding: Set by libavcodec.
  674. */
  675. int has_b_frames;
  676. /**
  677. * slice flags
  678. * - encoding: unused
  679. * - decoding: Set by user.
  680. */
  681. int slice_flags;
  682. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  683. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG-2 field pics)
  684. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  685. /**
  686. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  687. * decoder to draw a horizontal band. It improves cache usage. Not
  688. * all codecs can do that. You must check the codec capabilities
  689. * beforehand.
  690. * When multithreading is used, it may be called from multiple threads
  691. * at the same time; threads might draw different parts of the same AVFrame,
  692. * or multiple AVFrames, and there is no guarantee that slices will be drawn
  693. * in order.
  694. * The function is also used by hardware acceleration APIs.
  695. * It is called at least once during frame decoding to pass
  696. * the data needed for hardware render.
  697. * In that mode instead of pixel data, AVFrame points to
  698. * a structure specific to the acceleration API. The application
  699. * reads the structure and can change some fields to indicate progress
  700. * or mark state.
  701. * - encoding: unused
  702. * - decoding: Set by user.
  703. * @param height the height of the slice
  704. * @param y the y position of the slice
  705. * @param type 1->top field, 2->bottom field, 3->frame
  706. * @param offset offset into the AVFrame.data from which the slice should be read
  707. */
  708. void (*draw_horiz_band)(struct AVCodecContext *s,
  709. const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
  710. int y, int type, int height);
  711. /**
  712. * Callback to negotiate the pixel format. Decoding only, may be set by the
  713. * caller before avcodec_open2().
  714. *
  715. * Called by some decoders to select the pixel format that will be used for
  716. * the output frames. This is mainly used to set up hardware acceleration,
  717. * then the provided format list contains the corresponding hwaccel pixel
  718. * formats alongside the "software" one. The software pixel format may also
  719. * be retrieved from \ref sw_pix_fmt.
  720. *
  721. * This callback will be called when the coded frame properties (such as
  722. * resolution, pixel format, etc.) change and more than one output format is
  723. * supported for those new properties. If a hardware pixel format is chosen
  724. * and initialization for it fails, the callback may be called again
  725. * immediately.
  726. *
  727. * This callback may be called from different threads if the decoder is
  728. * multi-threaded, but not from more than one thread simultaneously.
  729. *
  730. * @param fmt list of formats which may be used in the current
  731. * configuration, terminated by AV_PIX_FMT_NONE.
  732. * @warning Behavior is undefined if the callback returns a value other
  733. * than one of the formats in fmt or AV_PIX_FMT_NONE.
  734. * @return the chosen format or AV_PIX_FMT_NONE
  735. */
  736. enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  737. /**
  738. * maximum number of B-frames between non-B-frames
  739. * Note: The output will be delayed by max_b_frames+1 relative to the input.
  740. * - encoding: Set by user.
  741. * - decoding: unused
  742. */
  743. int max_b_frames;
  744. /**
  745. * qscale factor between IP and B-frames
  746. * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
  747. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  748. * - encoding: Set by user.
  749. * - decoding: unused
  750. */
  751. float b_quant_factor;
  752. /**
  753. * qscale offset between IP and B-frames
  754. * - encoding: Set by user.
  755. * - decoding: unused
  756. */
  757. float b_quant_offset;
  758. /**
  759. * qscale factor between P- and I-frames
  760. * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset).
  761. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  762. * - encoding: Set by user.
  763. * - decoding: unused
  764. */
  765. float i_quant_factor;
  766. /**
  767. * qscale offset between P and I-frames
  768. * - encoding: Set by user.
  769. * - decoding: unused
  770. */
  771. float i_quant_offset;
  772. /**
  773. * luminance masking (0-> disabled)
  774. * - encoding: Set by user.
  775. * - decoding: unused
  776. */
  777. float lumi_masking;
  778. /**
  779. * temporary complexity masking (0-> disabled)
  780. * - encoding: Set by user.
  781. * - decoding: unused
  782. */
  783. float temporal_cplx_masking;
  784. /**
  785. * spatial complexity masking (0-> disabled)
  786. * - encoding: Set by user.
  787. * - decoding: unused
  788. */
  789. float spatial_cplx_masking;
  790. /**
  791. * p block masking (0-> disabled)
  792. * - encoding: Set by user.
  793. * - decoding: unused
  794. */
  795. float p_masking;
  796. /**
  797. * darkness masking (0-> disabled)
  798. * - encoding: Set by user.
  799. * - decoding: unused
  800. */
  801. float dark_masking;
  802. /**
  803. * noise vs. sse weight for the nsse comparison function
  804. * - encoding: Set by user.
  805. * - decoding: unused
  806. */
  807. int nsse_weight;
  808. /**
  809. * motion estimation comparison function
  810. * - encoding: Set by user.
  811. * - decoding: unused
  812. */
  813. int me_cmp;
  814. /**
  815. * subpixel motion estimation comparison function
  816. * - encoding: Set by user.
  817. * - decoding: unused
  818. */
  819. int me_sub_cmp;
  820. /**
  821. * macroblock comparison function (not supported yet)
  822. * - encoding: Set by user.
  823. * - decoding: unused
  824. */
  825. int mb_cmp;
  826. /**
  827. * interlaced DCT comparison function
  828. * - encoding: Set by user.
  829. * - decoding: unused
  830. */
  831. int ildct_cmp;
  832. #define FF_CMP_SAD 0
  833. #define FF_CMP_SSE 1
  834. #define FF_CMP_SATD 2
  835. #define FF_CMP_DCT 3
  836. #define FF_CMP_PSNR 4
  837. #define FF_CMP_BIT 5
  838. #define FF_CMP_RD 6
  839. #define FF_CMP_ZERO 7
  840. #define FF_CMP_VSAD 8
  841. #define FF_CMP_VSSE 9
  842. #define FF_CMP_NSSE 10
  843. #define FF_CMP_W53 11
  844. #define FF_CMP_W97 12
  845. #define FF_CMP_DCTMAX 13
  846. #define FF_CMP_DCT264 14
  847. #define FF_CMP_MEDIAN_SAD 15
  848. #define FF_CMP_CHROMA 256
  849. /**
  850. * ME diamond size & shape
  851. * - encoding: Set by user.
  852. * - decoding: unused
  853. */
  854. int dia_size;
  855. /**
  856. * amount of previous MV predictors (2a+1 x 2a+1 square)
  857. * - encoding: Set by user.
  858. * - decoding: unused
  859. */
  860. int last_predictor_count;
  861. /**
  862. * motion estimation prepass comparison function
  863. * - encoding: Set by user.
  864. * - decoding: unused
  865. */
  866. int me_pre_cmp;
  867. /**
  868. * ME prepass diamond size & shape
  869. * - encoding: Set by user.
  870. * - decoding: unused
  871. */
  872. int pre_dia_size;
  873. /**
  874. * subpel ME quality
  875. * - encoding: Set by user.
  876. * - decoding: unused
  877. */
  878. int me_subpel_quality;
  879. /**
  880. * maximum motion estimation search range in subpel units
  881. * If 0 then no limit.
  882. *
  883. * - encoding: Set by user.
  884. * - decoding: unused
  885. */
  886. int me_range;
  887. /**
  888. * macroblock decision mode
  889. * - encoding: Set by user.
  890. * - decoding: unused
  891. */
  892. int mb_decision;
  893. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  894. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  895. #define FF_MB_DECISION_RD 2 ///< rate distortion
  896. /**
  897. * custom intra quantization matrix
  898. * Must be allocated with the av_malloc() family of functions, and will be freed in
  899. * avcodec_free_context().
  900. * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  901. * - decoding: Set/allocated/freed by libavcodec.
  902. */
  903. uint16_t *intra_matrix;
  904. /**
  905. * custom inter quantization matrix
  906. * Must be allocated with the av_malloc() family of functions, and will be freed in
  907. * avcodec_free_context().
  908. * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  909. * - decoding: Set/allocated/freed by libavcodec.
  910. */
  911. uint16_t *inter_matrix;
  912. /**
  913. * custom intra quantization matrix
  914. * - encoding: Set by user, can be NULL.
  915. * - decoding: unused.
  916. */
  917. uint16_t *chroma_intra_matrix;
  918. /**
  919. * precision of the intra DC coefficient - 8
  920. * - encoding: Set by user.
  921. * - decoding: Set by libavcodec
  922. */
  923. int intra_dc_precision;
  924. /**
  925. * minimum MB Lagrange multiplier
  926. * - encoding: Set by user.
  927. * - decoding: unused
  928. */
  929. int mb_lmin;
  930. /**
  931. * maximum MB Lagrange multiplier
  932. * - encoding: Set by user.
  933. * - decoding: unused
  934. */
  935. int mb_lmax;
  936. /**
  937. * - encoding: Set by user.
  938. * - decoding: unused
  939. */
  940. int bidir_refine;
  941. /**
  942. * minimum GOP size
  943. * - encoding: Set by user.
  944. * - decoding: unused
  945. */
  946. int keyint_min;
  947. /**
  948. * the number of pictures in a group of pictures, or 0 for intra_only
  949. * - encoding: Set by user.
  950. * - decoding: unused
  951. */
  952. int gop_size;
  953. /**
  954. * Note: Value depends upon the compare function used for fullpel ME.
  955. * - encoding: Set by user.
  956. * - decoding: unused
  957. */
  958. int mv0_threshold;
  959. /**
  960. * Number of slices.
  961. * Indicates number of picture subdivisions. Used for parallelized
  962. * decoding.
  963. * - encoding: Set by user
  964. * - decoding: unused
  965. */
  966. int slices;
  967. /* audio only */
  968. int sample_rate; ///< samples per second
  969. /**
  970. * audio sample format
  971. * - encoding: Set by user.
  972. * - decoding: Set by libavcodec.
  973. */
  974. enum AVSampleFormat sample_fmt; ///< sample format
  975. /**
  976. * Audio channel layout.
  977. * - encoding: must be set by the caller, to one of AVCodec.ch_layouts.
  978. * - decoding: may be set by the caller if known e.g. from the container.
  979. * The decoder can then override during decoding as needed.
  980. */
  981. AVChannelLayout ch_layout;
  982. /* The following data should not be initialized. */
  983. /**
  984. * Number of samples per channel in an audio frame.
  985. *
  986. * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
  987. * except the last must contain exactly frame_size samples per channel.
  988. * May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
  989. * frame size is not restricted.
  990. * - decoding: may be set by some decoders to indicate constant frame size
  991. */
  992. int frame_size;
  993. /**
  994. * number of bytes per packet if constant and known or 0
  995. * Used by some WAV based audio codecs.
  996. */
  997. int block_align;
  998. /**
  999. * Audio cutoff bandwidth (0 means "automatic")
  1000. * - encoding: Set by user.
  1001. * - decoding: unused
  1002. */
  1003. int cutoff;
  1004. /**
  1005. * Type of service that the audio stream conveys.
  1006. * - encoding: Set by user.
  1007. * - decoding: Set by libavcodec.
  1008. */
  1009. enum AVAudioServiceType audio_service_type;
  1010. /**
  1011. * desired sample format
  1012. * - encoding: Not used.
  1013. * - decoding: Set by user.
  1014. * Decoder will decode to this format if it can.
  1015. */
  1016. enum AVSampleFormat request_sample_fmt;
  1017. /**
  1018. * Audio only. The number of "priming" samples (padding) inserted by the
  1019. * encoder at the beginning of the audio. I.e. this number of leading
  1020. * decoded samples must be discarded by the caller to get the original audio
  1021. * without leading padding.
  1022. *
  1023. * - decoding: unused
  1024. * - encoding: Set by libavcodec. The timestamps on the output packets are
  1025. * adjusted by the encoder so that they always refer to the
  1026. * first sample of the data actually contained in the packet,
  1027. * including any added padding. E.g. if the timebase is
  1028. * 1/samplerate and the timestamp of the first input sample is
  1029. * 0, the timestamp of the first output packet will be
  1030. * -initial_padding.
  1031. */
  1032. int initial_padding;
  1033. /**
  1034. * Audio only. The amount of padding (in samples) appended by the encoder to
  1035. * the end of the audio. I.e. this number of decoded samples must be
  1036. * discarded by the caller from the end of the stream to get the original
  1037. * audio without any trailing padding.
  1038. *
  1039. * - decoding: unused
  1040. * - encoding: unused
  1041. */
  1042. int trailing_padding;
  1043. /**
  1044. * Number of samples to skip after a discontinuity
  1045. * - decoding: unused
  1046. * - encoding: set by libavcodec
  1047. */
  1048. int seek_preroll;
  1049. /**
  1050. * This callback is called at the beginning of each frame to get data
  1051. * buffer(s) for it. There may be one contiguous buffer for all the data or
  1052. * there may be a buffer per each data plane or anything in between. What
  1053. * this means is, you may set however many entries in buf[] you feel necessary.
  1054. * Each buffer must be reference-counted using the AVBuffer API (see description
  1055. * of buf[] below).
  1056. *
  1057. * The following fields will be set in the frame before this callback is
  1058. * called:
  1059. * - format
  1060. * - width, height (video only)
  1061. * - sample_rate, channel_layout, nb_samples (audio only)
  1062. * Their values may differ from the corresponding values in
  1063. * AVCodecContext. This callback must use the frame values, not the codec
  1064. * context values, to calculate the required buffer size.
  1065. *
  1066. * This callback must fill the following fields in the frame:
  1067. * - data[]
  1068. * - linesize[]
  1069. * - extended_data:
  1070. * * if the data is planar audio with more than 8 channels, then this
  1071. * callback must allocate and fill extended_data to contain all pointers
  1072. * to all data planes. data[] must hold as many pointers as it can.
  1073. * extended_data must be allocated with av_malloc() and will be freed in
  1074. * av_frame_unref().
  1075. * * otherwise extended_data must point to data
  1076. * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
  1077. * the frame's data and extended_data pointers must be contained in these. That
  1078. * is, one AVBufferRef for each allocated chunk of memory, not necessarily one
  1079. * AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
  1080. * and av_buffer_ref().
  1081. * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
  1082. * this callback and filled with the extra buffers if there are more
  1083. * buffers than buf[] can hold. extended_buf will be freed in
  1084. * av_frame_unref().
  1085. *
  1086. * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call
  1087. * avcodec_default_get_buffer2() instead of providing buffers allocated by
  1088. * some other means.
  1089. *
  1090. * Each data plane must be aligned to the maximum required by the target
  1091. * CPU.
  1092. *
  1093. * @see avcodec_default_get_buffer2()
  1094. *
  1095. * Video:
  1096. *
  1097. * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
  1098. * (read and/or written to if it is writable) later by libavcodec.
  1099. *
  1100. * avcodec_align_dimensions2() should be used to find the required width and
  1101. * height, as they normally need to be rounded up to the next multiple of 16.
  1102. *
  1103. * Some decoders do not support linesizes changing between frames.
  1104. *
  1105. * If frame multithreading is used, this callback may be called from a
  1106. * different thread, but not from more than one at once. Does not need to be
  1107. * reentrant.
  1108. *
  1109. * @see avcodec_align_dimensions2()
  1110. *
  1111. * Audio:
  1112. *
  1113. * Decoders request a buffer of a particular size by setting
  1114. * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
  1115. * however, utilize only part of the buffer by setting AVFrame.nb_samples
  1116. * to a smaller value in the output frame.
  1117. *
  1118. * As a convenience, av_samples_get_buffer_size() and
  1119. * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
  1120. * functions to find the required data size and to fill data pointers and
  1121. * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
  1122. * since all planes must be the same size.
  1123. *
  1124. * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
  1125. *
  1126. * - encoding: unused
  1127. * - decoding: Set by libavcodec, user can override.
  1128. */
  1129. int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
  1130. /* - encoding parameters */
  1131. /**
  1132. * number of bits the bitstream is allowed to diverge from the reference.
  1133. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  1134. * - encoding: Set by user; unused for constant quantizer encoding.
  1135. * - decoding: unused
  1136. */
  1137. int bit_rate_tolerance;
  1138. /**
  1139. * Global quality for codecs which cannot change it per frame.
  1140. * This should be proportional to MPEG-1/2/4 qscale.
  1141. * - encoding: Set by user.
  1142. * - decoding: unused
  1143. */
  1144. int global_quality;
  1145. /**
  1146. * - encoding: Set by user.
  1147. * - decoding: unused
  1148. */
  1149. int compression_level;
  1150. #define FF_COMPRESSION_DEFAULT -1
  1151. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  1152. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  1153. /**
  1154. * minimum quantizer
  1155. * - encoding: Set by user.
  1156. * - decoding: unused
  1157. */
  1158. int qmin;
  1159. /**
  1160. * maximum quantizer
  1161. * - encoding: Set by user.
  1162. * - decoding: unused
  1163. */
  1164. int qmax;
  1165. /**
  1166. * maximum quantizer difference between frames
  1167. * - encoding: Set by user.
  1168. * - decoding: unused
  1169. */
  1170. int max_qdiff;
  1171. /**
  1172. * decoder bitstream buffer size
  1173. * - encoding: Set by user.
  1174. * - decoding: May be set by libavcodec.
  1175. */
  1176. int rc_buffer_size;
  1177. /**
  1178. * ratecontrol override, see RcOverride
  1179. * - encoding: Allocated/set/freed by user.
  1180. * - decoding: unused
  1181. */
  1182. int rc_override_count;
  1183. RcOverride *rc_override;
  1184. /**
  1185. * maximum bitrate
  1186. * - encoding: Set by user.
  1187. * - decoding: Set by user, may be overwritten by libavcodec.
  1188. */
  1189. int64_t rc_max_rate;
  1190. /**
  1191. * minimum bitrate
  1192. * - encoding: Set by user.
  1193. * - decoding: unused
  1194. */
  1195. int64_t rc_min_rate;
  1196. /**
  1197. * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
  1198. * - encoding: Set by user.
  1199. * - decoding: unused.
  1200. */
  1201. float rc_max_available_vbv_use;
  1202. /**
  1203. * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
  1204. * - encoding: Set by user.
  1205. * - decoding: unused.
  1206. */
  1207. float rc_min_vbv_overflow_use;
  1208. /**
  1209. * Number of bits which should be loaded into the rc buffer before decoding starts.
  1210. * - encoding: Set by user.
  1211. * - decoding: unused
  1212. */
  1213. int rc_initial_buffer_occupancy;
  1214. /**
  1215. * trellis RD quantization
  1216. * - encoding: Set by user.
  1217. * - decoding: unused
  1218. */
  1219. int trellis;
  1220. /**
  1221. * pass1 encoding statistics output buffer
  1222. * - encoding: Set by libavcodec.
  1223. * - decoding: unused
  1224. */
  1225. char *stats_out;
  1226. /**
  1227. * pass2 encoding statistics input buffer
  1228. * Concatenated stuff from stats_out of pass1 should be placed here.
  1229. * - encoding: Allocated/set/freed by user.
  1230. * - decoding: unused
  1231. */
  1232. char *stats_in;
  1233. /**
  1234. * Work around bugs in encoders which sometimes cannot be detected automatically.
  1235. * - encoding: Set by user
  1236. * - decoding: Set by user
  1237. */
  1238. int workaround_bugs;
  1239. #define FF_BUG_AUTODETECT 1 ///< autodetection
  1240. #define FF_BUG_XVID_ILACE 4
  1241. #define FF_BUG_UMP4 8
  1242. #define FF_BUG_NO_PADDING 16
  1243. #define FF_BUG_AMV 32
  1244. #define FF_BUG_QPEL_CHROMA 64
  1245. #define FF_BUG_STD_QPEL 128
  1246. #define FF_BUG_QPEL_CHROMA2 256
  1247. #define FF_BUG_DIRECT_BLOCKSIZE 512
  1248. #define FF_BUG_EDGE 1024
  1249. #define FF_BUG_HPEL_CHROMA 2048
  1250. #define FF_BUG_DC_CLIP 4096
  1251. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  1252. #define FF_BUG_TRUNCATED 16384
  1253. #define FF_BUG_IEDGE 32768
  1254. /**
  1255. * strictly follow the standard (MPEG-4, ...).
  1256. * - encoding: Set by user.
  1257. * - decoding: Set by user.
  1258. * Setting this to STRICT or higher means the encoder and decoder will
  1259. * generally do stupid things, whereas setting it to unofficial or lower
  1260. * will mean the encoder might produce output that is not supported by all
  1261. * spec-compliant decoders. Decoders don't differentiate between normal,
  1262. * unofficial and experimental (that is, they always try to decode things
  1263. * when they can) unless they are explicitly asked to behave stupidly
  1264. * (=strictly conform to the specs)
  1265. * This may only be set to one of the FF_COMPLIANCE_* values in defs.h.
  1266. */
  1267. int strict_std_compliance;
  1268. /**
  1269. * error concealment flags
  1270. * - encoding: unused
  1271. * - decoding: Set by user.
  1272. */
  1273. int error_concealment;
  1274. #define FF_EC_GUESS_MVS 1
  1275. #define FF_EC_DEBLOCK 2
  1276. #define FF_EC_FAVOR_INTER 256
  1277. /**
  1278. * debug
  1279. * - encoding: Set by user.
  1280. * - decoding: Set by user.
  1281. */
  1282. int debug;
  1283. #define FF_DEBUG_PICT_INFO 1
  1284. #define FF_DEBUG_RC 2
  1285. #define FF_DEBUG_BITSTREAM 4
  1286. #define FF_DEBUG_MB_TYPE 8
  1287. #define FF_DEBUG_QP 16
  1288. #define FF_DEBUG_DCT_COEFF 0x00000040
  1289. #define FF_DEBUG_SKIP 0x00000080
  1290. #define FF_DEBUG_STARTCODE 0x00000100
  1291. #define FF_DEBUG_ER 0x00000400
  1292. #define FF_DEBUG_MMCO 0x00000800
  1293. #define FF_DEBUG_BUGS 0x00001000
  1294. #define FF_DEBUG_BUFFERS 0x00008000
  1295. #define FF_DEBUG_THREADS 0x00010000
  1296. #define FF_DEBUG_GREEN_MD 0x00800000
  1297. #define FF_DEBUG_NOMC 0x01000000
  1298. /**
  1299. * Error recognition; may misdetect some more or less valid parts as errors.
  1300. * This is a bitfield of the AV_EF_* values defined in defs.h.
  1301. *
  1302. * - encoding: Set by user.
  1303. * - decoding: Set by user.
  1304. */
  1305. int err_recognition;
  1306. /**
  1307. * Hardware accelerator in use
  1308. * - encoding: unused.
  1309. * - decoding: Set by libavcodec
  1310. */
  1311. const struct AVHWAccel *hwaccel;
  1312. /**
  1313. * Legacy hardware accelerator context.
  1314. *
  1315. * For some hardware acceleration methods, the caller may use this field to
  1316. * signal hwaccel-specific data to the codec. The struct pointed to by this
  1317. * pointer is hwaccel-dependent and defined in the respective header. Please
  1318. * refer to the FFmpeg HW accelerator documentation to know how to fill
  1319. * this.
  1320. *
  1321. * In most cases this field is optional - the necessary information may also
  1322. * be provided to libavcodec through @ref hw_frames_ctx or @ref
  1323. * hw_device_ctx (see avcodec_get_hw_config()). However, in some cases it
  1324. * may be the only method of signalling some (optional) information.
  1325. *
  1326. * The struct and its contents are owned by the caller.
  1327. *
  1328. * - encoding: May be set by the caller before avcodec_open2(). Must remain
  1329. * valid until avcodec_free_context().
  1330. * - decoding: May be set by the caller in the get_format() callback.
  1331. * Must remain valid until the next get_format() call,
  1332. * or avcodec_free_context() (whichever comes first).
  1333. */
  1334. void *hwaccel_context;
  1335. /**
  1336. * A reference to the AVHWFramesContext describing the input (for encoding)
  1337. * or output (decoding) frames. The reference is set by the caller and
  1338. * afterwards owned (and freed) by libavcodec - it should never be read by
  1339. * the caller after being set.
  1340. *
  1341. * - decoding: This field should be set by the caller from the get_format()
  1342. * callback. The previous reference (if any) will always be
  1343. * unreffed by libavcodec before the get_format() call.
  1344. *
  1345. * If the default get_buffer2() is used with a hwaccel pixel
  1346. * format, then this AVHWFramesContext will be used for
  1347. * allocating the frame buffers.
  1348. *
  1349. * - encoding: For hardware encoders configured to use a hwaccel pixel
  1350. * format, this field should be set by the caller to a reference
  1351. * to the AVHWFramesContext describing input frames.
  1352. * AVHWFramesContext.format must be equal to
  1353. * AVCodecContext.pix_fmt.
  1354. *
  1355. * This field should be set before avcodec_open2() is called.
  1356. */
  1357. AVBufferRef *hw_frames_ctx;
  1358. /**
  1359. * A reference to the AVHWDeviceContext describing the device which will
  1360. * be used by a hardware encoder/decoder. The reference is set by the
  1361. * caller and afterwards owned (and freed) by libavcodec.
  1362. *
  1363. * This should be used if either the codec device does not require
  1364. * hardware frames or any that are used are to be allocated internally by
  1365. * libavcodec. If the user wishes to supply any of the frames used as
  1366. * encoder input or decoder output then hw_frames_ctx should be used
  1367. * instead. When hw_frames_ctx is set in get_format() for a decoder, this
  1368. * field will be ignored while decoding the associated stream segment, but
  1369. * may again be used on a following one after another get_format() call.
  1370. *
  1371. * For both encoders and decoders this field should be set before
  1372. * avcodec_open2() is called and must not be written to thereafter.
  1373. *
  1374. * Note that some decoders may require this field to be set initially in
  1375. * order to support hw_frames_ctx at all - in that case, all frames
  1376. * contexts used must be created on the same device.
  1377. */
  1378. AVBufferRef *hw_device_ctx;
  1379. /**
  1380. * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated
  1381. * decoding (if active).
  1382. * - encoding: unused
  1383. * - decoding: Set by user (either before avcodec_open2(), or in the
  1384. * AVCodecContext.get_format callback)
  1385. */
  1386. int hwaccel_flags;
  1387. /**
  1388. * Video decoding only. Sets the number of extra hardware frames which
  1389. * the decoder will allocate for use by the caller. This must be set
  1390. * before avcodec_open2() is called.
  1391. *
  1392. * Some hardware decoders require all frames that they will use for
  1393. * output to be defined in advance before decoding starts. For such
  1394. * decoders, the hardware frame pool must therefore be of a fixed size.
  1395. * The extra frames set here are on top of any number that the decoder
  1396. * needs internally in order to operate normally (for example, frames
  1397. * used as reference pictures).
  1398. */
  1399. int extra_hw_frames;
  1400. /**
  1401. * error
  1402. * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
  1403. * - decoding: unused
  1404. */
  1405. uint64_t error[AV_NUM_DATA_POINTERS];
  1406. /**
  1407. * DCT algorithm, see FF_DCT_* below
  1408. * - encoding: Set by user.
  1409. * - decoding: unused
  1410. */
  1411. int dct_algo;
  1412. #define FF_DCT_AUTO 0
  1413. #define FF_DCT_FASTINT 1
  1414. #define FF_DCT_INT 2
  1415. #define FF_DCT_MMX 3
  1416. #define FF_DCT_ALTIVEC 5
  1417. #define FF_DCT_FAAN 6
  1418. /**
  1419. * IDCT algorithm, see FF_IDCT_* below.
  1420. * - encoding: Set by user.
  1421. * - decoding: Set by user.
  1422. */
  1423. int idct_algo;
  1424. #define FF_IDCT_AUTO 0
  1425. #define FF_IDCT_INT 1
  1426. #define FF_IDCT_SIMPLE 2
  1427. #define FF_IDCT_SIMPLEMMX 3
  1428. #define FF_IDCT_ARM 7
  1429. #define FF_IDCT_ALTIVEC 8
  1430. #define FF_IDCT_SIMPLEARM 10
  1431. #define FF_IDCT_XVID 14
  1432. #define FF_IDCT_SIMPLEARMV5TE 16
  1433. #define FF_IDCT_SIMPLEARMV6 17
  1434. #define FF_IDCT_FAAN 20
  1435. #define FF_IDCT_SIMPLENEON 22
  1436. #define FF_IDCT_SIMPLEAUTO 128
  1437. /**
  1438. * bits per sample/pixel from the demuxer (needed for huffyuv).
  1439. * - encoding: Set by libavcodec.
  1440. * - decoding: Set by user.
  1441. */
  1442. int bits_per_coded_sample;
  1443. /**
  1444. * Bits per sample/pixel of internal libavcodec pixel/sample format.
  1445. * - encoding: set by user.
  1446. * - decoding: set by libavcodec.
  1447. */
  1448. int bits_per_raw_sample;
  1449. /**
  1450. * thread count
  1451. * is used to decide how many independent tasks should be passed to execute()
  1452. * - encoding: Set by user.
  1453. * - decoding: Set by user.
  1454. */
  1455. int thread_count;
  1456. /**
  1457. * Which multithreading methods to use.
  1458. * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
  1459. * so clients which cannot provide future frames should not use it.
  1460. *
  1461. * - encoding: Set by user, otherwise the default is used.
  1462. * - decoding: Set by user, otherwise the default is used.
  1463. */
  1464. int thread_type;
  1465. #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
  1466. #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
  1467. /**
  1468. * Which multithreading methods are in use by the codec.
  1469. * - encoding: Set by libavcodec.
  1470. * - decoding: Set by libavcodec.
  1471. */
  1472. int active_thread_type;
  1473. /**
  1474. * The codec may call this to execute several independent things.
  1475. * It will return only after finishing all tasks.
  1476. * The user may replace this with some multithreaded implementation,
  1477. * the default implementation will execute the parts serially.
  1478. * @param count the number of things to execute
  1479. * - encoding: Set by libavcodec, user can override.
  1480. * - decoding: Set by libavcodec, user can override.
  1481. */
  1482. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
  1483. /**
  1484. * The codec may call this to execute several independent things.
  1485. * It will return only after finishing all tasks.
  1486. * The user may replace this with some multithreaded implementation,
  1487. * the default implementation will execute the parts serially.
  1488. * @param c context passed also to func
  1489. * @param count the number of things to execute
  1490. * @param arg2 argument passed unchanged to func
  1491. * @param ret return values of executed functions, must have space for "count" values. May be NULL.
  1492. * @param func function that will be called count times, with jobnr from 0 to count-1.
  1493. * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
  1494. * two instances of func executing at the same time will have the same threadnr.
  1495. * @return always 0 currently, but code should handle a future improvement where when any call to func
  1496. * returns < 0 no further calls to func may be done and < 0 is returned.
  1497. * - encoding: Set by libavcodec, user can override.
  1498. * - decoding: Set by libavcodec, user can override.
  1499. */
  1500. int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
  1501. /**
  1502. * profile
  1503. * - encoding: Set by user.
  1504. * - decoding: Set by libavcodec.
  1505. * See the AV_PROFILE_* defines in defs.h.
  1506. */
  1507. int profile;
  1508. #if FF_API_FF_PROFILE_LEVEL
  1509. /** @deprecated The following defines are deprecated; use AV_PROFILE_*
  1510. * in defs.h instead. */
  1511. #define FF_PROFILE_UNKNOWN -99
  1512. #define FF_PROFILE_RESERVED -100
  1513. #define FF_PROFILE_AAC_MAIN 0
  1514. #define FF_PROFILE_AAC_LOW 1
  1515. #define FF_PROFILE_AAC_SSR 2
  1516. #define FF_PROFILE_AAC_LTP 3
  1517. #define FF_PROFILE_AAC_HE 4
  1518. #define FF_PROFILE_AAC_HE_V2 28
  1519. #define FF_PROFILE_AAC_LD 22
  1520. #define FF_PROFILE_AAC_ELD 38
  1521. #define FF_PROFILE_MPEG2_AAC_LOW 128
  1522. #define FF_PROFILE_MPEG2_AAC_HE 131
  1523. #define FF_PROFILE_DNXHD 0
  1524. #define FF_PROFILE_DNXHR_LB 1
  1525. #define FF_PROFILE_DNXHR_SQ 2
  1526. #define FF_PROFILE_DNXHR_HQ 3
  1527. #define FF_PROFILE_DNXHR_HQX 4
  1528. #define FF_PROFILE_DNXHR_444 5
  1529. #define FF_PROFILE_DTS 20
  1530. #define FF_PROFILE_DTS_ES 30
  1531. #define FF_PROFILE_DTS_96_24 40
  1532. #define FF_PROFILE_DTS_HD_HRA 50
  1533. #define FF_PROFILE_DTS_HD_MA 60
  1534. #define FF_PROFILE_DTS_EXPRESS 70
  1535. #define FF_PROFILE_DTS_HD_MA_X 61
  1536. #define FF_PROFILE_DTS_HD_MA_X_IMAX 62
  1537. #define FF_PROFILE_EAC3_DDP_ATMOS 30
  1538. #define FF_PROFILE_TRUEHD_ATMOS 30
  1539. #define FF_PROFILE_MPEG2_422 0
  1540. #define FF_PROFILE_MPEG2_HIGH 1
  1541. #define FF_PROFILE_MPEG2_SS 2
  1542. #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
  1543. #define FF_PROFILE_MPEG2_MAIN 4
  1544. #define FF_PROFILE_MPEG2_SIMPLE 5
  1545. #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
  1546. #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
  1547. #define FF_PROFILE_H264_BASELINE 66
  1548. #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
  1549. #define FF_PROFILE_H264_MAIN 77
  1550. #define FF_PROFILE_H264_EXTENDED 88
  1551. #define FF_PROFILE_H264_HIGH 100
  1552. #define FF_PROFILE_H264_HIGH_10 110
  1553. #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
  1554. #define FF_PROFILE_H264_MULTIVIEW_HIGH 118
  1555. #define FF_PROFILE_H264_HIGH_422 122
  1556. #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
  1557. #define FF_PROFILE_H264_STEREO_HIGH 128
  1558. #define FF_PROFILE_H264_HIGH_444 144
  1559. #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
  1560. #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
  1561. #define FF_PROFILE_H264_CAVLC_444 44
  1562. #define FF_PROFILE_VC1_SIMPLE 0
  1563. #define FF_PROFILE_VC1_MAIN 1
  1564. #define FF_PROFILE_VC1_COMPLEX 2
  1565. #define FF_PROFILE_VC1_ADVANCED 3
  1566. #define FF_PROFILE_MPEG4_SIMPLE 0
  1567. #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
  1568. #define FF_PROFILE_MPEG4_CORE 2
  1569. #define FF_PROFILE_MPEG4_MAIN 3
  1570. #define FF_PROFILE_MPEG4_N_BIT 4
  1571. #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
  1572. #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
  1573. #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
  1574. #define FF_PROFILE_MPEG4_HYBRID 8
  1575. #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
  1576. #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
  1577. #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
  1578. #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
  1579. #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
  1580. #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
  1581. #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
  1582. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 1
  1583. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 2
  1584. #define FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION 32768
  1585. #define FF_PROFILE_JPEG2000_DCINEMA_2K 3
  1586. #define FF_PROFILE_JPEG2000_DCINEMA_4K 4
  1587. #define FF_PROFILE_VP9_0 0
  1588. #define FF_PROFILE_VP9_1 1
  1589. #define FF_PROFILE_VP9_2 2
  1590. #define FF_PROFILE_VP9_3 3
  1591. #define FF_PROFILE_HEVC_MAIN 1
  1592. #define FF_PROFILE_HEVC_MAIN_10 2
  1593. #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3
  1594. #define FF_PROFILE_HEVC_REXT 4
  1595. #define FF_PROFILE_HEVC_SCC 9
  1596. #define FF_PROFILE_VVC_MAIN_10 1
  1597. #define FF_PROFILE_VVC_MAIN_10_444 33
  1598. #define FF_PROFILE_AV1_MAIN 0
  1599. #define FF_PROFILE_AV1_HIGH 1
  1600. #define FF_PROFILE_AV1_PROFESSIONAL 2
  1601. #define FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT 0xc0
  1602. #define FF_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT 0xc1
  1603. #define FF_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT 0xc2
  1604. #define FF_PROFILE_MJPEG_HUFFMAN_LOSSLESS 0xc3
  1605. #define FF_PROFILE_MJPEG_JPEG_LS 0xf7
  1606. #define FF_PROFILE_SBC_MSBC 1
  1607. #define FF_PROFILE_PRORES_PROXY 0
  1608. #define FF_PROFILE_PRORES_LT 1
  1609. #define FF_PROFILE_PRORES_STANDARD 2
  1610. #define FF_PROFILE_PRORES_HQ 3
  1611. #define FF_PROFILE_PRORES_4444 4
  1612. #define FF_PROFILE_PRORES_XQ 5
  1613. #define FF_PROFILE_ARIB_PROFILE_A 0
  1614. #define FF_PROFILE_ARIB_PROFILE_C 1
  1615. #define FF_PROFILE_KLVA_SYNC 0
  1616. #define FF_PROFILE_KLVA_ASYNC 1
  1617. #define FF_PROFILE_EVC_BASELINE 0
  1618. #define FF_PROFILE_EVC_MAIN 1
  1619. #endif
  1620. /**
  1621. * Encoding level descriptor.
  1622. * - encoding: Set by user, corresponds to a specific level defined by the
  1623. * codec, usually corresponding to the profile level, if not specified it
  1624. * is set to FF_LEVEL_UNKNOWN.
  1625. * - decoding: Set by libavcodec.
  1626. * See AV_LEVEL_* in defs.h.
  1627. */
  1628. int level;
  1629. #if FF_API_FF_PROFILE_LEVEL
  1630. /** @deprecated The following define is deprecated; use AV_LEVEL_UNKOWN
  1631. * in defs.h instead. */
  1632. #define FF_LEVEL_UNKNOWN -99
  1633. #endif
  1634. /**
  1635. * Properties of the stream that gets decoded
  1636. * - encoding: unused
  1637. * - decoding: set by libavcodec
  1638. */
  1639. unsigned properties;
  1640. #define FF_CODEC_PROPERTY_LOSSLESS 0x00000001
  1641. #define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002
  1642. #define FF_CODEC_PROPERTY_FILM_GRAIN 0x00000004
  1643. /**
  1644. * Skip loop filtering for selected frames.
  1645. * - encoding: unused
  1646. * - decoding: Set by user.
  1647. */
  1648. enum AVDiscard skip_loop_filter;
  1649. /**
  1650. * Skip IDCT/dequantization for selected frames.
  1651. * - encoding: unused
  1652. * - decoding: Set by user.
  1653. */
  1654. enum AVDiscard skip_idct;
  1655. /**
  1656. * Skip decoding for selected frames.
  1657. * - encoding: unused
  1658. * - decoding: Set by user.
  1659. */
  1660. enum AVDiscard skip_frame;
  1661. /**
  1662. * Skip processing alpha if supported by codec.
  1663. * Note that if the format uses pre-multiplied alpha (common with VP6,
  1664. * and recommended due to better video quality/compression)
  1665. * the image will look as if alpha-blended onto a black background.
  1666. * However for formats that do not use pre-multiplied alpha
  1667. * there might be serious artefacts (though e.g. libswscale currently
  1668. * assumes pre-multiplied alpha anyway).
  1669. *
  1670. * - decoding: set by user
  1671. * - encoding: unused
  1672. */
  1673. int skip_alpha;
  1674. /**
  1675. * Number of macroblock rows at the top which are skipped.
  1676. * - encoding: unused
  1677. * - decoding: Set by user.
  1678. */
  1679. int skip_top;
  1680. /**
  1681. * Number of macroblock rows at the bottom which are skipped.
  1682. * - encoding: unused
  1683. * - decoding: Set by user.
  1684. */
  1685. int skip_bottom;
  1686. /**
  1687. * low resolution decoding, 1-> 1/2 size, 2->1/4 size
  1688. * - encoding: unused
  1689. * - decoding: Set by user.
  1690. */
  1691. int lowres;
  1692. /**
  1693. * AVCodecDescriptor
  1694. * - encoding: unused.
  1695. * - decoding: set by libavcodec.
  1696. */
  1697. const struct AVCodecDescriptor *codec_descriptor;
  1698. /**
  1699. * Character encoding of the input subtitles file.
  1700. * - decoding: set by user
  1701. * - encoding: unused
  1702. */
  1703. char *sub_charenc;
  1704. /**
  1705. * Subtitles character encoding mode. Formats or codecs might be adjusting
  1706. * this setting (if they are doing the conversion themselves for instance).
  1707. * - decoding: set by libavcodec
  1708. * - encoding: unused
  1709. */
  1710. int sub_charenc_mode;
  1711. #define FF_SUB_CHARENC_MODE_DO_NOTHING -1 ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for instance)
  1712. #define FF_SUB_CHARENC_MODE_AUTOMATIC 0 ///< libavcodec will select the mode itself
  1713. #define FF_SUB_CHARENC_MODE_PRE_DECODER 1 ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv
  1714. #define FF_SUB_CHARENC_MODE_IGNORE 2 ///< neither convert the subtitles, nor check them for valid UTF-8
  1715. /**
  1716. * Header containing style information for text subtitles.
  1717. * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
  1718. * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  1719. * the Format line following. It shouldn't include any Dialogue line.
  1720. * - encoding: Set/allocated/freed by user (before avcodec_open2())
  1721. * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
  1722. */
  1723. int subtitle_header_size;
  1724. uint8_t *subtitle_header;
  1725. /**
  1726. * dump format separator.
  1727. * can be ", " or "\n " or anything else
  1728. * - encoding: Set by user.
  1729. * - decoding: Set by user.
  1730. */
  1731. uint8_t *dump_separator;
  1732. /**
  1733. * ',' separated list of allowed decoders.
  1734. * If NULL then all are allowed
  1735. * - encoding: unused
  1736. * - decoding: set by user
  1737. */
  1738. char *codec_whitelist;
  1739. /**
  1740. * Additional data associated with the entire coded stream.
  1741. *
  1742. * - decoding: may be set by user before calling avcodec_open2().
  1743. * - encoding: may be set by libavcodec after avcodec_open2().
  1744. */
  1745. AVPacketSideData *coded_side_data;
  1746. int nb_coded_side_data;
  1747. /**
  1748. * Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of
  1749. * metadata exported in frame, packet, or coded stream side data by
  1750. * decoders and encoders.
  1751. *
  1752. * - decoding: set by user
  1753. * - encoding: set by user
  1754. */
  1755. int export_side_data;
  1756. /**
  1757. * The number of pixels per image to maximally accept.
  1758. *
  1759. * - decoding: set by user
  1760. * - encoding: set by user
  1761. */
  1762. int64_t max_pixels;
  1763. /**
  1764. * Video decoding only. Certain video codecs support cropping, meaning that
  1765. * only a sub-rectangle of the decoded frame is intended for display. This
  1766. * option controls how cropping is handled by libavcodec.
  1767. *
  1768. * When set to 1 (the default), libavcodec will apply cropping internally.
  1769. * I.e. it will modify the output frame width/height fields and offset the
  1770. * data pointers (only by as much as possible while preserving alignment, or
  1771. * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
  1772. * the frames output by the decoder refer only to the cropped area. The
  1773. * crop_* fields of the output frames will be zero.
  1774. *
  1775. * When set to 0, the width/height fields of the output frames will be set
  1776. * to the coded dimensions and the crop_* fields will describe the cropping
  1777. * rectangle. Applying the cropping is left to the caller.
  1778. *
  1779. * @warning When hardware acceleration with opaque output frames is used,
  1780. * libavcodec is unable to apply cropping from the top/left border.
  1781. *
  1782. * @note when this option is set to zero, the width/height fields of the
  1783. * AVCodecContext and output AVFrames have different meanings. The codec
  1784. * context fields store display dimensions (with the coded dimensions in
  1785. * coded_width/height), while the frame fields store the coded dimensions
  1786. * (with the display dimensions being determined by the crop_* fields).
  1787. */
  1788. int apply_cropping;
  1789. /**
  1790. * The percentage of damaged samples to discard a frame.
  1791. *
  1792. * - decoding: set by user
  1793. * - encoding: unused
  1794. */
  1795. int discard_damaged_percentage;
  1796. /**
  1797. * The number of samples per frame to maximally accept.
  1798. *
  1799. * - decoding: set by user
  1800. * - encoding: set by user
  1801. */
  1802. int64_t max_samples;
  1803. /**
  1804. * This callback is called at the beginning of each packet to get a data
  1805. * buffer for it.
  1806. *
  1807. * The following field will be set in the packet before this callback is
  1808. * called:
  1809. * - size
  1810. * This callback must use the above value to calculate the required buffer size,
  1811. * which must padded by at least AV_INPUT_BUFFER_PADDING_SIZE bytes.
  1812. *
  1813. * In some specific cases, the encoder may not use the entire buffer allocated by this
  1814. * callback. This will be reflected in the size value in the packet once returned by
  1815. * avcodec_receive_packet().
  1816. *
  1817. * This callback must fill the following fields in the packet:
  1818. * - data: alignment requirements for AVPacket apply, if any. Some architectures and
  1819. * encoders may benefit from having aligned data.
  1820. * - buf: must contain a pointer to an AVBufferRef structure. The packet's
  1821. * data pointer must be contained in it. See: av_buffer_create(), av_buffer_alloc(),
  1822. * and av_buffer_ref().
  1823. *
  1824. * If AV_CODEC_CAP_DR1 is not set then get_encode_buffer() must call
  1825. * avcodec_default_get_encode_buffer() instead of providing a buffer allocated by
  1826. * some other means.
  1827. *
  1828. * The flags field may contain a combination of AV_GET_ENCODE_BUFFER_FLAG_ flags.
  1829. * They may be used for example to hint what use the buffer may get after being
  1830. * created.
  1831. * Implementations of this callback may ignore flags they don't understand.
  1832. * If AV_GET_ENCODE_BUFFER_FLAG_REF is set in flags then the packet may be reused
  1833. * (read and/or written to if it is writable) later by libavcodec.
  1834. *
  1835. * This callback must be thread-safe, as when frame threading is used, it may
  1836. * be called from multiple threads simultaneously.
  1837. *
  1838. * @see avcodec_default_get_encode_buffer()
  1839. *
  1840. * - encoding: Set by libavcodec, user can override.
  1841. * - decoding: unused
  1842. */
  1843. int (*get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int flags);
  1844. /**
  1845. * Frame counter, set by libavcodec.
  1846. *
  1847. * - decoding: total number of frames returned from the decoder so far.
  1848. * - encoding: total number of frames passed to the encoder so far.
  1849. *
  1850. * @note the counter is not incremented if encoding/decoding resulted in
  1851. * an error.
  1852. */
  1853. int64_t frame_num;
  1854. /**
  1855. * Decoding only. May be set by the caller before avcodec_open2() to an
  1856. * av_malloc()'ed array (or via AVOptions). Owned and freed by the decoder
  1857. * afterwards.
  1858. *
  1859. * Side data attached to decoded frames may come from several sources:
  1860. * 1. coded_side_data, which the decoder will for certain types translate
  1861. * from packet-type to frame-type and attach to frames;
  1862. * 2. side data attached to an AVPacket sent for decoding (same
  1863. * considerations as above);
  1864. * 3. extracted from the coded bytestream.
  1865. * The first two cases are supplied by the caller and typically come from a
  1866. * container.
  1867. *
  1868. * This array configures decoder behaviour in cases when side data of the
  1869. * same type is present both in the coded bytestream and in the
  1870. * user-supplied side data (items 1. and 2. above). In all cases, at most
  1871. * one instance of each side data type will be attached to output frames. By
  1872. * default it will be the bytestream side data. Adding an
  1873. * AVPacketSideDataType value to this array will flip the preference for
  1874. * this type, thus making the decoder prefer user-supplied side data over
  1875. * bytestream. In case side data of the same type is present both in
  1876. * coded_data and attacked to a packet, the packet instance always has
  1877. * priority.
  1878. *
  1879. * The array may also contain a single -1, in which case the preference is
  1880. * switched for all side data types.
  1881. */
  1882. int *side_data_prefer_packet;
  1883. /**
  1884. * Number of entries in side_data_prefer_packet.
  1885. */
  1886. unsigned nb_side_data_prefer_packet;
  1887. /**
  1888. * Array containing static side data, such as HDR10 CLL / MDCV structures.
  1889. * Side data entries should be allocated by usage of helpers defined in
  1890. * libavutil/frame.h.
  1891. *
  1892. * - encoding: may be set by user before calling avcodec_open2() for
  1893. * encoder configuration. Afterwards owned and freed by the
  1894. * encoder.
  1895. * - decoding: unused
  1896. */
  1897. AVFrameSideData **decoded_side_data;
  1898. int nb_decoded_side_data;
  1899. } AVCodecContext;
  1900. /**
  1901. * @defgroup lavc_hwaccel AVHWAccel
  1902. *
  1903. * @note Nothing in this structure should be accessed by the user. At some
  1904. * point in future it will not be externally visible at all.
  1905. *
  1906. * @{
  1907. */
  1908. typedef struct AVHWAccel {
  1909. /**
  1910. * Name of the hardware accelerated codec.
  1911. * The name is globally unique among encoders and among decoders (but an
  1912. * encoder and a decoder can share the same name).
  1913. */
  1914. const char *name;
  1915. /**
  1916. * Type of codec implemented by the hardware accelerator.
  1917. *
  1918. * See AVMEDIA_TYPE_xxx
  1919. */
  1920. enum AVMediaType type;
  1921. /**
  1922. * Codec implemented by the hardware accelerator.
  1923. *
  1924. * See AV_CODEC_ID_xxx
  1925. */
  1926. enum AVCodecID id;
  1927. /**
  1928. * Supported pixel format.
  1929. *
  1930. * Only hardware accelerated formats are supported here.
  1931. */
  1932. enum AVPixelFormat pix_fmt;
  1933. /**
  1934. * Hardware accelerated codec capabilities.
  1935. * see AV_HWACCEL_CODEC_CAP_*
  1936. */
  1937. int capabilities;
  1938. } AVHWAccel;
  1939. /**
  1940. * HWAccel is experimental and is thus avoided in favor of non experimental
  1941. * codecs
  1942. */
  1943. #define AV_HWACCEL_CODEC_CAP_EXPERIMENTAL 0x0200
  1944. /**
  1945. * Hardware acceleration should be used for decoding even if the codec level
  1946. * used is unknown or higher than the maximum supported level reported by the
  1947. * hardware driver.
  1948. *
  1949. * It's generally a good idea to pass this flag unless you have a specific
  1950. * reason not to, as hardware tends to under-report supported levels.
  1951. */
  1952. #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
  1953. /**
  1954. * Hardware acceleration can output YUV pixel formats with a different chroma
  1955. * sampling than 4:2:0 and/or other than 8 bits per component.
  1956. */
  1957. #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
  1958. /**
  1959. * Hardware acceleration should still be attempted for decoding when the
  1960. * codec profile does not match the reported capabilities of the hardware.
  1961. *
  1962. * For example, this can be used to try to decode baseline profile H.264
  1963. * streams in hardware - it will often succeed, because many streams marked
  1964. * as baseline profile actually conform to constrained baseline profile.
  1965. *
  1966. * @warning If the stream is actually not supported then the behaviour is
  1967. * undefined, and may include returning entirely incorrect output
  1968. * while indicating success.
  1969. */
  1970. #define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2)
  1971. /**
  1972. * Some hardware decoders (namely nvdec) can either output direct decoder
  1973. * surfaces, or make an on-device copy and return said copy.
  1974. * There is a hard limit on how many decoder surfaces there can be, and it
  1975. * cannot be accurately guessed ahead of time.
  1976. * For some processing chains, this can be okay, but others will run into the
  1977. * limit and in turn produce very confusing errors that require fine tuning of
  1978. * more or less obscure options by the user, or in extreme cases cannot be
  1979. * resolved at all without inserting an avfilter that forces a copy.
  1980. *
  1981. * Thus, the hwaccel will by default make a copy for safety and resilience.
  1982. * If a users really wants to minimize the amount of copies, they can set this
  1983. * flag and ensure their processing chain does not exhaust the surface pool.
  1984. */
  1985. #define AV_HWACCEL_FLAG_UNSAFE_OUTPUT (1 << 3)
  1986. /**
  1987. * @}
  1988. */
  1989. enum AVSubtitleType {
  1990. SUBTITLE_NONE,
  1991. SUBTITLE_BITMAP, ///< A bitmap, pict will be set
  1992. /**
  1993. * Plain text, the text field must be set by the decoder and is
  1994. * authoritative. ass and pict fields may contain approximations.
  1995. */
  1996. SUBTITLE_TEXT,
  1997. /**
  1998. * Formatted text, the ass field must be set by the decoder and is
  1999. * authoritative. pict and text fields may contain approximations.
  2000. */
  2001. SUBTITLE_ASS,
  2002. };
  2003. #define AV_SUBTITLE_FLAG_FORCED 0x00000001
  2004. typedef struct AVSubtitleRect {
  2005. int x; ///< top left corner of pict, undefined when pict is not set
  2006. int y; ///< top left corner of pict, undefined when pict is not set
  2007. int w; ///< width of pict, undefined when pict is not set
  2008. int h; ///< height of pict, undefined when pict is not set
  2009. int nb_colors; ///< number of colors in pict, undefined when pict is not set
  2010. /**
  2011. * data+linesize for the bitmap of this subtitle.
  2012. * Can be set for text/ass as well once they are rendered.
  2013. */
  2014. uint8_t *data[4];
  2015. int linesize[4];
  2016. int flags;
  2017. enum AVSubtitleType type;
  2018. char *text; ///< 0 terminated plain UTF-8 text
  2019. /**
  2020. * 0 terminated ASS/SSA compatible event line.
  2021. * The presentation of this is unaffected by the other values in this
  2022. * struct.
  2023. */
  2024. char *ass;
  2025. } AVSubtitleRect;
  2026. typedef struct AVSubtitle {
  2027. uint16_t format; /* 0 = graphics */
  2028. uint32_t start_display_time; /* relative to packet pts, in ms */
  2029. uint32_t end_display_time; /* relative to packet pts, in ms */
  2030. unsigned num_rects;
  2031. AVSubtitleRect **rects;
  2032. int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
  2033. } AVSubtitle;
  2034. /**
  2035. * Return the LIBAVCODEC_VERSION_INT constant.
  2036. */
  2037. unsigned avcodec_version(void);
  2038. /**
  2039. * Return the libavcodec build-time configuration.
  2040. */
  2041. const char *avcodec_configuration(void);
  2042. /**
  2043. * Return the libavcodec license.
  2044. */
  2045. const char *avcodec_license(void);
  2046. /**
  2047. * Allocate an AVCodecContext and set its fields to default values. The
  2048. * resulting struct should be freed with avcodec_free_context().
  2049. *
  2050. * @param codec if non-NULL, allocate private data and initialize defaults
  2051. * for the given codec. It is illegal to then call avcodec_open2()
  2052. * with a different codec.
  2053. * If NULL, then the codec-specific defaults won't be initialized,
  2054. * which may result in suboptimal default settings (this is
  2055. * important mainly for encoders, e.g. libx264).
  2056. *
  2057. * @return An AVCodecContext filled with default values or NULL on failure.
  2058. */
  2059. AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
  2060. /**
  2061. * Free the codec context and everything associated with it and write NULL to
  2062. * the provided pointer.
  2063. */
  2064. void avcodec_free_context(AVCodecContext **avctx);
  2065. /**
  2066. * Get the AVClass for AVCodecContext. It can be used in combination with
  2067. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  2068. *
  2069. * @see av_opt_find().
  2070. */
  2071. const AVClass *avcodec_get_class(void);
  2072. /**
  2073. * Get the AVClass for AVSubtitleRect. It can be used in combination with
  2074. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  2075. *
  2076. * @see av_opt_find().
  2077. */
  2078. const AVClass *avcodec_get_subtitle_rect_class(void);
  2079. /**
  2080. * Fill the parameters struct based on the values from the supplied codec
  2081. * context. Any allocated fields in par are freed and replaced with duplicates
  2082. * of the corresponding fields in codec.
  2083. *
  2084. * @return >= 0 on success, a negative AVERROR code on failure
  2085. */
  2086. int avcodec_parameters_from_context(struct AVCodecParameters *par,
  2087. const AVCodecContext *codec);
  2088. /**
  2089. * Fill the codec context based on the values from the supplied codec
  2090. * parameters. Any allocated fields in codec that have a corresponding field in
  2091. * par are freed and replaced with duplicates of the corresponding field in par.
  2092. * Fields in codec that do not have a counterpart in par are not touched.
  2093. *
  2094. * @return >= 0 on success, a negative AVERROR code on failure.
  2095. */
  2096. int avcodec_parameters_to_context(AVCodecContext *codec,
  2097. const struct AVCodecParameters *par);
  2098. /**
  2099. * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  2100. * function the context has to be allocated with avcodec_alloc_context3().
  2101. *
  2102. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  2103. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  2104. * retrieving a codec.
  2105. *
  2106. * Depending on the codec, you might need to set options in the codec context
  2107. * also for decoding (e.g. width, height, or the pixel or audio sample format in
  2108. * the case the information is not available in the bitstream, as when decoding
  2109. * raw audio or video).
  2110. *
  2111. * Options in the codec context can be set either by setting them in the options
  2112. * AVDictionary, or by setting the values in the context itself, directly or by
  2113. * using the av_opt_set() API before calling this function.
  2114. *
  2115. * Example:
  2116. * @code
  2117. * av_dict_set(&opts, "b", "2.5M", 0);
  2118. * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
  2119. * if (!codec)
  2120. * exit(1);
  2121. *
  2122. * context = avcodec_alloc_context3(codec);
  2123. *
  2124. * if (avcodec_open2(context, codec, opts) < 0)
  2125. * exit(1);
  2126. * @endcode
  2127. *
  2128. * In the case AVCodecParameters are available (e.g. when demuxing a stream
  2129. * using libavformat, and accessing the AVStream contained in the demuxer), the
  2130. * codec parameters can be copied to the codec context using
  2131. * avcodec_parameters_to_context(), as in the following example:
  2132. *
  2133. * @code
  2134. * AVStream *stream = ...;
  2135. * context = avcodec_alloc_context3(codec);
  2136. * if (avcodec_parameters_to_context(context, stream->codecpar) < 0)
  2137. * exit(1);
  2138. * if (avcodec_open2(context, codec, NULL) < 0)
  2139. * exit(1);
  2140. * @endcode
  2141. *
  2142. * @note Always call this function before using decoding routines (such as
  2143. * @ref avcodec_receive_frame()).
  2144. *
  2145. * @param avctx The context to initialize.
  2146. * @param codec The codec to open this context for. If a non-NULL codec has been
  2147. * previously passed to avcodec_alloc_context3() or
  2148. * for this context, then this parameter MUST be either NULL or
  2149. * equal to the previously passed codec.
  2150. * @param options A dictionary filled with AVCodecContext and codec-private
  2151. * options, which are set on top of the options already set in
  2152. * avctx, can be NULL. On return this object will be filled with
  2153. * options that were not found in the avctx codec context.
  2154. *
  2155. * @return zero on success, a negative value on error
  2156. * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
  2157. * av_dict_set(), av_opt_set(), av_opt_find(), avcodec_parameters_to_context()
  2158. */
  2159. int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
  2160. #if FF_API_AVCODEC_CLOSE
  2161. /**
  2162. * Close a given AVCodecContext and free all the data associated with it
  2163. * (but not the AVCodecContext itself).
  2164. *
  2165. * Calling this function on an AVCodecContext that hasn't been opened will free
  2166. * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
  2167. * codec. Subsequent calls will do nothing.
  2168. *
  2169. * @deprecated Do not use this function. Use avcodec_free_context() to destroy a
  2170. * codec context (either open or closed). Opening and closing a codec context
  2171. * multiple times is not supported anymore -- use multiple codec contexts
  2172. * instead.
  2173. */
  2174. attribute_deprecated
  2175. int avcodec_close(AVCodecContext *avctx);
  2176. #endif
  2177. /**
  2178. * Free all allocated data in the given subtitle struct.
  2179. *
  2180. * @param sub AVSubtitle to free.
  2181. */
  2182. void avsubtitle_free(AVSubtitle *sub);
  2183. /**
  2184. * @}
  2185. */
  2186. /**
  2187. * @addtogroup lavc_decoding
  2188. * @{
  2189. */
  2190. /**
  2191. * The default callback for AVCodecContext.get_buffer2(). It is made public so
  2192. * it can be called by custom get_buffer2() implementations for decoders without
  2193. * AV_CODEC_CAP_DR1 set.
  2194. */
  2195. int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags);
  2196. /**
  2197. * The default callback for AVCodecContext.get_encode_buffer(). It is made public so
  2198. * it can be called by custom get_encode_buffer() implementations for encoders without
  2199. * AV_CODEC_CAP_DR1 set.
  2200. */
  2201. int avcodec_default_get_encode_buffer(AVCodecContext *s, AVPacket *pkt, int flags);
  2202. /**
  2203. * Modify width and height values so that they will result in a memory
  2204. * buffer that is acceptable for the codec if you do not use any horizontal
  2205. * padding.
  2206. *
  2207. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  2208. */
  2209. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  2210. /**
  2211. * Modify width and height values so that they will result in a memory
  2212. * buffer that is acceptable for the codec if you also ensure that all
  2213. * line sizes are a multiple of the respective linesize_align[i].
  2214. *
  2215. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  2216. */
  2217. void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
  2218. int linesize_align[AV_NUM_DATA_POINTERS]);
  2219. /**
  2220. * Decode a subtitle message.
  2221. * Return a negative value on error, otherwise return the number of bytes used.
  2222. * If no subtitle could be decompressed, got_sub_ptr is zero.
  2223. * Otherwise, the subtitle is stored in *sub.
  2224. * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for
  2225. * simplicity, because the performance difference is expected to be negligible
  2226. * and reusing a get_buffer written for video codecs would probably perform badly
  2227. * due to a potentially very different allocation pattern.
  2228. *
  2229. * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
  2230. * and output. This means that for some packets they will not immediately
  2231. * produce decoded output and need to be flushed at the end of decoding to get
  2232. * all the decoded data. Flushing is done by calling this function with packets
  2233. * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
  2234. * returning subtitles. It is safe to flush even those decoders that are not
  2235. * marked with AV_CODEC_CAP_DELAY, then no subtitles will be returned.
  2236. *
  2237. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  2238. * before packets may be fed to the decoder.
  2239. *
  2240. * @param avctx the codec context
  2241. * @param[out] sub The preallocated AVSubtitle in which the decoded subtitle will be stored,
  2242. * must be freed with avsubtitle_free if *got_sub_ptr is set.
  2243. * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
  2244. * @param[in] avpkt The input AVPacket containing the input buffer.
  2245. */
  2246. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  2247. int *got_sub_ptr, const AVPacket *avpkt);
  2248. /**
  2249. * Supply raw packet data as input to a decoder.
  2250. *
  2251. * Internally, this call will copy relevant AVCodecContext fields, which can
  2252. * influence decoding per-packet, and apply them when the packet is actually
  2253. * decoded. (For example AVCodecContext.skip_frame, which might direct the
  2254. * decoder to drop the frame contained by the packet sent with this function.)
  2255. *
  2256. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  2257. * larger than the actual read bytes because some optimized bitstream
  2258. * readers read 32 or 64 bits at once and could read over the end.
  2259. *
  2260. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  2261. * before packets may be fed to the decoder.
  2262. *
  2263. * @param avctx codec context
  2264. * @param[in] avpkt The input AVPacket. Usually, this will be a single video
  2265. * frame, or several complete audio frames.
  2266. * Ownership of the packet remains with the caller, and the
  2267. * decoder will not write to the packet. The decoder may create
  2268. * a reference to the packet data (or copy it if the packet is
  2269. * not reference-counted).
  2270. * Unlike with older APIs, the packet is always fully consumed,
  2271. * and if it contains multiple frames (e.g. some audio codecs),
  2272. * will require you to call avcodec_receive_frame() multiple
  2273. * times afterwards before you can send a new packet.
  2274. * It can be NULL (or an AVPacket with data set to NULL and
  2275. * size set to 0); in this case, it is considered a flush
  2276. * packet, which signals the end of the stream. Sending the
  2277. * first flush packet will return success. Subsequent ones are
  2278. * unnecessary and will return AVERROR_EOF. If the decoder
  2279. * still has frames buffered, it will return them after sending
  2280. * a flush packet.
  2281. *
  2282. * @retval 0 success
  2283. * @retval AVERROR(EAGAIN) input is not accepted in the current state - user
  2284. * must read output with avcodec_receive_frame() (once
  2285. * all output is read, the packet should be resent,
  2286. * and the call will not fail with EAGAIN).
  2287. * @retval AVERROR_EOF the decoder has been flushed, and no new packets can be
  2288. * sent to it (also returned if more than 1 flush
  2289. * packet is sent)
  2290. * @retval AVERROR(EINVAL) codec not opened, it is an encoder, or requires flush
  2291. * @retval AVERROR(ENOMEM) failed to add packet to internal queue, or similar
  2292. * @retval "another negative error code" legitimate decoding errors
  2293. */
  2294. int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
  2295. /**
  2296. * Return decoded output data from a decoder or encoder (when the
  2297. * @ref AV_CODEC_FLAG_RECON_FRAME flag is used).
  2298. *
  2299. * @param avctx codec context
  2300. * @param frame This will be set to a reference-counted video or audio
  2301. * frame (depending on the decoder type) allocated by the
  2302. * codec. Note that the function will always call
  2303. * av_frame_unref(frame) before doing anything else.
  2304. *
  2305. * @retval 0 success, a frame was returned
  2306. * @retval AVERROR(EAGAIN) output is not available in this state - user must
  2307. * try to send new input
  2308. * @retval AVERROR_EOF the codec has been fully flushed, and there will be
  2309. * no more output frames
  2310. * @retval AVERROR(EINVAL) codec not opened, or it is an encoder without the
  2311. * @ref AV_CODEC_FLAG_RECON_FRAME flag enabled
  2312. * @retval "other negative error code" legitimate decoding errors
  2313. */
  2314. int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
  2315. /**
  2316. * Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()
  2317. * to retrieve buffered output packets.
  2318. *
  2319. * @param avctx codec context
  2320. * @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
  2321. * Ownership of the frame remains with the caller, and the
  2322. * encoder will not write to the frame. The encoder may create
  2323. * a reference to the frame data (or copy it if the frame is
  2324. * not reference-counted).
  2325. * It can be NULL, in which case it is considered a flush
  2326. * packet. This signals the end of the stream. If the encoder
  2327. * still has packets buffered, it will return them after this
  2328. * call. Once flushing mode has been entered, additional flush
  2329. * packets are ignored, and sending frames will return
  2330. * AVERROR_EOF.
  2331. *
  2332. * For audio:
  2333. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  2334. * can have any number of samples.
  2335. * If it is not set, frame->nb_samples must be equal to
  2336. * avctx->frame_size for all frames except the last.
  2337. * The final frame may be smaller than avctx->frame_size.
  2338. * @retval 0 success
  2339. * @retval AVERROR(EAGAIN) input is not accepted in the current state - user must
  2340. * read output with avcodec_receive_packet() (once all
  2341. * output is read, the packet should be resent, and the
  2342. * call will not fail with EAGAIN).
  2343. * @retval AVERROR_EOF the encoder has been flushed, and no new frames can
  2344. * be sent to it
  2345. * @retval AVERROR(EINVAL) codec not opened, it is a decoder, or requires flush
  2346. * @retval AVERROR(ENOMEM) failed to add packet to internal queue, or similar
  2347. * @retval "another negative error code" legitimate encoding errors
  2348. */
  2349. int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  2350. /**
  2351. * Read encoded data from the encoder.
  2352. *
  2353. * @param avctx codec context
  2354. * @param avpkt This will be set to a reference-counted packet allocated by the
  2355. * encoder. Note that the function will always call
  2356. * av_packet_unref(avpkt) before doing anything else.
  2357. * @retval 0 success
  2358. * @retval AVERROR(EAGAIN) output is not available in the current state - user must
  2359. * try to send input
  2360. * @retval AVERROR_EOF the encoder has been fully flushed, and there will be no
  2361. * more output packets
  2362. * @retval AVERROR(EINVAL) codec not opened, or it is a decoder
  2363. * @retval "another negative error code" legitimate encoding errors
  2364. */
  2365. int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  2366. /**
  2367. * Create and return a AVHWFramesContext with values adequate for hardware
  2368. * decoding. This is meant to get called from the get_format callback, and is
  2369. * a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx.
  2370. * This API is for decoding with certain hardware acceleration modes/APIs only.
  2371. *
  2372. * The returned AVHWFramesContext is not initialized. The caller must do this
  2373. * with av_hwframe_ctx_init().
  2374. *
  2375. * Calling this function is not a requirement, but makes it simpler to avoid
  2376. * codec or hardware API specific details when manually allocating frames.
  2377. *
  2378. * Alternatively to this, an API user can set AVCodecContext.hw_device_ctx,
  2379. * which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes
  2380. * it unnecessary to call this function or having to care about
  2381. * AVHWFramesContext initialization at all.
  2382. *
  2383. * There are a number of requirements for calling this function:
  2384. *
  2385. * - It must be called from get_format with the same avctx parameter that was
  2386. * passed to get_format. Calling it outside of get_format is not allowed, and
  2387. * can trigger undefined behavior.
  2388. * - The function is not always supported (see description of return values).
  2389. * Even if this function returns successfully, hwaccel initialization could
  2390. * fail later. (The degree to which implementations check whether the stream
  2391. * is actually supported varies. Some do this check only after the user's
  2392. * get_format callback returns.)
  2393. * - The hw_pix_fmt must be one of the choices suggested by get_format. If the
  2394. * user decides to use a AVHWFramesContext prepared with this API function,
  2395. * the user must return the same hw_pix_fmt from get_format.
  2396. * - The device_ref passed to this function must support the given hw_pix_fmt.
  2397. * - After calling this API function, it is the user's responsibility to
  2398. * initialize the AVHWFramesContext (returned by the out_frames_ref parameter),
  2399. * and to set AVCodecContext.hw_frames_ctx to it. If done, this must be done
  2400. * before returning from get_format (this is implied by the normal
  2401. * AVCodecContext.hw_frames_ctx API rules).
  2402. * - The AVHWFramesContext parameters may change every time time get_format is
  2403. * called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So
  2404. * you are inherently required to go through this process again on every
  2405. * get_format call.
  2406. * - It is perfectly possible to call this function without actually using
  2407. * the resulting AVHWFramesContext. One use-case might be trying to reuse a
  2408. * previously initialized AVHWFramesContext, and calling this API function
  2409. * only to test whether the required frame parameters have changed.
  2410. * - Fields that use dynamically allocated values of any kind must not be set
  2411. * by the user unless setting them is explicitly allowed by the documentation.
  2412. * If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque,
  2413. * the new free callback must call the potentially set previous free callback.
  2414. * This API call may set any dynamically allocated fields, including the free
  2415. * callback.
  2416. *
  2417. * The function will set at least the following fields on AVHWFramesContext
  2418. * (potentially more, depending on hwaccel API):
  2419. *
  2420. * - All fields set by av_hwframe_ctx_alloc().
  2421. * - Set the format field to hw_pix_fmt.
  2422. * - Set the sw_format field to the most suited and most versatile format. (An
  2423. * implication is that this will prefer generic formats over opaque formats
  2424. * with arbitrary restrictions, if possible.)
  2425. * - Set the width/height fields to the coded frame size, rounded up to the
  2426. * API-specific minimum alignment.
  2427. * - Only _if_ the hwaccel requires a pre-allocated pool: set the initial_pool_size
  2428. * field to the number of maximum reference surfaces possible with the codec,
  2429. * plus 1 surface for the user to work (meaning the user can safely reference
  2430. * at most 1 decoded surface at a time), plus additional buffering introduced
  2431. * by frame threading. If the hwaccel does not require pre-allocation, the
  2432. * field is left to 0, and the decoder will allocate new surfaces on demand
  2433. * during decoding.
  2434. * - Possibly AVHWFramesContext.hwctx fields, depending on the underlying
  2435. * hardware API.
  2436. *
  2437. * Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but
  2438. * with basic frame parameters set.
  2439. *
  2440. * The function is stateless, and does not change the AVCodecContext or the
  2441. * device_ref AVHWDeviceContext.
  2442. *
  2443. * @param avctx The context which is currently calling get_format, and which
  2444. * implicitly contains all state needed for filling the returned
  2445. * AVHWFramesContext properly.
  2446. * @param device_ref A reference to the AVHWDeviceContext describing the device
  2447. * which will be used by the hardware decoder.
  2448. * @param hw_pix_fmt The hwaccel format you are going to return from get_format.
  2449. * @param out_frames_ref On success, set to a reference to an _uninitialized_
  2450. * AVHWFramesContext, created from the given device_ref.
  2451. * Fields will be set to values required for decoding.
  2452. * Not changed if an error is returned.
  2453. * @return zero on success, a negative value on error. The following error codes
  2454. * have special semantics:
  2455. * AVERROR(ENOENT): the decoder does not support this functionality. Setup
  2456. * is always manual, or it is a decoder which does not
  2457. * support setting AVCodecContext.hw_frames_ctx at all,
  2458. * or it is a software format.
  2459. * AVERROR(EINVAL): it is known that hardware decoding is not supported for
  2460. * this configuration, or the device_ref is not supported
  2461. * for the hwaccel referenced by hw_pix_fmt.
  2462. */
  2463. int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
  2464. AVBufferRef *device_ref,
  2465. enum AVPixelFormat hw_pix_fmt,
  2466. AVBufferRef **out_frames_ref);
  2467. /**
  2468. * @defgroup lavc_parsing Frame parsing
  2469. * @{
  2470. */
  2471. enum AVPictureStructure {
  2472. AV_PICTURE_STRUCTURE_UNKNOWN, ///< unknown
  2473. AV_PICTURE_STRUCTURE_TOP_FIELD, ///< coded as top field
  2474. AV_PICTURE_STRUCTURE_BOTTOM_FIELD, ///< coded as bottom field
  2475. AV_PICTURE_STRUCTURE_FRAME, ///< coded as frame
  2476. };
  2477. typedef struct AVCodecParserContext {
  2478. void *priv_data;
  2479. const struct AVCodecParser *parser;
  2480. int64_t frame_offset; /* offset of the current frame */
  2481. int64_t cur_offset; /* current offset
  2482. (incremented by each av_parser_parse()) */
  2483. int64_t next_frame_offset; /* offset of the next frame */
  2484. /* video info */
  2485. int pict_type; /* XXX: Put it back in AVCodecContext. */
  2486. /**
  2487. * This field is used for proper frame duration computation in lavf.
  2488. * It signals, how much longer the frame duration of the current frame
  2489. * is compared to normal frame duration.
  2490. *
  2491. * frame_duration = (1 + repeat_pict) * time_base
  2492. *
  2493. * It is used by codecs like H.264 to display telecined material.
  2494. */
  2495. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
  2496. int64_t pts; /* pts of the current frame */
  2497. int64_t dts; /* dts of the current frame */
  2498. /* private data */
  2499. int64_t last_pts;
  2500. int64_t last_dts;
  2501. int fetch_timestamp;
  2502. #define AV_PARSER_PTS_NB 4
  2503. int cur_frame_start_index;
  2504. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  2505. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  2506. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  2507. int flags;
  2508. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
  2509. #define PARSER_FLAG_ONCE 0x0002
  2510. /// Set if the parser has a valid file offset
  2511. #define PARSER_FLAG_FETCHED_OFFSET 0x0004
  2512. #define PARSER_FLAG_USE_CODEC_TS 0x1000
  2513. int64_t offset; ///< byte offset from starting packet start
  2514. int64_t cur_frame_end[AV_PARSER_PTS_NB];
  2515. /**
  2516. * Set by parser to 1 for key frames and 0 for non-key frames.
  2517. * It is initialized to -1, so if the parser doesn't set this flag,
  2518. * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
  2519. * will be used.
  2520. */
  2521. int key_frame;
  2522. // Timestamp generation support:
  2523. /**
  2524. * Synchronization point for start of timestamp generation.
  2525. *
  2526. * Set to >0 for sync point, 0 for no sync point and <0 for undefined
  2527. * (default).
  2528. *
  2529. * For example, this corresponds to presence of H.264 buffering period
  2530. * SEI message.
  2531. */
  2532. int dts_sync_point;
  2533. /**
  2534. * Offset of the current timestamp against last timestamp sync point in
  2535. * units of AVCodecContext.time_base.
  2536. *
  2537. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  2538. * contain a valid timestamp offset.
  2539. *
  2540. * Note that the timestamp of sync point has usually a nonzero
  2541. * dts_ref_dts_delta, which refers to the previous sync point. Offset of
  2542. * the next frame after timestamp sync point will be usually 1.
  2543. *
  2544. * For example, this corresponds to H.264 cpb_removal_delay.
  2545. */
  2546. int dts_ref_dts_delta;
  2547. /**
  2548. * Presentation delay of current frame in units of AVCodecContext.time_base.
  2549. *
  2550. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  2551. * contain valid non-negative timestamp delta (presentation time of a frame
  2552. * must not lie in the past).
  2553. *
  2554. * This delay represents the difference between decoding and presentation
  2555. * time of the frame.
  2556. *
  2557. * For example, this corresponds to H.264 dpb_output_delay.
  2558. */
  2559. int pts_dts_delta;
  2560. /**
  2561. * Position of the packet in file.
  2562. *
  2563. * Analogous to cur_frame_pts/dts
  2564. */
  2565. int64_t cur_frame_pos[AV_PARSER_PTS_NB];
  2566. /**
  2567. * Byte position of currently parsed frame in stream.
  2568. */
  2569. int64_t pos;
  2570. /**
  2571. * Previous frame byte position.
  2572. */
  2573. int64_t last_pos;
  2574. /**
  2575. * Duration of the current frame.
  2576. * For audio, this is in units of 1 / AVCodecContext.sample_rate.
  2577. * For all other types, this is in units of AVCodecContext.time_base.
  2578. */
  2579. int duration;
  2580. enum AVFieldOrder field_order;
  2581. /**
  2582. * Indicate whether a picture is coded as a frame, top field or bottom field.
  2583. *
  2584. * For example, H.264 field_pic_flag equal to 0 corresponds to
  2585. * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
  2586. * equal to 1 and bottom_field_flag equal to 0 corresponds to
  2587. * AV_PICTURE_STRUCTURE_TOP_FIELD.
  2588. */
  2589. enum AVPictureStructure picture_structure;
  2590. /**
  2591. * Picture number incremented in presentation or output order.
  2592. * This field may be reinitialized at the first picture of a new sequence.
  2593. *
  2594. * For example, this corresponds to H.264 PicOrderCnt.
  2595. */
  2596. int output_picture_number;
  2597. /**
  2598. * Dimensions of the decoded video intended for presentation.
  2599. */
  2600. int width;
  2601. int height;
  2602. /**
  2603. * Dimensions of the coded video.
  2604. */
  2605. int coded_width;
  2606. int coded_height;
  2607. /**
  2608. * The format of the coded data, corresponds to enum AVPixelFormat for video
  2609. * and for enum AVSampleFormat for audio.
  2610. *
  2611. * Note that a decoder can have considerable freedom in how exactly it
  2612. * decodes the data, so the format reported here might be different from the
  2613. * one returned by a decoder.
  2614. */
  2615. int format;
  2616. } AVCodecParserContext;
  2617. typedef struct AVCodecParser {
  2618. int codec_ids[7]; /* several codec IDs are permitted */
  2619. int priv_data_size;
  2620. int (*parser_init)(AVCodecParserContext *s);
  2621. /* This callback never returns an error, a negative value means that
  2622. * the frame start was in a previous packet. */
  2623. int (*parser_parse)(AVCodecParserContext *s,
  2624. AVCodecContext *avctx,
  2625. const uint8_t **poutbuf, int *poutbuf_size,
  2626. const uint8_t *buf, int buf_size);
  2627. void (*parser_close)(AVCodecParserContext *s);
  2628. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  2629. } AVCodecParser;
  2630. /**
  2631. * Iterate over all registered codec parsers.
  2632. *
  2633. * @param opaque a pointer where libavcodec will store the iteration state. Must
  2634. * point to NULL to start the iteration.
  2635. *
  2636. * @return the next registered codec parser or NULL when the iteration is
  2637. * finished
  2638. */
  2639. const AVCodecParser *av_parser_iterate(void **opaque);
  2640. AVCodecParserContext *av_parser_init(int codec_id);
  2641. /**
  2642. * Parse a packet.
  2643. *
  2644. * @param s parser context.
  2645. * @param avctx codec context.
  2646. * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
  2647. * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
  2648. * @param buf input buffer.
  2649. * @param buf_size buffer size in bytes without the padding. I.e. the full buffer
  2650. size is assumed to be buf_size + AV_INPUT_BUFFER_PADDING_SIZE.
  2651. To signal EOF, this should be 0 (so that the last frame
  2652. can be output).
  2653. * @param pts input presentation timestamp.
  2654. * @param dts input decoding timestamp.
  2655. * @param pos input byte position in stream.
  2656. * @return the number of bytes of the input bitstream used.
  2657. *
  2658. * Example:
  2659. * @code
  2660. * while(in_len){
  2661. * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
  2662. * in_data, in_len,
  2663. * pts, dts, pos);
  2664. * in_data += len;
  2665. * in_len -= len;
  2666. *
  2667. * if(size)
  2668. * decode_frame(data, size);
  2669. * }
  2670. * @endcode
  2671. */
  2672. int av_parser_parse2(AVCodecParserContext *s,
  2673. AVCodecContext *avctx,
  2674. uint8_t **poutbuf, int *poutbuf_size,
  2675. const uint8_t *buf, int buf_size,
  2676. int64_t pts, int64_t dts,
  2677. int64_t pos);
  2678. void av_parser_close(AVCodecParserContext *s);
  2679. /**
  2680. * @}
  2681. * @}
  2682. */
  2683. /**
  2684. * @addtogroup lavc_encoding
  2685. * @{
  2686. */
  2687. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  2688. const AVSubtitle *sub);
  2689. /**
  2690. * @}
  2691. */
  2692. /**
  2693. * @defgroup lavc_misc Utility functions
  2694. * @ingroup libavc
  2695. *
  2696. * Miscellaneous utility functions related to both encoding and decoding
  2697. * (or neither).
  2698. * @{
  2699. */
  2700. /**
  2701. * @defgroup lavc_misc_pixfmt Pixel formats
  2702. *
  2703. * Functions for working with pixel formats.
  2704. * @{
  2705. */
  2706. /**
  2707. * Return a value representing the fourCC code associated to the
  2708. * pixel format pix_fmt, or 0 if no associated fourCC code can be
  2709. * found.
  2710. */
  2711. unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt);
  2712. /**
  2713. * Find the best pixel format to convert to given a certain source pixel
  2714. * format. When converting from one pixel format to another, information loss
  2715. * may occur. For example, when converting from RGB24 to GRAY, the color
  2716. * information will be lost. Similarly, other losses occur when converting from
  2717. * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches which of
  2718. * the given pixel formats should be used to suffer the least amount of loss.
  2719. * The pixel formats from which it chooses one, are determined by the
  2720. * pix_fmt_list parameter.
  2721. *
  2722. *
  2723. * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
  2724. * @param[in] src_pix_fmt source pixel format
  2725. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  2726. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
  2727. * @return The best pixel format to convert to or -1 if none was found.
  2728. */
  2729. enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *pix_fmt_list,
  2730. enum AVPixelFormat src_pix_fmt,
  2731. int has_alpha, int *loss_ptr);
  2732. enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  2733. /**
  2734. * @}
  2735. */
  2736. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  2737. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
  2738. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
  2739. //FIXME func typedef
  2740. /**
  2741. * Fill AVFrame audio data and linesize pointers.
  2742. *
  2743. * The buffer buf must be a preallocated buffer with a size big enough
  2744. * to contain the specified samples amount. The filled AVFrame data
  2745. * pointers will point to this buffer.
  2746. *
  2747. * AVFrame extended_data channel pointers are allocated if necessary for
  2748. * planar audio.
  2749. *
  2750. * @param frame the AVFrame
  2751. * frame->nb_samples must be set prior to calling the
  2752. * function. This function fills in frame->data,
  2753. * frame->extended_data, frame->linesize[0].
  2754. * @param nb_channels channel count
  2755. * @param sample_fmt sample format
  2756. * @param buf buffer to use for frame data
  2757. * @param buf_size size of buffer
  2758. * @param align plane size sample alignment (0 = default)
  2759. * @return >=0 on success, negative error code on failure
  2760. * @todo return the size in bytes required to store the samples in
  2761. * case of success, at the next libavutil bump
  2762. */
  2763. int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
  2764. enum AVSampleFormat sample_fmt, const uint8_t *buf,
  2765. int buf_size, int align);
  2766. /**
  2767. * Reset the internal codec state / flush internal buffers. Should be called
  2768. * e.g. when seeking or when switching to a different stream.
  2769. *
  2770. * @note for decoders, this function just releases any references the decoder
  2771. * might keep internally, but the caller's references remain valid.
  2772. *
  2773. * @note for encoders, this function will only do something if the encoder
  2774. * declares support for AV_CODEC_CAP_ENCODER_FLUSH. When called, the encoder
  2775. * will drain any remaining packets, and can then be re-used for a different
  2776. * stream (as opposed to sending a null frame which will leave the encoder
  2777. * in a permanent EOF state after draining). This can be desirable if the
  2778. * cost of tearing down and replacing the encoder instance is high.
  2779. */
  2780. void avcodec_flush_buffers(AVCodecContext *avctx);
  2781. /**
  2782. * Return audio frame duration.
  2783. *
  2784. * @param avctx codec context
  2785. * @param frame_bytes size of the frame, or 0 if unknown
  2786. * @return frame duration, in samples, if known. 0 if not able to
  2787. * determine.
  2788. */
  2789. int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
  2790. /* memory */
  2791. /**
  2792. * Same behaviour av_fast_malloc but the buffer has additional
  2793. * AV_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
  2794. *
  2795. * In addition the whole buffer will initially and after resizes
  2796. * be 0-initialized so that no uninitialized data will ever appear.
  2797. */
  2798. void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
  2799. /**
  2800. * Same behaviour av_fast_padded_malloc except that buffer will always
  2801. * be 0-initialized after call.
  2802. */
  2803. void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
  2804. /**
  2805. * @return a positive value if s is open (i.e. avcodec_open2() was called on it
  2806. * with no corresponding avcodec_close()), 0 otherwise.
  2807. */
  2808. int avcodec_is_open(AVCodecContext *s);
  2809. /**
  2810. * @}
  2811. */
  2812. #endif /* AVCODEC_AVCODEC_H */