avcodec.h 112 KB

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