avcodec.h 110 KB

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