No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

avcodec.h 114KB

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