avcodec.h 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142
  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 <errno.h>
  28. #include "libavutil/samplefmt.h"
  29. #include "libavutil/attributes.h"
  30. #include "libavutil/avutil.h"
  31. #include "libavutil/buffer.h"
  32. #include "libavutil/cpu.h"
  33. #include "libavutil/channel_layout.h"
  34. #include "libavutil/dict.h"
  35. #include "libavutil/frame.h"
  36. #include "libavutil/hwcontext.h"
  37. #include "libavutil/log.h"
  38. #include "libavutil/pixfmt.h"
  39. #include "libavutil/rational.h"
  40. #include "bsf.h"
  41. #include "codec.h"
  42. #include "codec_desc.h"
  43. #include "codec_par.h"
  44. #include "codec_id.h"
  45. #include "packet.h"
  46. #include "version.h"
  47. /**
  48. * @defgroup libavc libavcodec
  49. * Encoding/Decoding Library
  50. *
  51. * @{
  52. *
  53. * @defgroup lavc_decoding Decoding
  54. * @{
  55. * @}
  56. *
  57. * @defgroup lavc_encoding Encoding
  58. * @{
  59. * @}
  60. *
  61. * @defgroup lavc_codec Codecs
  62. * @{
  63. * @defgroup lavc_codec_native Native Codecs
  64. * @{
  65. * @}
  66. * @defgroup lavc_codec_wrappers External library wrappers
  67. * @{
  68. * @}
  69. * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
  70. * @{
  71. * @}
  72. * @}
  73. * @defgroup lavc_internal Internal
  74. * @{
  75. * @}
  76. * @}
  77. */
  78. /**
  79. * @ingroup libavc
  80. * @defgroup lavc_encdec send/receive encoding and decoding API overview
  81. * @{
  82. *
  83. * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/
  84. * avcodec_receive_packet() functions provide an encode/decode API, which
  85. * decouples input and output.
  86. *
  87. * The API is very similar for encoding/decoding and audio/video, and works as
  88. * follows:
  89. * - Set up and open the AVCodecContext as usual.
  90. * - Send valid input:
  91. * - For decoding, call avcodec_send_packet() to give the decoder raw
  92. * compressed data in an AVPacket.
  93. * - For encoding, call avcodec_send_frame() to give the encoder an AVFrame
  94. * containing uncompressed audio or video.
  95. *
  96. * In both cases, it is recommended that AVPackets and AVFrames are
  97. * refcounted, or libavcodec might have to copy the input data. (libavformat
  98. * always returns refcounted AVPackets, and av_frame_get_buffer() allocates
  99. * refcounted AVFrames.)
  100. * - Receive output in a loop. Periodically call one of the avcodec_receive_*()
  101. * functions and process their output:
  102. * - For decoding, call avcodec_receive_frame(). On success, it will return
  103. * an AVFrame containing uncompressed audio or video data.
  104. * - For encoding, call avcodec_receive_packet(). On success, it will return
  105. * an AVPacket with a compressed frame.
  106. *
  107. * Repeat this call until it returns AVERROR(EAGAIN) or an error. The
  108. * AVERROR(EAGAIN) return value means that new input data is required to
  109. * return new output. In this case, continue with sending input. For each
  110. * input frame/packet, the codec will typically return 1 output frame/packet,
  111. * but it can also be 0 or more than 1.
  112. *
  113. * At the beginning of decoding or encoding, the codec might accept multiple
  114. * input frames/packets without returning a frame, until its internal buffers
  115. * are filled. This situation is handled transparently if you follow the steps
  116. * outlined above.
  117. *
  118. * In theory, sending input can result in EAGAIN - this should happen only if
  119. * not all output was received. You can use this to structure alternative decode
  120. * or encode loops other than the one suggested above. For example, you could
  121. * try sending new input on each iteration, and try to receive output if that
  122. * returns EAGAIN.
  123. *
  124. * End of stream situations. These require "flushing" (aka draining) the codec,
  125. * as the codec might buffer multiple frames or packets internally for
  126. * performance or out of necessity (consider B-frames).
  127. * This is handled as follows:
  128. * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding)
  129. * or avcodec_send_frame() (encoding) functions. This will enter draining
  130. * mode.
  131. * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet()
  132. * (encoding) in a loop until AVERROR_EOF is returned. The functions will
  133. * not return AVERROR(EAGAIN), unless you forgot to enter draining mode.
  134. * - Before decoding can be resumed again, the codec has to be reset with
  135. * avcodec_flush_buffers().
  136. *
  137. * Using the API as outlined above is highly recommended. But it is also
  138. * possible to call functions outside of this rigid schema. For example, you can
  139. * call avcodec_send_packet() repeatedly without calling
  140. * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed
  141. * until the codec's internal buffer has been filled up (which is typically of
  142. * size 1 per output frame, after initial input), and then reject input with
  143. * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to
  144. * read at least some output.
  145. *
  146. * Not all codecs will follow a rigid and predictable dataflow; the only
  147. * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on
  148. * one end implies that a receive/send call on the other end will succeed, or
  149. * at least will not fail with AVERROR(EAGAIN). In general, no codec will
  150. * permit unlimited buffering of input or output.
  151. *
  152. * This API replaces the following legacy functions:
  153. * - avcodec_decode_video2() and avcodec_decode_audio4():
  154. * Use avcodec_send_packet() to feed input to the decoder, then use
  155. * avcodec_receive_frame() to receive decoded frames after each packet.
  156. * Unlike with the old video decoding API, multiple frames might result from
  157. * a packet. For audio, splitting the input packet into frames by partially
  158. * decoding packets becomes transparent to the API user. You never need to
  159. * feed an AVPacket to the API twice (unless it is rejected with AVERROR(EAGAIN) - then
  160. * no data was read from the packet).
  161. * Additionally, sending a flush/draining packet is required only once.
  162. * - avcodec_encode_video2()/avcodec_encode_audio2():
  163. * Use avcodec_send_frame() to feed input to the encoder, then use
  164. * avcodec_receive_packet() to receive encoded packets.
  165. * Providing user-allocated buffers for avcodec_receive_packet() is not
  166. * possible.
  167. * - The new API does not handle subtitles yet.
  168. *
  169. * Mixing new and old function calls on the same AVCodecContext is not allowed,
  170. * and will result in undefined behavior.
  171. *
  172. * Some codecs might require using the new API; using the old API will return
  173. * an error when calling it. All codecs support the new API.
  174. *
  175. * A codec is not allowed to return AVERROR(EAGAIN) for both sending and receiving. This
  176. * would be an invalid state, which could put the codec user into an endless
  177. * loop. The API has no concept of time either: it cannot happen that trying to
  178. * do avcodec_send_packet() results in AVERROR(EAGAIN), but a repeated call 1 second
  179. * later accepts the packet (with no other receive/flush API calls involved).
  180. * The API is a strict state machine, and the passage of time is not supposed
  181. * to influence it. Some timing-dependent behavior might still be deemed
  182. * acceptable in certain cases. But it must never result in both send/receive
  183. * returning EAGAIN at the same time at any point. It must also absolutely be
  184. * avoided that the current state is "unstable" and can "flip-flop" between
  185. * the send/receive APIs allowing progress. For example, it's not allowed that
  186. * the codec randomly decides that it actually wants to consume a packet now
  187. * instead of returning a frame, after it just returned AVERROR(EAGAIN) on an
  188. * avcodec_send_packet() call.
  189. * @}
  190. */
  191. /**
  192. * @defgroup lavc_core Core functions/structures.
  193. * @ingroup libavc
  194. *
  195. * Basic definitions, functions for querying libavcodec capabilities,
  196. * allocating core structures, etc.
  197. * @{
  198. */
  199. /**
  200. * @ingroup lavc_decoding
  201. * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
  202. * This is mainly needed because some optimized bitstream readers read
  203. * 32 or 64 bit at once and could read over the end.<br>
  204. * Note: If the first 23 bits of the additional bytes are not 0, then damaged
  205. * MPEG bitstreams could cause overread and segfault.
  206. */
  207. #define AV_INPUT_BUFFER_PADDING_SIZE 64
  208. /**
  209. * @ingroup lavc_encoding
  210. * minimum encoding buffer size
  211. * Used to avoid some checks during header writing.
  212. */
  213. #define AV_INPUT_BUFFER_MIN_SIZE 16384
  214. /**
  215. * @ingroup lavc_decoding
  216. */
  217. enum AVDiscard{
  218. /* We leave some space between them for extensions (drop some
  219. * keyframes for intra-only or drop just some bidir frames). */
  220. AVDISCARD_NONE =-16, ///< discard nothing
  221. AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
  222. AVDISCARD_NONREF = 8, ///< discard all non reference
  223. AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
  224. AVDISCARD_NONINTRA= 24, ///< discard all non intra frames
  225. AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
  226. AVDISCARD_ALL = 48, ///< discard all
  227. };
  228. enum AVAudioServiceType {
  229. AV_AUDIO_SERVICE_TYPE_MAIN = 0,
  230. AV_AUDIO_SERVICE_TYPE_EFFECTS = 1,
  231. AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
  232. AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED = 3,
  233. AV_AUDIO_SERVICE_TYPE_DIALOGUE = 4,
  234. AV_AUDIO_SERVICE_TYPE_COMMENTARY = 5,
  235. AV_AUDIO_SERVICE_TYPE_EMERGENCY = 6,
  236. AV_AUDIO_SERVICE_TYPE_VOICE_OVER = 7,
  237. AV_AUDIO_SERVICE_TYPE_KARAOKE = 8,
  238. AV_AUDIO_SERVICE_TYPE_NB , ///< Not part of ABI
  239. };
  240. /**
  241. * @ingroup lavc_encoding
  242. */
  243. typedef struct RcOverride{
  244. int start_frame;
  245. int end_frame;
  246. int qscale; // If this is 0 then quality_factor will be used instead.
  247. float quality_factor;
  248. } RcOverride;
  249. /* encoding support
  250. These flags can be passed in AVCodecContext.flags before initialization.
  251. Note: Not everything is supported yet.
  252. */
  253. /**
  254. * Allow decoders to produce frames with data planes that are not aligned
  255. * to CPU requirements (e.g. due to cropping).
  256. */
  257. #define AV_CODEC_FLAG_UNALIGNED (1 << 0)
  258. /**
  259. * Use fixed qscale.
  260. */
  261. #define AV_CODEC_FLAG_QSCALE (1 << 1)
  262. /**
  263. * 4 MV per MB allowed / advanced prediction for H.263.
  264. */
  265. #define AV_CODEC_FLAG_4MV (1 << 2)
  266. /**
  267. * Output even those frames that might be corrupted.
  268. */
  269. #define AV_CODEC_FLAG_OUTPUT_CORRUPT (1 << 3)
  270. /**
  271. * Use qpel MC.
  272. */
  273. #define AV_CODEC_FLAG_QPEL (1 << 4)
  274. /**
  275. * Don't output frames whose parameters differ from first
  276. * decoded frame in stream.
  277. */
  278. #define AV_CODEC_FLAG_DROPCHANGED (1 << 5)
  279. /**
  280. * Use internal 2pass ratecontrol in first pass mode.
  281. */
  282. #define AV_CODEC_FLAG_PASS1 (1 << 9)
  283. /**
  284. * Use internal 2pass ratecontrol in second pass mode.
  285. */
  286. #define AV_CODEC_FLAG_PASS2 (1 << 10)
  287. /**
  288. * loop filter.
  289. */
  290. #define AV_CODEC_FLAG_LOOP_FILTER (1 << 11)
  291. /**
  292. * Only decode/encode grayscale.
  293. */
  294. #define AV_CODEC_FLAG_GRAY (1 << 13)
  295. /**
  296. * error[?] variables will be set during encoding.
  297. */
  298. #define AV_CODEC_FLAG_PSNR (1 << 15)
  299. /**
  300. * Input bitstream might be truncated at a random location
  301. * instead of only at frame boundaries.
  302. */
  303. #define AV_CODEC_FLAG_TRUNCATED (1 << 16)
  304. /**
  305. * Use interlaced DCT.
  306. */
  307. #define AV_CODEC_FLAG_INTERLACED_DCT (1 << 18)
  308. /**
  309. * Force low delay.
  310. */
  311. #define AV_CODEC_FLAG_LOW_DELAY (1 << 19)
  312. /**
  313. * Place global headers in extradata instead of every keyframe.
  314. */
  315. #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
  316. /**
  317. * Use only bitexact stuff (except (I)DCT).
  318. */
  319. #define AV_CODEC_FLAG_BITEXACT (1 << 23)
  320. /* Fx : Flag for H.263+ extra options */
  321. /**
  322. * H.263 advanced intra coding / MPEG-4 AC prediction
  323. */
  324. #define AV_CODEC_FLAG_AC_PRED (1 << 24)
  325. /**
  326. * interlaced motion estimation
  327. */
  328. #define AV_CODEC_FLAG_INTERLACED_ME (1 << 29)
  329. #define AV_CODEC_FLAG_CLOSED_GOP (1U << 31)
  330. /**
  331. * Allow non spec compliant speedup tricks.
  332. */
  333. #define AV_CODEC_FLAG2_FAST (1 << 0)
  334. /**
  335. * Skip bitstream encoding.
  336. */
  337. #define AV_CODEC_FLAG2_NO_OUTPUT (1 << 2)
  338. /**
  339. * Place global headers at every keyframe instead of in extradata.
  340. */
  341. #define AV_CODEC_FLAG2_LOCAL_HEADER (1 << 3)
  342. /**
  343. * timecode is in drop frame format. DEPRECATED!!!!
  344. */
  345. #define AV_CODEC_FLAG2_DROP_FRAME_TIMECODE (1 << 13)
  346. /**
  347. * Input bitstream might be truncated at a packet boundaries
  348. * instead of only at frame boundaries.
  349. */
  350. #define AV_CODEC_FLAG2_CHUNKS (1 << 15)
  351. /**
  352. * Discard cropping information from SPS.
  353. */
  354. #define AV_CODEC_FLAG2_IGNORE_CROP (1 << 16)
  355. /**
  356. * Show all frames before the first keyframe
  357. */
  358. #define AV_CODEC_FLAG2_SHOW_ALL (1 << 22)
  359. /**
  360. * Export motion vectors through frame side data
  361. */
  362. #define AV_CODEC_FLAG2_EXPORT_MVS (1 << 28)
  363. /**
  364. * Do not skip samples and export skip information as frame side data
  365. */
  366. #define AV_CODEC_FLAG2_SKIP_MANUAL (1 << 29)
  367. /**
  368. * Do not reset ASS ReadOrder field on flush (subtitles decoding)
  369. */
  370. #define AV_CODEC_FLAG2_RO_FLUSH_NOOP (1 << 30)
  371. /* Unsupported options :
  372. * Syntax Arithmetic coding (SAC)
  373. * Reference Picture Selection
  374. * Independent Segment Decoding */
  375. /* /Fx */
  376. /* codec capabilities */
  377. /* Exported side data.
  378. These flags can be passed in AVCodecContext.export_side_data before initialization.
  379. */
  380. /**
  381. * Export motion vectors through frame side data
  382. */
  383. #define AV_CODEC_EXPORT_DATA_MVS (1 << 0)
  384. /**
  385. * Export encoder Producer Reference Time through packet side data
  386. */
  387. #define AV_CODEC_EXPORT_DATA_PRFT (1 << 1)
  388. /**
  389. * Decoding only.
  390. * Export the AVVideoEncParams structure through frame side data.
  391. */
  392. #define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS (1 << 2)
  393. /**
  394. * Pan Scan area.
  395. * This specifies the area which should be displayed.
  396. * Note there may be multiple such areas for one frame.
  397. */
  398. typedef struct AVPanScan {
  399. /**
  400. * id
  401. * - encoding: Set by user.
  402. * - decoding: Set by libavcodec.
  403. */
  404. int id;
  405. /**
  406. * width and height in 1/16 pel
  407. * - encoding: Set by user.
  408. * - decoding: Set by libavcodec.
  409. */
  410. int width;
  411. int height;
  412. /**
  413. * position of the top left corner in 1/16 pel for up to 3 fields/frames
  414. * - encoding: Set by user.
  415. * - decoding: Set by libavcodec.
  416. */
  417. int16_t position[3][2];
  418. } AVPanScan;
  419. /**
  420. * This structure describes the bitrate properties of an encoded bitstream. It
  421. * roughly corresponds to a subset the VBV parameters for MPEG-2 or HRD
  422. * parameters for H.264/HEVC.
  423. */
  424. typedef struct AVCPBProperties {
  425. /**
  426. * Maximum bitrate of the stream, in bits per second.
  427. * Zero if unknown or unspecified.
  428. */
  429. #if FF_API_UNSANITIZED_BITRATES
  430. int max_bitrate;
  431. #else
  432. int64_t max_bitrate;
  433. #endif
  434. /**
  435. * Minimum bitrate of the stream, in bits per second.
  436. * Zero if unknown or unspecified.
  437. */
  438. #if FF_API_UNSANITIZED_BITRATES
  439. int min_bitrate;
  440. #else
  441. int64_t min_bitrate;
  442. #endif
  443. /**
  444. * Average bitrate of the stream, in bits per second.
  445. * Zero if unknown or unspecified.
  446. */
  447. #if FF_API_UNSANITIZED_BITRATES
  448. int avg_bitrate;
  449. #else
  450. int64_t avg_bitrate;
  451. #endif
  452. /**
  453. * The size of the buffer to which the ratecontrol is applied, in bits.
  454. * Zero if unknown or unspecified.
  455. */
  456. int buffer_size;
  457. /**
  458. * The delay between the time the packet this structure is associated with
  459. * is received and the time when it should be decoded, in periods of a 27MHz
  460. * clock.
  461. *
  462. * UINT64_MAX when unknown or unspecified.
  463. */
  464. uint64_t vbv_delay;
  465. } AVCPBProperties;
  466. /**
  467. * This structure supplies correlation between a packet timestamp and a wall clock
  468. * production time. The definition follows the Producer Reference Time ('prft')
  469. * as defined in ISO/IEC 14496-12
  470. */
  471. typedef struct AVProducerReferenceTime {
  472. /**
  473. * A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
  474. */
  475. int64_t wallclock;
  476. int flags;
  477. } AVProducerReferenceTime;
  478. /**
  479. * The decoder will keep a reference to the frame and may reuse it later.
  480. */
  481. #define AV_GET_BUFFER_FLAG_REF (1 << 0)
  482. struct AVCodecInternal;
  483. /**
  484. * main external API structure.
  485. * New fields can be added to the end with minor version bumps.
  486. * Removal, reordering and changes to existing fields require a major
  487. * version bump.
  488. * You can use AVOptions (av_opt* / av_set/get*()) to access these fields from user
  489. * applications.
  490. * The name string for AVOptions options matches the associated command line
  491. * parameter name and can be found in libavcodec/options_table.h
  492. * The AVOption/command line parameter names differ in some cases from the C
  493. * structure field names for historic reasons or brevity.
  494. * sizeof(AVCodecContext) must not be used outside libav*.
  495. */
  496. typedef struct AVCodecContext {
  497. /**
  498. * information on struct for av_log
  499. * - set by avcodec_alloc_context3
  500. */
  501. const AVClass *av_class;
  502. int log_level_offset;
  503. enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
  504. const struct AVCodec *codec;
  505. enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
  506. /**
  507. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  508. * This is used to work around some encoder bugs.
  509. * A demuxer should set this to what is stored in the field used to identify the codec.
  510. * If there are multiple such fields in a container then the demuxer should choose the one
  511. * which maximizes the information about the used codec.
  512. * If the codec tag field in a container is larger than 32 bits then the demuxer should
  513. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  514. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  515. * first.
  516. * - encoding: Set by user, if not then the default based on codec_id will be used.
  517. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  518. */
  519. unsigned int codec_tag;
  520. void *priv_data;
  521. /**
  522. * Private context used for internal data.
  523. *
  524. * Unlike priv_data, this is not codec-specific. It is used in general
  525. * libavcodec functions.
  526. */
  527. struct AVCodecInternal *internal;
  528. /**
  529. * Private data of the user, can be used to carry app specific stuff.
  530. * - encoding: Set by user.
  531. * - decoding: Set by user.
  532. */
  533. void *opaque;
  534. /**
  535. * the average bitrate
  536. * - encoding: Set by user; unused for constant quantizer encoding.
  537. * - decoding: Set by user, may be overwritten by libavcodec
  538. * if this info is available in the stream
  539. */
  540. int64_t bit_rate;
  541. /**
  542. * number of bits the bitstream is allowed to diverge from the reference.
  543. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  544. * - encoding: Set by user; unused for constant quantizer encoding.
  545. * - decoding: unused
  546. */
  547. int bit_rate_tolerance;
  548. /**
  549. * Global quality for codecs which cannot change it per frame.
  550. * This should be proportional to MPEG-1/2/4 qscale.
  551. * - encoding: Set by user.
  552. * - decoding: unused
  553. */
  554. int global_quality;
  555. /**
  556. * - encoding: Set by user.
  557. * - decoding: unused
  558. */
  559. int compression_level;
  560. #define FF_COMPRESSION_DEFAULT -1
  561. /**
  562. * AV_CODEC_FLAG_*.
  563. * - encoding: Set by user.
  564. * - decoding: Set by user.
  565. */
  566. int flags;
  567. /**
  568. * AV_CODEC_FLAG2_*
  569. * - encoding: Set by user.
  570. * - decoding: Set by user.
  571. */
  572. int flags2;
  573. /**
  574. * some codecs need / can use extradata like Huffman tables.
  575. * MJPEG: Huffman tables
  576. * rv10: additional flags
  577. * MPEG-4: global headers (they can be in the bitstream or here)
  578. * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
  579. * than extradata_size to avoid problems if it is read with the bitstream reader.
  580. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  581. * Must be allocated with the av_malloc() family of functions.
  582. * - encoding: Set/allocated/freed by libavcodec.
  583. * - decoding: Set/allocated/freed by user.
  584. */
  585. uint8_t *extradata;
  586. int extradata_size;
  587. /**
  588. * This is the fundamental unit of time (in seconds) in terms
  589. * of which frame timestamps are represented. For fixed-fps content,
  590. * timebase should be 1/framerate and timestamp increments should be
  591. * identically 1.
  592. * This often, but not always is the inverse of the frame rate or field rate
  593. * for video. 1/time_base is not the average frame rate if the frame rate is not
  594. * constant.
  595. *
  596. * Like containers, elementary streams also can store timestamps, 1/time_base
  597. * is the unit in which these timestamps are specified.
  598. * As example of such codec time base see ISO/IEC 14496-2:2001(E)
  599. * vop_time_increment_resolution and fixed_vop_rate
  600. * (fixed_vop_rate == 0 implies that it is different from the framerate)
  601. *
  602. * - encoding: MUST be set by user.
  603. * - decoding: the use of this field for decoding is deprecated.
  604. * Use framerate instead.
  605. */
  606. AVRational time_base;
  607. /**
  608. * For some codecs, the time base is closer to the field rate than the frame rate.
  609. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
  610. * if no telecine is used ...
  611. *
  612. * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
  613. */
  614. int ticks_per_frame;
  615. /**
  616. * Codec delay.
  617. *
  618. * Encoding: Number of frames delay there will be from the encoder input to
  619. * the decoder output. (we assume the decoder matches the spec)
  620. * Decoding: Number of frames delay in addition to what a standard decoder
  621. * as specified in the spec would produce.
  622. *
  623. * Video:
  624. * Number of frames the decoded output will be delayed relative to the
  625. * encoded input.
  626. *
  627. * Audio:
  628. * For encoding, this field is unused (see initial_padding).
  629. *
  630. * For decoding, this is the number of samples the decoder needs to
  631. * output before the decoder's output is valid. When seeking, you should
  632. * start decoding this many samples prior to your desired seek point.
  633. *
  634. * - encoding: Set by libavcodec.
  635. * - decoding: Set by libavcodec.
  636. */
  637. int delay;
  638. /* video only */
  639. /**
  640. * picture width / height.
  641. *
  642. * @note Those fields may not match the values of the last
  643. * AVFrame output by avcodec_decode_video2 due frame
  644. * reordering.
  645. *
  646. * - encoding: MUST be set by user.
  647. * - decoding: May be set by the user before opening the decoder if known e.g.
  648. * from the container. Some decoders will require the dimensions
  649. * to be set by the caller. During decoding, the decoder may
  650. * overwrite those values as required while parsing the data.
  651. */
  652. int width, height;
  653. /**
  654. * Bitstream width / height, may be different from width/height e.g. when
  655. * the decoded frame is cropped before being output or lowres is enabled.
  656. *
  657. * @note Those field may not match the value of the last
  658. * AVFrame output by avcodec_receive_frame() due frame
  659. * reordering.
  660. *
  661. * - encoding: unused
  662. * - decoding: May be set by the user before opening the decoder if known
  663. * e.g. from the container. During decoding, the decoder may
  664. * overwrite those values as required while parsing the data.
  665. */
  666. int coded_width, coded_height;
  667. /**
  668. * the number of pictures in a group of pictures, or 0 for intra_only
  669. * - encoding: Set by user.
  670. * - decoding: unused
  671. */
  672. int gop_size;
  673. /**
  674. * Pixel format, see AV_PIX_FMT_xxx.
  675. * May be set by the demuxer if known from headers.
  676. * May be overridden by the decoder if it knows better.
  677. *
  678. * @note This field may not match the value of the last
  679. * AVFrame output by avcodec_receive_frame() due frame
  680. * reordering.
  681. *
  682. * - encoding: Set by user.
  683. * - decoding: Set by user if known, overridden by libavcodec while
  684. * parsing the data.
  685. */
  686. enum AVPixelFormat pix_fmt;
  687. /**
  688. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  689. * decoder to draw a horizontal band. It improves cache usage. Not
  690. * all codecs can do that. You must check the codec capabilities
  691. * beforehand.
  692. * When multithreading is used, it may be called from multiple threads
  693. * at the same time; threads might draw different parts of the same AVFrame,
  694. * or multiple AVFrames, and there is no guarantee that slices will be drawn
  695. * in order.
  696. * The function is also used by hardware acceleration APIs.
  697. * It is called at least once during frame decoding to pass
  698. * the data needed for hardware render.
  699. * In that mode instead of pixel data, AVFrame points to
  700. * a structure specific to the acceleration API. The application
  701. * reads the structure and can change some fields to indicate progress
  702. * or mark state.
  703. * - encoding: unused
  704. * - decoding: Set by user.
  705. * @param height the height of the slice
  706. * @param y the y position of the slice
  707. * @param type 1->top field, 2->bottom field, 3->frame
  708. * @param offset offset into the AVFrame.data from which the slice should be read
  709. */
  710. void (*draw_horiz_band)(struct AVCodecContext *s,
  711. const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
  712. int y, int type, int height);
  713. /**
  714. * callback to negotiate the pixelFormat
  715. * @param fmt is the list of formats which are supported by the codec,
  716. * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
  717. * The first is always the native one.
  718. * @note The callback may be called again immediately if initialization for
  719. * the selected (hardware-accelerated) pixel format failed.
  720. * @warning Behavior is undefined if the callback returns a value not
  721. * in the fmt list of formats.
  722. * @return the chosen format
  723. * - encoding: unused
  724. * - decoding: Set by user, if not set the native format will be chosen.
  725. */
  726. enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  727. /**
  728. * maximum number of B-frames between non-B-frames
  729. * Note: The output will be delayed by max_b_frames+1 relative to the input.
  730. * - encoding: Set by user.
  731. * - decoding: unused
  732. */
  733. int max_b_frames;
  734. /**
  735. * qscale factor between IP and B-frames
  736. * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
  737. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  738. * - encoding: Set by user.
  739. * - decoding: unused
  740. */
  741. float b_quant_factor;
  742. #if FF_API_PRIVATE_OPT
  743. /** @deprecated use encoder private options instead */
  744. attribute_deprecated
  745. int b_frame_strategy;
  746. #endif
  747. /**
  748. * qscale offset between IP and B-frames
  749. * - encoding: Set by user.
  750. * - decoding: unused
  751. */
  752. float b_quant_offset;
  753. /**
  754. * Size of the frame reordering buffer in the decoder.
  755. * For MPEG-2 it is 1 IPB or 0 low delay IP.
  756. * - encoding: Set by libavcodec.
  757. * - decoding: Set by libavcodec.
  758. */
  759. int has_b_frames;
  760. #if FF_API_PRIVATE_OPT
  761. /** @deprecated use encoder private options instead */
  762. attribute_deprecated
  763. int mpeg_quant;
  764. #endif
  765. /**
  766. * qscale factor between P- and I-frames
  767. * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset).
  768. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  769. * - encoding: Set by user.
  770. * - decoding: unused
  771. */
  772. float i_quant_factor;
  773. /**
  774. * qscale offset between P and I-frames
  775. * - encoding: Set by user.
  776. * - decoding: unused
  777. */
  778. float i_quant_offset;
  779. /**
  780. * luminance masking (0-> disabled)
  781. * - encoding: Set by user.
  782. * - decoding: unused
  783. */
  784. float lumi_masking;
  785. /**
  786. * temporary complexity masking (0-> disabled)
  787. * - encoding: Set by user.
  788. * - decoding: unused
  789. */
  790. float temporal_cplx_masking;
  791. /**
  792. * spatial complexity masking (0-> disabled)
  793. * - encoding: Set by user.
  794. * - decoding: unused
  795. */
  796. float spatial_cplx_masking;
  797. /**
  798. * p block masking (0-> disabled)
  799. * - encoding: Set by user.
  800. * - decoding: unused
  801. */
  802. float p_masking;
  803. /**
  804. * darkness masking (0-> disabled)
  805. * - encoding: Set by user.
  806. * - decoding: unused
  807. */
  808. float dark_masking;
  809. /**
  810. * slice count
  811. * - encoding: Set by libavcodec.
  812. * - decoding: Set by user (or 0).
  813. */
  814. int slice_count;
  815. #if FF_API_PRIVATE_OPT
  816. /** @deprecated use encoder private options instead */
  817. attribute_deprecated
  818. int prediction_method;
  819. #define FF_PRED_LEFT 0
  820. #define FF_PRED_PLANE 1
  821. #define FF_PRED_MEDIAN 2
  822. #endif
  823. /**
  824. * slice offsets in the frame in bytes
  825. * - encoding: Set/allocated by libavcodec.
  826. * - decoding: Set/allocated by user (or NULL).
  827. */
  828. int *slice_offset;
  829. /**
  830. * sample aspect ratio (0 if unknown)
  831. * That is the width of a pixel divided by the height of the pixel.
  832. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  833. * - encoding: Set by user.
  834. * - decoding: Set by libavcodec.
  835. */
  836. AVRational sample_aspect_ratio;
  837. /**
  838. * motion estimation comparison function
  839. * - encoding: Set by user.
  840. * - decoding: unused
  841. */
  842. int me_cmp;
  843. /**
  844. * subpixel motion estimation comparison function
  845. * - encoding: Set by user.
  846. * - decoding: unused
  847. */
  848. int me_sub_cmp;
  849. /**
  850. * macroblock comparison function (not supported yet)
  851. * - encoding: Set by user.
  852. * - decoding: unused
  853. */
  854. int mb_cmp;
  855. /**
  856. * interlaced DCT comparison function
  857. * - encoding: Set by user.
  858. * - decoding: unused
  859. */
  860. int ildct_cmp;
  861. #define FF_CMP_SAD 0
  862. #define FF_CMP_SSE 1
  863. #define FF_CMP_SATD 2
  864. #define FF_CMP_DCT 3
  865. #define FF_CMP_PSNR 4
  866. #define FF_CMP_BIT 5
  867. #define FF_CMP_RD 6
  868. #define FF_CMP_ZERO 7
  869. #define FF_CMP_VSAD 8
  870. #define FF_CMP_VSSE 9
  871. #define FF_CMP_NSSE 10
  872. #define FF_CMP_W53 11
  873. #define FF_CMP_W97 12
  874. #define FF_CMP_DCTMAX 13
  875. #define FF_CMP_DCT264 14
  876. #define FF_CMP_MEDIAN_SAD 15
  877. #define FF_CMP_CHROMA 256
  878. /**
  879. * ME diamond size & shape
  880. * - encoding: Set by user.
  881. * - decoding: unused
  882. */
  883. int dia_size;
  884. /**
  885. * amount of previous MV predictors (2a+1 x 2a+1 square)
  886. * - encoding: Set by user.
  887. * - decoding: unused
  888. */
  889. int last_predictor_count;
  890. #if FF_API_PRIVATE_OPT
  891. /** @deprecated use encoder private options instead */
  892. attribute_deprecated
  893. int pre_me;
  894. #endif
  895. /**
  896. * motion estimation prepass comparison function
  897. * - encoding: Set by user.
  898. * - decoding: unused
  899. */
  900. int me_pre_cmp;
  901. /**
  902. * ME prepass diamond size & shape
  903. * - encoding: Set by user.
  904. * - decoding: unused
  905. */
  906. int pre_dia_size;
  907. /**
  908. * subpel ME quality
  909. * - encoding: Set by user.
  910. * - decoding: unused
  911. */
  912. int me_subpel_quality;
  913. /**
  914. * maximum motion estimation search range in subpel units
  915. * If 0 then no limit.
  916. *
  917. * - encoding: Set by user.
  918. * - decoding: unused
  919. */
  920. int me_range;
  921. /**
  922. * slice flags
  923. * - encoding: unused
  924. * - decoding: Set by user.
  925. */
  926. int slice_flags;
  927. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  928. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG-2 field pics)
  929. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  930. /**
  931. * macroblock decision mode
  932. * - encoding: Set by user.
  933. * - decoding: unused
  934. */
  935. int mb_decision;
  936. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  937. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  938. #define FF_MB_DECISION_RD 2 ///< rate distortion
  939. /**
  940. * custom intra quantization matrix
  941. * Must be allocated with the av_malloc() family of functions, and will be freed in
  942. * avcodec_free_context().
  943. * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  944. * - decoding: Set/allocated/freed by libavcodec.
  945. */
  946. uint16_t *intra_matrix;
  947. /**
  948. * custom inter quantization matrix
  949. * Must be allocated with the av_malloc() family of functions, and will be freed in
  950. * avcodec_free_context().
  951. * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  952. * - decoding: Set/allocated/freed by libavcodec.
  953. */
  954. uint16_t *inter_matrix;
  955. #if FF_API_PRIVATE_OPT
  956. /** @deprecated use encoder private options instead */
  957. attribute_deprecated
  958. int scenechange_threshold;
  959. /** @deprecated use encoder private options instead */
  960. attribute_deprecated
  961. int noise_reduction;
  962. #endif
  963. /**
  964. * precision of the intra DC coefficient - 8
  965. * - encoding: Set by user.
  966. * - decoding: Set by libavcodec
  967. */
  968. int intra_dc_precision;
  969. /**
  970. * Number of macroblock rows at the top which are skipped.
  971. * - encoding: unused
  972. * - decoding: Set by user.
  973. */
  974. int skip_top;
  975. /**
  976. * Number of macroblock rows at the bottom which are skipped.
  977. * - encoding: unused
  978. * - decoding: Set by user.
  979. */
  980. int skip_bottom;
  981. /**
  982. * minimum MB Lagrange multiplier
  983. * - encoding: Set by user.
  984. * - decoding: unused
  985. */
  986. int mb_lmin;
  987. /**
  988. * maximum MB Lagrange multiplier
  989. * - encoding: Set by user.
  990. * - decoding: unused
  991. */
  992. int mb_lmax;
  993. #if FF_API_PRIVATE_OPT
  994. /**
  995. * @deprecated use encoder private options instead
  996. */
  997. attribute_deprecated
  998. int me_penalty_compensation;
  999. #endif
  1000. /**
  1001. * - encoding: Set by user.
  1002. * - decoding: unused
  1003. */
  1004. int bidir_refine;
  1005. #if FF_API_PRIVATE_OPT
  1006. /** @deprecated use encoder private options instead */
  1007. attribute_deprecated
  1008. int brd_scale;
  1009. #endif
  1010. /**
  1011. * minimum GOP size
  1012. * - encoding: Set by user.
  1013. * - decoding: unused
  1014. */
  1015. int keyint_min;
  1016. /**
  1017. * number of reference frames
  1018. * - encoding: Set by user.
  1019. * - decoding: Set by lavc.
  1020. */
  1021. int refs;
  1022. #if FF_API_PRIVATE_OPT
  1023. /** @deprecated use encoder private options instead */
  1024. attribute_deprecated
  1025. int chromaoffset;
  1026. #endif
  1027. /**
  1028. * Note: Value depends upon the compare function used for fullpel ME.
  1029. * - encoding: Set by user.
  1030. * - decoding: unused
  1031. */
  1032. int mv0_threshold;
  1033. #if FF_API_PRIVATE_OPT
  1034. /** @deprecated use encoder private options instead */
  1035. attribute_deprecated
  1036. int b_sensitivity;
  1037. #endif
  1038. /**
  1039. * Chromaticity coordinates of the source primaries.
  1040. * - encoding: Set by user
  1041. * - decoding: Set by libavcodec
  1042. */
  1043. enum AVColorPrimaries color_primaries;
  1044. /**
  1045. * Color Transfer Characteristic.
  1046. * - encoding: Set by user
  1047. * - decoding: Set by libavcodec
  1048. */
  1049. enum AVColorTransferCharacteristic color_trc;
  1050. /**
  1051. * YUV colorspace type.
  1052. * - encoding: Set by user
  1053. * - decoding: Set by libavcodec
  1054. */
  1055. enum AVColorSpace colorspace;
  1056. /**
  1057. * MPEG vs JPEG YUV range.
  1058. * - encoding: Set by user
  1059. * - decoding: Set by libavcodec
  1060. */
  1061. enum AVColorRange color_range;
  1062. /**
  1063. * This defines the location of chroma samples.
  1064. * - encoding: Set by user
  1065. * - decoding: Set by libavcodec
  1066. */
  1067. enum AVChromaLocation chroma_sample_location;
  1068. /**
  1069. * Number of slices.
  1070. * Indicates number of picture subdivisions. Used for parallelized
  1071. * decoding.
  1072. * - encoding: Set by user
  1073. * - decoding: unused
  1074. */
  1075. int slices;
  1076. /** Field order
  1077. * - encoding: set by libavcodec
  1078. * - decoding: Set by user.
  1079. */
  1080. enum AVFieldOrder field_order;
  1081. /* audio only */
  1082. int sample_rate; ///< samples per second
  1083. int channels; ///< number of audio channels
  1084. /**
  1085. * audio sample format
  1086. * - encoding: Set by user.
  1087. * - decoding: Set by libavcodec.
  1088. */
  1089. enum AVSampleFormat sample_fmt; ///< sample format
  1090. /* The following data should not be initialized. */
  1091. /**
  1092. * Number of samples per channel in an audio frame.
  1093. *
  1094. * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
  1095. * except the last must contain exactly frame_size samples per channel.
  1096. * May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
  1097. * frame size is not restricted.
  1098. * - decoding: may be set by some decoders to indicate constant frame size
  1099. */
  1100. int frame_size;
  1101. /**
  1102. * Frame counter, set by libavcodec.
  1103. *
  1104. * - decoding: total number of frames returned from the decoder so far.
  1105. * - encoding: total number of frames passed to the encoder so far.
  1106. *
  1107. * @note the counter is not incremented if encoding/decoding resulted in
  1108. * an error.
  1109. */
  1110. int frame_number;
  1111. /**
  1112. * number of bytes per packet if constant and known or 0
  1113. * Used by some WAV based audio codecs.
  1114. */
  1115. int block_align;
  1116. /**
  1117. * Audio cutoff bandwidth (0 means "automatic")
  1118. * - encoding: Set by user.
  1119. * - decoding: unused
  1120. */
  1121. int cutoff;
  1122. /**
  1123. * Audio channel layout.
  1124. * - encoding: set by user.
  1125. * - decoding: set by user, may be overwritten by libavcodec.
  1126. */
  1127. uint64_t channel_layout;
  1128. /**
  1129. * Request decoder to use this channel layout if it can (0 for default)
  1130. * - encoding: unused
  1131. * - decoding: Set by user.
  1132. */
  1133. uint64_t request_channel_layout;
  1134. /**
  1135. * Type of service that the audio stream conveys.
  1136. * - encoding: Set by user.
  1137. * - decoding: Set by libavcodec.
  1138. */
  1139. enum AVAudioServiceType audio_service_type;
  1140. /**
  1141. * desired sample format
  1142. * - encoding: Not used.
  1143. * - decoding: Set by user.
  1144. * Decoder will decode to this format if it can.
  1145. */
  1146. enum AVSampleFormat request_sample_fmt;
  1147. /**
  1148. * This callback is called at the beginning of each frame to get data
  1149. * buffer(s) for it. There may be one contiguous buffer for all the data or
  1150. * there may be a buffer per each data plane or anything in between. What
  1151. * this means is, you may set however many entries in buf[] you feel necessary.
  1152. * Each buffer must be reference-counted using the AVBuffer API (see description
  1153. * of buf[] below).
  1154. *
  1155. * The following fields will be set in the frame before this callback is
  1156. * called:
  1157. * - format
  1158. * - width, height (video only)
  1159. * - sample_rate, channel_layout, nb_samples (audio only)
  1160. * Their values may differ from the corresponding values in
  1161. * AVCodecContext. This callback must use the frame values, not the codec
  1162. * context values, to calculate the required buffer size.
  1163. *
  1164. * This callback must fill the following fields in the frame:
  1165. * - data[]
  1166. * - linesize[]
  1167. * - extended_data:
  1168. * * if the data is planar audio with more than 8 channels, then this
  1169. * callback must allocate and fill extended_data to contain all pointers
  1170. * to all data planes. data[] must hold as many pointers as it can.
  1171. * extended_data must be allocated with av_malloc() and will be freed in
  1172. * av_frame_unref().
  1173. * * otherwise extended_data must point to data
  1174. * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
  1175. * the frame's data and extended_data pointers must be contained in these. That
  1176. * is, one AVBufferRef for each allocated chunk of memory, not necessarily one
  1177. * AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
  1178. * and av_buffer_ref().
  1179. * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
  1180. * this callback and filled with the extra buffers if there are more
  1181. * buffers than buf[] can hold. extended_buf will be freed in
  1182. * av_frame_unref().
  1183. *
  1184. * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call
  1185. * avcodec_default_get_buffer2() instead of providing buffers allocated by
  1186. * some other means.
  1187. *
  1188. * Each data plane must be aligned to the maximum required by the target
  1189. * CPU.
  1190. *
  1191. * @see avcodec_default_get_buffer2()
  1192. *
  1193. * Video:
  1194. *
  1195. * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
  1196. * (read and/or written to if it is writable) later by libavcodec.
  1197. *
  1198. * avcodec_align_dimensions2() should be used to find the required width and
  1199. * height, as they normally need to be rounded up to the next multiple of 16.
  1200. *
  1201. * Some decoders do not support linesizes changing between frames.
  1202. *
  1203. * If frame multithreading is used and thread_safe_callbacks is set,
  1204. * this callback may be called from a different thread, but not from more
  1205. * than one at once. Does not need to be reentrant.
  1206. *
  1207. * @see avcodec_align_dimensions2()
  1208. *
  1209. * Audio:
  1210. *
  1211. * Decoders request a buffer of a particular size by setting
  1212. * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
  1213. * however, utilize only part of the buffer by setting AVFrame.nb_samples
  1214. * to a smaller value in the output frame.
  1215. *
  1216. * As a convenience, av_samples_get_buffer_size() and
  1217. * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
  1218. * functions to find the required data size and to fill data pointers and
  1219. * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
  1220. * since all planes must be the same size.
  1221. *
  1222. * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
  1223. *
  1224. * - encoding: unused
  1225. * - decoding: Set by libavcodec, user can override.
  1226. */
  1227. int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
  1228. /**
  1229. * If non-zero, the decoded audio and video frames returned from
  1230. * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted
  1231. * and are valid indefinitely. The caller must free them with
  1232. * av_frame_unref() when they are not needed anymore.
  1233. * Otherwise, the decoded frames must not be freed by the caller and are
  1234. * only valid until the next decode call.
  1235. *
  1236. * This is always automatically enabled if avcodec_receive_frame() is used.
  1237. *
  1238. * - encoding: unused
  1239. * - decoding: set by the caller before avcodec_open2().
  1240. */
  1241. attribute_deprecated
  1242. int refcounted_frames;
  1243. /* - encoding parameters */
  1244. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  1245. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  1246. /**
  1247. * minimum quantizer
  1248. * - encoding: Set by user.
  1249. * - decoding: unused
  1250. */
  1251. int qmin;
  1252. /**
  1253. * maximum quantizer
  1254. * - encoding: Set by user.
  1255. * - decoding: unused
  1256. */
  1257. int qmax;
  1258. /**
  1259. * maximum quantizer difference between frames
  1260. * - encoding: Set by user.
  1261. * - decoding: unused
  1262. */
  1263. int max_qdiff;
  1264. /**
  1265. * decoder bitstream buffer size
  1266. * - encoding: Set by user.
  1267. * - decoding: unused
  1268. */
  1269. int rc_buffer_size;
  1270. /**
  1271. * ratecontrol override, see RcOverride
  1272. * - encoding: Allocated/set/freed by user.
  1273. * - decoding: unused
  1274. */
  1275. int rc_override_count;
  1276. RcOverride *rc_override;
  1277. /**
  1278. * maximum bitrate
  1279. * - encoding: Set by user.
  1280. * - decoding: Set by user, may be overwritten by libavcodec.
  1281. */
  1282. int64_t rc_max_rate;
  1283. /**
  1284. * minimum bitrate
  1285. * - encoding: Set by user.
  1286. * - decoding: unused
  1287. */
  1288. int64_t rc_min_rate;
  1289. /**
  1290. * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
  1291. * - encoding: Set by user.
  1292. * - decoding: unused.
  1293. */
  1294. float rc_max_available_vbv_use;
  1295. /**
  1296. * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
  1297. * - encoding: Set by user.
  1298. * - decoding: unused.
  1299. */
  1300. float rc_min_vbv_overflow_use;
  1301. /**
  1302. * Number of bits which should be loaded into the rc buffer before decoding starts.
  1303. * - encoding: Set by user.
  1304. * - decoding: unused
  1305. */
  1306. int rc_initial_buffer_occupancy;
  1307. #if FF_API_CODER_TYPE
  1308. #define FF_CODER_TYPE_VLC 0
  1309. #define FF_CODER_TYPE_AC 1
  1310. #define FF_CODER_TYPE_RAW 2
  1311. #define FF_CODER_TYPE_RLE 3
  1312. /**
  1313. * @deprecated use encoder private options instead
  1314. */
  1315. attribute_deprecated
  1316. int coder_type;
  1317. #endif /* FF_API_CODER_TYPE */
  1318. #if FF_API_PRIVATE_OPT
  1319. /** @deprecated use encoder private options instead */
  1320. attribute_deprecated
  1321. int context_model;
  1322. #endif
  1323. #if FF_API_PRIVATE_OPT
  1324. /** @deprecated use encoder private options instead */
  1325. attribute_deprecated
  1326. int frame_skip_threshold;
  1327. /** @deprecated use encoder private options instead */
  1328. attribute_deprecated
  1329. int frame_skip_factor;
  1330. /** @deprecated use encoder private options instead */
  1331. attribute_deprecated
  1332. int frame_skip_exp;
  1333. /** @deprecated use encoder private options instead */
  1334. attribute_deprecated
  1335. int frame_skip_cmp;
  1336. #endif /* FF_API_PRIVATE_OPT */
  1337. /**
  1338. * trellis RD quantization
  1339. * - encoding: Set by user.
  1340. * - decoding: unused
  1341. */
  1342. int trellis;
  1343. #if FF_API_PRIVATE_OPT
  1344. /** @deprecated use encoder private options instead */
  1345. attribute_deprecated
  1346. int min_prediction_order;
  1347. /** @deprecated use encoder private options instead */
  1348. attribute_deprecated
  1349. int max_prediction_order;
  1350. /** @deprecated use encoder private options instead */
  1351. attribute_deprecated
  1352. int64_t timecode_frame_start;
  1353. #endif
  1354. #if FF_API_RTP_CALLBACK
  1355. /**
  1356. * @deprecated unused
  1357. */
  1358. /* The RTP callback: This function is called */
  1359. /* every time the encoder has a packet to send. */
  1360. /* It depends on the encoder if the data starts */
  1361. /* with a Start Code (it should). H.263 does. */
  1362. /* mb_nb contains the number of macroblocks */
  1363. /* encoded in the RTP payload. */
  1364. attribute_deprecated
  1365. void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
  1366. #endif
  1367. #if FF_API_PRIVATE_OPT
  1368. /** @deprecated use encoder private options instead */
  1369. attribute_deprecated
  1370. int rtp_payload_size; /* The size of the RTP payload: the coder will */
  1371. /* do its best to deliver a chunk with size */
  1372. /* below rtp_payload_size, the chunk will start */
  1373. /* with a start code on some codecs like H.263. */
  1374. /* This doesn't take account of any particular */
  1375. /* headers inside the transmitted RTP payload. */
  1376. #endif
  1377. #if FF_API_STAT_BITS
  1378. /* statistics, used for 2-pass encoding */
  1379. attribute_deprecated
  1380. int mv_bits;
  1381. attribute_deprecated
  1382. int header_bits;
  1383. attribute_deprecated
  1384. int i_tex_bits;
  1385. attribute_deprecated
  1386. int p_tex_bits;
  1387. attribute_deprecated
  1388. int i_count;
  1389. attribute_deprecated
  1390. int p_count;
  1391. attribute_deprecated
  1392. int skip_count;
  1393. attribute_deprecated
  1394. int misc_bits;
  1395. /** @deprecated this field is unused */
  1396. attribute_deprecated
  1397. int frame_bits;
  1398. #endif
  1399. /**
  1400. * pass1 encoding statistics output buffer
  1401. * - encoding: Set by libavcodec.
  1402. * - decoding: unused
  1403. */
  1404. char *stats_out;
  1405. /**
  1406. * pass2 encoding statistics input buffer
  1407. * Concatenated stuff from stats_out of pass1 should be placed here.
  1408. * - encoding: Allocated/set/freed by user.
  1409. * - decoding: unused
  1410. */
  1411. char *stats_in;
  1412. /**
  1413. * Work around bugs in encoders which sometimes cannot be detected automatically.
  1414. * - encoding: Set by user
  1415. * - decoding: Set by user
  1416. */
  1417. int workaround_bugs;
  1418. #define FF_BUG_AUTODETECT 1 ///< autodetection
  1419. #define FF_BUG_XVID_ILACE 4
  1420. #define FF_BUG_UMP4 8
  1421. #define FF_BUG_NO_PADDING 16
  1422. #define FF_BUG_AMV 32
  1423. #define FF_BUG_QPEL_CHROMA 64
  1424. #define FF_BUG_STD_QPEL 128
  1425. #define FF_BUG_QPEL_CHROMA2 256
  1426. #define FF_BUG_DIRECT_BLOCKSIZE 512
  1427. #define FF_BUG_EDGE 1024
  1428. #define FF_BUG_HPEL_CHROMA 2048
  1429. #define FF_BUG_DC_CLIP 4096
  1430. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  1431. #define FF_BUG_TRUNCATED 16384
  1432. #define FF_BUG_IEDGE 32768
  1433. /**
  1434. * strictly follow the standard (MPEG-4, ...).
  1435. * - encoding: Set by user.
  1436. * - decoding: Set by user.
  1437. * Setting this to STRICT or higher means the encoder and decoder will
  1438. * generally do stupid things, whereas setting it to unofficial or lower
  1439. * will mean the encoder might produce output that is not supported by all
  1440. * spec-compliant decoders. Decoders don't differentiate between normal,
  1441. * unofficial and experimental (that is, they always try to decode things
  1442. * when they can) unless they are explicitly asked to behave stupidly
  1443. * (=strictly conform to the specs)
  1444. */
  1445. int strict_std_compliance;
  1446. #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
  1447. #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
  1448. #define FF_COMPLIANCE_NORMAL 0
  1449. #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
  1450. #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
  1451. /**
  1452. * error concealment flags
  1453. * - encoding: unused
  1454. * - decoding: Set by user.
  1455. */
  1456. int error_concealment;
  1457. #define FF_EC_GUESS_MVS 1
  1458. #define FF_EC_DEBLOCK 2
  1459. #define FF_EC_FAVOR_INTER 256
  1460. /**
  1461. * debug
  1462. * - encoding: Set by user.
  1463. * - decoding: Set by user.
  1464. */
  1465. int debug;
  1466. #define FF_DEBUG_PICT_INFO 1
  1467. #define FF_DEBUG_RC 2
  1468. #define FF_DEBUG_BITSTREAM 4
  1469. #define FF_DEBUG_MB_TYPE 8
  1470. #define FF_DEBUG_QP 16
  1471. #if FF_API_DEBUG_MV
  1472. /**
  1473. * @deprecated this option does nothing
  1474. */
  1475. #define FF_DEBUG_MV 32
  1476. #endif
  1477. #define FF_DEBUG_DCT_COEFF 0x00000040
  1478. #define FF_DEBUG_SKIP 0x00000080
  1479. #define FF_DEBUG_STARTCODE 0x00000100
  1480. #define FF_DEBUG_ER 0x00000400
  1481. #define FF_DEBUG_MMCO 0x00000800
  1482. #define FF_DEBUG_BUGS 0x00001000
  1483. #if FF_API_DEBUG_MV
  1484. #define FF_DEBUG_VIS_QP 0x00002000
  1485. #define FF_DEBUG_VIS_MB_TYPE 0x00004000
  1486. #endif
  1487. #define FF_DEBUG_BUFFERS 0x00008000
  1488. #define FF_DEBUG_THREADS 0x00010000
  1489. #define FF_DEBUG_GREEN_MD 0x00800000
  1490. #define FF_DEBUG_NOMC 0x01000000
  1491. #if FF_API_DEBUG_MV
  1492. /**
  1493. * debug
  1494. * - encoding: Set by user.
  1495. * - decoding: Set by user.
  1496. */
  1497. int debug_mv;
  1498. #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 // visualize forward predicted MVs of P-frames
  1499. #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 // visualize forward predicted MVs of B-frames
  1500. #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 // visualize backward predicted MVs of B-frames
  1501. #endif
  1502. /**
  1503. * Error recognition; may misdetect some more or less valid parts as errors.
  1504. * - encoding: unused
  1505. * - decoding: Set by user.
  1506. */
  1507. int err_recognition;
  1508. /**
  1509. * Verify checksums embedded in the bitstream (could be of either encoded or
  1510. * decoded data, depending on the codec) and print an error message on mismatch.
  1511. * If AV_EF_EXPLODE is also set, a mismatching checksum will result in the
  1512. * decoder returning an error.
  1513. */
  1514. #define AV_EF_CRCCHECK (1<<0)
  1515. #define AV_EF_BITSTREAM (1<<1) ///< detect bitstream specification deviations
  1516. #define AV_EF_BUFFER (1<<2) ///< detect improper bitstream length
  1517. #define AV_EF_EXPLODE (1<<3) ///< abort decoding on minor error detection
  1518. #define AV_EF_IGNORE_ERR (1<<15) ///< ignore errors and continue
  1519. #define AV_EF_CAREFUL (1<<16) ///< consider things that violate the spec, are fast to calculate and have not been seen in the wild as errors
  1520. #define AV_EF_COMPLIANT (1<<17) ///< consider all spec non compliances as errors
  1521. #define AV_EF_AGGRESSIVE (1<<18) ///< consider things that a sane encoder should not do as an error
  1522. /**
  1523. * opaque 64-bit number (generally a PTS) that will be reordered and
  1524. * output in AVFrame.reordered_opaque
  1525. * - encoding: Set by libavcodec to the reordered_opaque of the input
  1526. * frame corresponding to the last returned packet. Only
  1527. * supported by encoders with the
  1528. * AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability.
  1529. * - decoding: Set by user.
  1530. */
  1531. int64_t reordered_opaque;
  1532. /**
  1533. * Hardware accelerator in use
  1534. * - encoding: unused.
  1535. * - decoding: Set by libavcodec
  1536. */
  1537. const struct AVHWAccel *hwaccel;
  1538. /**
  1539. * Hardware accelerator context.
  1540. * For some hardware accelerators, a global context needs to be
  1541. * provided by the user. In that case, this holds display-dependent
  1542. * data FFmpeg cannot instantiate itself. Please refer to the
  1543. * FFmpeg HW accelerator documentation to know how to fill this
  1544. * is. e.g. for VA API, this is a struct vaapi_context.
  1545. * - encoding: unused
  1546. * - decoding: Set by user
  1547. */
  1548. void *hwaccel_context;
  1549. /**
  1550. * error
  1551. * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
  1552. * - decoding: unused
  1553. */
  1554. uint64_t error[AV_NUM_DATA_POINTERS];
  1555. /**
  1556. * DCT algorithm, see FF_DCT_* below
  1557. * - encoding: Set by user.
  1558. * - decoding: unused
  1559. */
  1560. int dct_algo;
  1561. #define FF_DCT_AUTO 0
  1562. #define FF_DCT_FASTINT 1
  1563. #define FF_DCT_INT 2
  1564. #define FF_DCT_MMX 3
  1565. #define FF_DCT_ALTIVEC 5
  1566. #define FF_DCT_FAAN 6
  1567. /**
  1568. * IDCT algorithm, see FF_IDCT_* below.
  1569. * - encoding: Set by user.
  1570. * - decoding: Set by user.
  1571. */
  1572. int idct_algo;
  1573. #define FF_IDCT_AUTO 0
  1574. #define FF_IDCT_INT 1
  1575. #define FF_IDCT_SIMPLE 2
  1576. #define FF_IDCT_SIMPLEMMX 3
  1577. #define FF_IDCT_ARM 7
  1578. #define FF_IDCT_ALTIVEC 8
  1579. #define FF_IDCT_SIMPLEARM 10
  1580. #define FF_IDCT_XVID 14
  1581. #define FF_IDCT_SIMPLEARMV5TE 16
  1582. #define FF_IDCT_SIMPLEARMV6 17
  1583. #define FF_IDCT_FAAN 20
  1584. #define FF_IDCT_SIMPLENEON 22
  1585. #define FF_IDCT_NONE 24 /* Used by XvMC to extract IDCT coefficients with FF_IDCT_PERM_NONE */
  1586. #define FF_IDCT_SIMPLEAUTO 128
  1587. /**
  1588. * bits per sample/pixel from the demuxer (needed for huffyuv).
  1589. * - encoding: Set by libavcodec.
  1590. * - decoding: Set by user.
  1591. */
  1592. int bits_per_coded_sample;
  1593. /**
  1594. * Bits per sample/pixel of internal libavcodec pixel/sample format.
  1595. * - encoding: set by user.
  1596. * - decoding: set by libavcodec.
  1597. */
  1598. int bits_per_raw_sample;
  1599. #if FF_API_LOWRES
  1600. /**
  1601. * low resolution decoding, 1-> 1/2 size, 2->1/4 size
  1602. * - encoding: unused
  1603. * - decoding: Set by user.
  1604. */
  1605. int lowres;
  1606. #endif
  1607. #if FF_API_CODED_FRAME
  1608. /**
  1609. * the picture in the bitstream
  1610. * - encoding: Set by libavcodec.
  1611. * - decoding: unused
  1612. *
  1613. * @deprecated use the quality factor packet side data instead
  1614. */
  1615. attribute_deprecated AVFrame *coded_frame;
  1616. #endif
  1617. /**
  1618. * thread count
  1619. * is used to decide how many independent tasks should be passed to execute()
  1620. * - encoding: Set by user.
  1621. * - decoding: Set by user.
  1622. */
  1623. int thread_count;
  1624. /**
  1625. * Which multithreading methods to use.
  1626. * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
  1627. * so clients which cannot provide future frames should not use it.
  1628. *
  1629. * - encoding: Set by user, otherwise the default is used.
  1630. * - decoding: Set by user, otherwise the default is used.
  1631. */
  1632. int thread_type;
  1633. #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
  1634. #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
  1635. /**
  1636. * Which multithreading methods are in use by the codec.
  1637. * - encoding: Set by libavcodec.
  1638. * - decoding: Set by libavcodec.
  1639. */
  1640. int active_thread_type;
  1641. /**
  1642. * Set by the client if its custom get_buffer() callback can be called
  1643. * synchronously from another thread, which allows faster multithreaded decoding.
  1644. * draw_horiz_band() will be called from other threads regardless of this setting.
  1645. * Ignored if the default get_buffer() is used.
  1646. * - encoding: Set by user.
  1647. * - decoding: Set by user.
  1648. */
  1649. int thread_safe_callbacks;
  1650. /**
  1651. * The codec may call this to execute several independent things.
  1652. * It will return only after finishing all tasks.
  1653. * The user may replace this with some multithreaded implementation,
  1654. * the default implementation will execute the parts serially.
  1655. * @param count the number of things to execute
  1656. * - encoding: Set by libavcodec, user can override.
  1657. * - decoding: Set by libavcodec, user can override.
  1658. */
  1659. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
  1660. /**
  1661. * The codec may call this to execute several independent things.
  1662. * It will return only after finishing all tasks.
  1663. * The user may replace this with some multithreaded implementation,
  1664. * the default implementation will execute the parts serially.
  1665. * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
  1666. * @param c context passed also to func
  1667. * @param count the number of things to execute
  1668. * @param arg2 argument passed unchanged to func
  1669. * @param ret return values of executed functions, must have space for "count" values. May be NULL.
  1670. * @param func function that will be called count times, with jobnr from 0 to count-1.
  1671. * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
  1672. * two instances of func executing at the same time will have the same threadnr.
  1673. * @return always 0 currently, but code should handle a future improvement where when any call to func
  1674. * returns < 0 no further calls to func may be done and < 0 is returned.
  1675. * - encoding: Set by libavcodec, user can override.
  1676. * - decoding: Set by libavcodec, user can override.
  1677. */
  1678. int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
  1679. /**
  1680. * noise vs. sse weight for the nsse comparison function
  1681. * - encoding: Set by user.
  1682. * - decoding: unused
  1683. */
  1684. int nsse_weight;
  1685. /**
  1686. * profile
  1687. * - encoding: Set by user.
  1688. * - decoding: Set by libavcodec.
  1689. */
  1690. int profile;
  1691. #define FF_PROFILE_UNKNOWN -99
  1692. #define FF_PROFILE_RESERVED -100
  1693. #define FF_PROFILE_AAC_MAIN 0
  1694. #define FF_PROFILE_AAC_LOW 1
  1695. #define FF_PROFILE_AAC_SSR 2
  1696. #define FF_PROFILE_AAC_LTP 3
  1697. #define FF_PROFILE_AAC_HE 4
  1698. #define FF_PROFILE_AAC_HE_V2 28
  1699. #define FF_PROFILE_AAC_LD 22
  1700. #define FF_PROFILE_AAC_ELD 38
  1701. #define FF_PROFILE_MPEG2_AAC_LOW 128
  1702. #define FF_PROFILE_MPEG2_AAC_HE 131
  1703. #define FF_PROFILE_DNXHD 0
  1704. #define FF_PROFILE_DNXHR_LB 1
  1705. #define FF_PROFILE_DNXHR_SQ 2
  1706. #define FF_PROFILE_DNXHR_HQ 3
  1707. #define FF_PROFILE_DNXHR_HQX 4
  1708. #define FF_PROFILE_DNXHR_444 5
  1709. #define FF_PROFILE_DTS 20
  1710. #define FF_PROFILE_DTS_ES 30
  1711. #define FF_PROFILE_DTS_96_24 40
  1712. #define FF_PROFILE_DTS_HD_HRA 50
  1713. #define FF_PROFILE_DTS_HD_MA 60
  1714. #define FF_PROFILE_DTS_EXPRESS 70
  1715. #define FF_PROFILE_MPEG2_422 0
  1716. #define FF_PROFILE_MPEG2_HIGH 1
  1717. #define FF_PROFILE_MPEG2_SS 2
  1718. #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
  1719. #define FF_PROFILE_MPEG2_MAIN 4
  1720. #define FF_PROFILE_MPEG2_SIMPLE 5
  1721. #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
  1722. #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
  1723. #define FF_PROFILE_H264_BASELINE 66
  1724. #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
  1725. #define FF_PROFILE_H264_MAIN 77
  1726. #define FF_PROFILE_H264_EXTENDED 88
  1727. #define FF_PROFILE_H264_HIGH 100
  1728. #define FF_PROFILE_H264_HIGH_10 110
  1729. #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
  1730. #define FF_PROFILE_H264_MULTIVIEW_HIGH 118
  1731. #define FF_PROFILE_H264_HIGH_422 122
  1732. #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
  1733. #define FF_PROFILE_H264_STEREO_HIGH 128
  1734. #define FF_PROFILE_H264_HIGH_444 144
  1735. #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
  1736. #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
  1737. #define FF_PROFILE_H264_CAVLC_444 44
  1738. #define FF_PROFILE_VC1_SIMPLE 0
  1739. #define FF_PROFILE_VC1_MAIN 1
  1740. #define FF_PROFILE_VC1_COMPLEX 2
  1741. #define FF_PROFILE_VC1_ADVANCED 3
  1742. #define FF_PROFILE_MPEG4_SIMPLE 0
  1743. #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
  1744. #define FF_PROFILE_MPEG4_CORE 2
  1745. #define FF_PROFILE_MPEG4_MAIN 3
  1746. #define FF_PROFILE_MPEG4_N_BIT 4
  1747. #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
  1748. #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
  1749. #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
  1750. #define FF_PROFILE_MPEG4_HYBRID 8
  1751. #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
  1752. #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
  1753. #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
  1754. #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
  1755. #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
  1756. #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
  1757. #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
  1758. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 1
  1759. #define FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 2
  1760. #define FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION 32768
  1761. #define FF_PROFILE_JPEG2000_DCINEMA_2K 3
  1762. #define FF_PROFILE_JPEG2000_DCINEMA_4K 4
  1763. #define FF_PROFILE_VP9_0 0
  1764. #define FF_PROFILE_VP9_1 1
  1765. #define FF_PROFILE_VP9_2 2
  1766. #define FF_PROFILE_VP9_3 3
  1767. #define FF_PROFILE_HEVC_MAIN 1
  1768. #define FF_PROFILE_HEVC_MAIN_10 2
  1769. #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3
  1770. #define FF_PROFILE_HEVC_REXT 4
  1771. #define FF_PROFILE_AV1_MAIN 0
  1772. #define FF_PROFILE_AV1_HIGH 1
  1773. #define FF_PROFILE_AV1_PROFESSIONAL 2
  1774. #define FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT 0xc0
  1775. #define FF_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT 0xc1
  1776. #define FF_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT 0xc2
  1777. #define FF_PROFILE_MJPEG_HUFFMAN_LOSSLESS 0xc3
  1778. #define FF_PROFILE_MJPEG_JPEG_LS 0xf7
  1779. #define FF_PROFILE_SBC_MSBC 1
  1780. #define FF_PROFILE_PRORES_PROXY 0
  1781. #define FF_PROFILE_PRORES_LT 1
  1782. #define FF_PROFILE_PRORES_STANDARD 2
  1783. #define FF_PROFILE_PRORES_HQ 3
  1784. #define FF_PROFILE_PRORES_4444 4
  1785. #define FF_PROFILE_PRORES_XQ 5
  1786. #define FF_PROFILE_ARIB_PROFILE_A 0
  1787. #define FF_PROFILE_ARIB_PROFILE_C 1
  1788. #define FF_PROFILE_KLVA_SYNC 0
  1789. #define FF_PROFILE_KLVA_ASYNC 1
  1790. /**
  1791. * level
  1792. * - encoding: Set by user.
  1793. * - decoding: Set by libavcodec.
  1794. */
  1795. int level;
  1796. #define FF_LEVEL_UNKNOWN -99
  1797. /**
  1798. * Skip loop filtering for selected frames.
  1799. * - encoding: unused
  1800. * - decoding: Set by user.
  1801. */
  1802. enum AVDiscard skip_loop_filter;
  1803. /**
  1804. * Skip IDCT/dequantization for selected frames.
  1805. * - encoding: unused
  1806. * - decoding: Set by user.
  1807. */
  1808. enum AVDiscard skip_idct;
  1809. /**
  1810. * Skip decoding for selected frames.
  1811. * - encoding: unused
  1812. * - decoding: Set by user.
  1813. */
  1814. enum AVDiscard skip_frame;
  1815. /**
  1816. * Header containing style information for text subtitles.
  1817. * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
  1818. * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  1819. * the Format line following. It shouldn't include any Dialogue line.
  1820. * - encoding: Set/allocated/freed by user (before avcodec_open2())
  1821. * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
  1822. */
  1823. uint8_t *subtitle_header;
  1824. int subtitle_header_size;
  1825. #if FF_API_VBV_DELAY
  1826. /**
  1827. * VBV delay coded in the last frame (in periods of a 27 MHz clock).
  1828. * Used for compliant TS muxing.
  1829. * - encoding: Set by libavcodec.
  1830. * - decoding: unused.
  1831. * @deprecated this value is now exported as a part of
  1832. * AV_PKT_DATA_CPB_PROPERTIES packet side data
  1833. */
  1834. attribute_deprecated
  1835. uint64_t vbv_delay;
  1836. #endif
  1837. #if FF_API_SIDEDATA_ONLY_PKT
  1838. /**
  1839. * Encoding only and set by default. Allow encoders to output packets
  1840. * that do not contain any encoded data, only side data.
  1841. *
  1842. * Some encoders need to output such packets, e.g. to update some stream
  1843. * parameters at the end of encoding.
  1844. *
  1845. * @deprecated this field disables the default behaviour and
  1846. * it is kept only for compatibility.
  1847. */
  1848. attribute_deprecated
  1849. int side_data_only_packets;
  1850. #endif
  1851. /**
  1852. * Audio only. The number of "priming" samples (padding) inserted by the
  1853. * encoder at the beginning of the audio. I.e. this number of leading
  1854. * decoded samples must be discarded by the caller to get the original audio
  1855. * without leading padding.
  1856. *
  1857. * - decoding: unused
  1858. * - encoding: Set by libavcodec. The timestamps on the output packets are
  1859. * adjusted by the encoder so that they always refer to the
  1860. * first sample of the data actually contained in the packet,
  1861. * including any added padding. E.g. if the timebase is
  1862. * 1/samplerate and the timestamp of the first input sample is
  1863. * 0, the timestamp of the first output packet will be
  1864. * -initial_padding.
  1865. */
  1866. int initial_padding;
  1867. /**
  1868. * - decoding: For codecs that store a framerate value in the compressed
  1869. * bitstream, the decoder may export it here. { 0, 1} when
  1870. * unknown.
  1871. * - encoding: May be used to signal the framerate of CFR content to an
  1872. * encoder.
  1873. */
  1874. AVRational framerate;
  1875. /**
  1876. * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
  1877. * - encoding: unused.
  1878. * - decoding: Set by libavcodec before calling get_format()
  1879. */
  1880. enum AVPixelFormat sw_pix_fmt;
  1881. /**
  1882. * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
  1883. * - encoding unused.
  1884. * - decoding set by user.
  1885. */
  1886. AVRational pkt_timebase;
  1887. /**
  1888. * AVCodecDescriptor
  1889. * - encoding: unused.
  1890. * - decoding: set by libavcodec.
  1891. */
  1892. const AVCodecDescriptor *codec_descriptor;
  1893. #if !FF_API_LOWRES
  1894. /**
  1895. * low resolution decoding, 1-> 1/2 size, 2->1/4 size
  1896. * - encoding: unused
  1897. * - decoding: Set by user.
  1898. */
  1899. int lowres;
  1900. #endif
  1901. /**
  1902. * Current statistics for PTS correction.
  1903. * - decoding: maintained and used by libavcodec, not intended to be used by user apps
  1904. * - encoding: unused
  1905. */
  1906. int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
  1907. int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
  1908. int64_t pts_correction_last_pts; /// PTS of the last frame
  1909. int64_t pts_correction_last_dts; /// DTS of the last frame
  1910. /**
  1911. * Character encoding of the input subtitles file.
  1912. * - decoding: set by user
  1913. * - encoding: unused
  1914. */
  1915. char *sub_charenc;
  1916. /**
  1917. * Subtitles character encoding mode. Formats or codecs might be adjusting
  1918. * this setting (if they are doing the conversion themselves for instance).
  1919. * - decoding: set by libavcodec
  1920. * - encoding: unused
  1921. */
  1922. int sub_charenc_mode;
  1923. #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)
  1924. #define FF_SUB_CHARENC_MODE_AUTOMATIC 0 ///< libavcodec will select the mode itself
  1925. #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
  1926. #define FF_SUB_CHARENC_MODE_IGNORE 2 ///< neither convert the subtitles, nor check them for valid UTF-8
  1927. /**
  1928. * Skip processing alpha if supported by codec.
  1929. * Note that if the format uses pre-multiplied alpha (common with VP6,
  1930. * and recommended due to better video quality/compression)
  1931. * the image will look as if alpha-blended onto a black background.
  1932. * However for formats that do not use pre-multiplied alpha
  1933. * there might be serious artefacts (though e.g. libswscale currently
  1934. * assumes pre-multiplied alpha anyway).
  1935. *
  1936. * - decoding: set by user
  1937. * - encoding: unused
  1938. */
  1939. int skip_alpha;
  1940. /**
  1941. * Number of samples to skip after a discontinuity
  1942. * - decoding: unused
  1943. * - encoding: set by libavcodec
  1944. */
  1945. int seek_preroll;
  1946. #if !FF_API_DEBUG_MV
  1947. /**
  1948. * debug motion vectors
  1949. * - encoding: Set by user.
  1950. * - decoding: Set by user.
  1951. */
  1952. int debug_mv;
  1953. #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
  1954. #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
  1955. #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
  1956. #endif
  1957. /**
  1958. * custom intra quantization matrix
  1959. * - encoding: Set by user, can be NULL.
  1960. * - decoding: unused.
  1961. */
  1962. uint16_t *chroma_intra_matrix;
  1963. /**
  1964. * dump format separator.
  1965. * can be ", " or "\n " or anything else
  1966. * - encoding: Set by user.
  1967. * - decoding: Set by user.
  1968. */
  1969. uint8_t *dump_separator;
  1970. /**
  1971. * ',' separated list of allowed decoders.
  1972. * If NULL then all are allowed
  1973. * - encoding: unused
  1974. * - decoding: set by user
  1975. */
  1976. char *codec_whitelist;
  1977. /**
  1978. * Properties of the stream that gets decoded
  1979. * - encoding: unused
  1980. * - decoding: set by libavcodec
  1981. */
  1982. unsigned properties;
  1983. #define FF_CODEC_PROPERTY_LOSSLESS 0x00000001
  1984. #define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002
  1985. /**
  1986. * Additional data associated with the entire coded stream.
  1987. *
  1988. * - decoding: unused
  1989. * - encoding: may be set by libavcodec after avcodec_open2().
  1990. */
  1991. AVPacketSideData *coded_side_data;
  1992. int nb_coded_side_data;
  1993. /**
  1994. * A reference to the AVHWFramesContext describing the input (for encoding)
  1995. * or output (decoding) frames. The reference is set by the caller and
  1996. * afterwards owned (and freed) by libavcodec - it should never be read by
  1997. * the caller after being set.
  1998. *
  1999. * - decoding: This field should be set by the caller from the get_format()
  2000. * callback. The previous reference (if any) will always be
  2001. * unreffed by libavcodec before the get_format() call.
  2002. *
  2003. * If the default get_buffer2() is used with a hwaccel pixel
  2004. * format, then this AVHWFramesContext will be used for
  2005. * allocating the frame buffers.
  2006. *
  2007. * - encoding: For hardware encoders configured to use a hwaccel pixel
  2008. * format, this field should be set by the caller to a reference
  2009. * to the AVHWFramesContext describing input frames.
  2010. * AVHWFramesContext.format must be equal to
  2011. * AVCodecContext.pix_fmt.
  2012. *
  2013. * This field should be set before avcodec_open2() is called.
  2014. */
  2015. AVBufferRef *hw_frames_ctx;
  2016. /**
  2017. * Control the form of AVSubtitle.rects[N]->ass
  2018. * - decoding: set by user
  2019. * - encoding: unused
  2020. */
  2021. int sub_text_format;
  2022. #define FF_SUB_TEXT_FMT_ASS 0
  2023. #if FF_API_ASS_TIMING
  2024. #define FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS 1
  2025. #endif
  2026. /**
  2027. * Audio only. The amount of padding (in samples) appended by the encoder to
  2028. * the end of the audio. I.e. this number of decoded samples must be
  2029. * discarded by the caller from the end of the stream to get the original
  2030. * audio without any trailing padding.
  2031. *
  2032. * - decoding: unused
  2033. * - encoding: unused
  2034. */
  2035. int trailing_padding;
  2036. /**
  2037. * The number of pixels per image to maximally accept.
  2038. *
  2039. * - decoding: set by user
  2040. * - encoding: set by user
  2041. */
  2042. int64_t max_pixels;
  2043. /**
  2044. * A reference to the AVHWDeviceContext describing the device which will
  2045. * be used by a hardware encoder/decoder. The reference is set by the
  2046. * caller and afterwards owned (and freed) by libavcodec.
  2047. *
  2048. * This should be used if either the codec device does not require
  2049. * hardware frames or any that are used are to be allocated internally by
  2050. * libavcodec. If the user wishes to supply any of the frames used as
  2051. * encoder input or decoder output then hw_frames_ctx should be used
  2052. * instead. When hw_frames_ctx is set in get_format() for a decoder, this
  2053. * field will be ignored while decoding the associated stream segment, but
  2054. * may again be used on a following one after another get_format() call.
  2055. *
  2056. * For both encoders and decoders this field should be set before
  2057. * avcodec_open2() is called and must not be written to thereafter.
  2058. *
  2059. * Note that some decoders may require this field to be set initially in
  2060. * order to support hw_frames_ctx at all - in that case, all frames
  2061. * contexts used must be created on the same device.
  2062. */
  2063. AVBufferRef *hw_device_ctx;
  2064. /**
  2065. * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated
  2066. * decoding (if active).
  2067. * - encoding: unused
  2068. * - decoding: Set by user (either before avcodec_open2(), or in the
  2069. * AVCodecContext.get_format callback)
  2070. */
  2071. int hwaccel_flags;
  2072. /**
  2073. * Video decoding only. Certain video codecs support cropping, meaning that
  2074. * only a sub-rectangle of the decoded frame is intended for display. This
  2075. * option controls how cropping is handled by libavcodec.
  2076. *
  2077. * When set to 1 (the default), libavcodec will apply cropping internally.
  2078. * I.e. it will modify the output frame width/height fields and offset the
  2079. * data pointers (only by as much as possible while preserving alignment, or
  2080. * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
  2081. * the frames output by the decoder refer only to the cropped area. The
  2082. * crop_* fields of the output frames will be zero.
  2083. *
  2084. * When set to 0, the width/height fields of the output frames will be set
  2085. * to the coded dimensions and the crop_* fields will describe the cropping
  2086. * rectangle. Applying the cropping is left to the caller.
  2087. *
  2088. * @warning When hardware acceleration with opaque output frames is used,
  2089. * libavcodec is unable to apply cropping from the top/left border.
  2090. *
  2091. * @note when this option is set to zero, the width/height fields of the
  2092. * AVCodecContext and output AVFrames have different meanings. The codec
  2093. * context fields store display dimensions (with the coded dimensions in
  2094. * coded_width/height), while the frame fields store the coded dimensions
  2095. * (with the display dimensions being determined by the crop_* fields).
  2096. */
  2097. int apply_cropping;
  2098. /*
  2099. * Video decoding only. Sets the number of extra hardware frames which
  2100. * the decoder will allocate for use by the caller. This must be set
  2101. * before avcodec_open2() is called.
  2102. *
  2103. * Some hardware decoders require all frames that they will use for
  2104. * output to be defined in advance before decoding starts. For such
  2105. * decoders, the hardware frame pool must therefore be of a fixed size.
  2106. * The extra frames set here are on top of any number that the decoder
  2107. * needs internally in order to operate normally (for example, frames
  2108. * used as reference pictures).
  2109. */
  2110. int extra_hw_frames;
  2111. /**
  2112. * The percentage of damaged samples to discard a frame.
  2113. *
  2114. * - decoding: set by user
  2115. * - encoding: unused
  2116. */
  2117. int discard_damaged_percentage;
  2118. /**
  2119. * The number of samples per frame to maximally accept.
  2120. *
  2121. * - decoding: set by user
  2122. * - encoding: set by user
  2123. */
  2124. int64_t max_samples;
  2125. /**
  2126. * Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of
  2127. * metadata exported in frame, packet, or coded stream side data by
  2128. * decoders and encoders.
  2129. *
  2130. * - decoding: set by user
  2131. * - encoding: set by user
  2132. */
  2133. int export_side_data;
  2134. } AVCodecContext;
  2135. #if FF_API_CODEC_GET_SET
  2136. /**
  2137. * Accessors for some AVCodecContext fields. These used to be provided for ABI
  2138. * compatibility, and do not need to be used anymore.
  2139. */
  2140. attribute_deprecated
  2141. AVRational av_codec_get_pkt_timebase (const AVCodecContext *avctx);
  2142. attribute_deprecated
  2143. void av_codec_set_pkt_timebase (AVCodecContext *avctx, AVRational val);
  2144. attribute_deprecated
  2145. const AVCodecDescriptor *av_codec_get_codec_descriptor(const AVCodecContext *avctx);
  2146. attribute_deprecated
  2147. void av_codec_set_codec_descriptor(AVCodecContext *avctx, const AVCodecDescriptor *desc);
  2148. attribute_deprecated
  2149. unsigned av_codec_get_codec_properties(const AVCodecContext *avctx);
  2150. #if FF_API_LOWRES
  2151. attribute_deprecated
  2152. int av_codec_get_lowres(const AVCodecContext *avctx);
  2153. attribute_deprecated
  2154. void av_codec_set_lowres(AVCodecContext *avctx, int val);
  2155. #endif
  2156. attribute_deprecated
  2157. int av_codec_get_seek_preroll(const AVCodecContext *avctx);
  2158. attribute_deprecated
  2159. void av_codec_set_seek_preroll(AVCodecContext *avctx, int val);
  2160. attribute_deprecated
  2161. uint16_t *av_codec_get_chroma_intra_matrix(const AVCodecContext *avctx);
  2162. attribute_deprecated
  2163. void av_codec_set_chroma_intra_matrix(AVCodecContext *avctx, uint16_t *val);
  2164. #endif
  2165. struct AVSubtitle;
  2166. #if FF_API_CODEC_GET_SET
  2167. attribute_deprecated
  2168. int av_codec_get_max_lowres(const AVCodec *codec);
  2169. #endif
  2170. struct MpegEncContext;
  2171. /**
  2172. * @defgroup lavc_hwaccel AVHWAccel
  2173. *
  2174. * @note Nothing in this structure should be accessed by the user. At some
  2175. * point in future it will not be externally visible at all.
  2176. *
  2177. * @{
  2178. */
  2179. typedef struct AVHWAccel {
  2180. /**
  2181. * Name of the hardware accelerated codec.
  2182. * The name is globally unique among encoders and among decoders (but an
  2183. * encoder and a decoder can share the same name).
  2184. */
  2185. const char *name;
  2186. /**
  2187. * Type of codec implemented by the hardware accelerator.
  2188. *
  2189. * See AVMEDIA_TYPE_xxx
  2190. */
  2191. enum AVMediaType type;
  2192. /**
  2193. * Codec implemented by the hardware accelerator.
  2194. *
  2195. * See AV_CODEC_ID_xxx
  2196. */
  2197. enum AVCodecID id;
  2198. /**
  2199. * Supported pixel format.
  2200. *
  2201. * Only hardware accelerated formats are supported here.
  2202. */
  2203. enum AVPixelFormat pix_fmt;
  2204. /**
  2205. * Hardware accelerated codec capabilities.
  2206. * see AV_HWACCEL_CODEC_CAP_*
  2207. */
  2208. int capabilities;
  2209. /*****************************************************************
  2210. * No fields below this line are part of the public API. They
  2211. * may not be used outside of libavcodec and can be changed and
  2212. * removed at will.
  2213. * New public fields should be added right above.
  2214. *****************************************************************
  2215. */
  2216. /**
  2217. * Allocate a custom buffer
  2218. */
  2219. int (*alloc_frame)(AVCodecContext *avctx, AVFrame *frame);
  2220. /**
  2221. * Called at the beginning of each frame or field picture.
  2222. *
  2223. * Meaningful frame information (codec specific) is guaranteed to
  2224. * be parsed at this point. This function is mandatory.
  2225. *
  2226. * Note that buf can be NULL along with buf_size set to 0.
  2227. * Otherwise, this means the whole frame is available at this point.
  2228. *
  2229. * @param avctx the codec context
  2230. * @param buf the frame data buffer base
  2231. * @param buf_size the size of the frame in bytes
  2232. * @return zero if successful, a negative value otherwise
  2233. */
  2234. int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2235. /**
  2236. * Callback for parameter data (SPS/PPS/VPS etc).
  2237. *
  2238. * Useful for hardware decoders which keep persistent state about the
  2239. * video parameters, and need to receive any changes to update that state.
  2240. *
  2241. * @param avctx the codec context
  2242. * @param type the nal unit type
  2243. * @param buf the nal unit data buffer
  2244. * @param buf_size the size of the nal unit in bytes
  2245. * @return zero if successful, a negative value otherwise
  2246. */
  2247. int (*decode_params)(AVCodecContext *avctx, int type, const uint8_t *buf, uint32_t buf_size);
  2248. /**
  2249. * Callback for each slice.
  2250. *
  2251. * Meaningful slice information (codec specific) is guaranteed to
  2252. * be parsed at this point. This function is mandatory.
  2253. * The only exception is XvMC, that works on MB level.
  2254. *
  2255. * @param avctx the codec context
  2256. * @param buf the slice data buffer base
  2257. * @param buf_size the size of the slice in bytes
  2258. * @return zero if successful, a negative value otherwise
  2259. */
  2260. int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
  2261. /**
  2262. * Called at the end of each frame or field picture.
  2263. *
  2264. * The whole picture is parsed at this point and can now be sent
  2265. * to the hardware accelerator. This function is mandatory.
  2266. *
  2267. * @param avctx the codec context
  2268. * @return zero if successful, a negative value otherwise
  2269. */
  2270. int (*end_frame)(AVCodecContext *avctx);
  2271. /**
  2272. * Size of per-frame hardware accelerator private data.
  2273. *
  2274. * Private data is allocated with av_mallocz() before
  2275. * AVCodecContext.get_buffer() and deallocated after
  2276. * AVCodecContext.release_buffer().
  2277. */
  2278. int frame_priv_data_size;
  2279. /**
  2280. * Called for every Macroblock in a slice.
  2281. *
  2282. * XvMC uses it to replace the ff_mpv_reconstruct_mb().
  2283. * Instead of decoding to raw picture, MB parameters are
  2284. * stored in an array provided by the video driver.
  2285. *
  2286. * @param s the mpeg context
  2287. */
  2288. void (*decode_mb)(struct MpegEncContext *s);
  2289. /**
  2290. * Initialize the hwaccel private data.
  2291. *
  2292. * This will be called from ff_get_format(), after hwaccel and
  2293. * hwaccel_context are set and the hwaccel private data in AVCodecInternal
  2294. * is allocated.
  2295. */
  2296. int (*init)(AVCodecContext *avctx);
  2297. /**
  2298. * Uninitialize the hwaccel private data.
  2299. *
  2300. * This will be called from get_format() or avcodec_close(), after hwaccel
  2301. * and hwaccel_context are already uninitialized.
  2302. */
  2303. int (*uninit)(AVCodecContext *avctx);
  2304. /**
  2305. * Size of the private data to allocate in
  2306. * AVCodecInternal.hwaccel_priv_data.
  2307. */
  2308. int priv_data_size;
  2309. /**
  2310. * Internal hwaccel capabilities.
  2311. */
  2312. int caps_internal;
  2313. /**
  2314. * Fill the given hw_frames context with current codec parameters. Called
  2315. * from get_format. Refer to avcodec_get_hw_frames_parameters() for
  2316. * details.
  2317. *
  2318. * This CAN be called before AVHWAccel.init is called, and you must assume
  2319. * that avctx->hwaccel_priv_data is invalid.
  2320. */
  2321. int (*frame_params)(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
  2322. } AVHWAccel;
  2323. /**
  2324. * HWAccel is experimental and is thus avoided in favor of non experimental
  2325. * codecs
  2326. */
  2327. #define AV_HWACCEL_CODEC_CAP_EXPERIMENTAL 0x0200
  2328. /**
  2329. * Hardware acceleration should be used for decoding even if the codec level
  2330. * used is unknown or higher than the maximum supported level reported by the
  2331. * hardware driver.
  2332. *
  2333. * It's generally a good idea to pass this flag unless you have a specific
  2334. * reason not to, as hardware tends to under-report supported levels.
  2335. */
  2336. #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0)
  2337. /**
  2338. * Hardware acceleration can output YUV pixel formats with a different chroma
  2339. * sampling than 4:2:0 and/or other than 8 bits per component.
  2340. */
  2341. #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1)
  2342. /**
  2343. * Hardware acceleration should still be attempted for decoding when the
  2344. * codec profile does not match the reported capabilities of the hardware.
  2345. *
  2346. * For example, this can be used to try to decode baseline profile H.264
  2347. * streams in hardware - it will often succeed, because many streams marked
  2348. * as baseline profile actually conform to constrained baseline profile.
  2349. *
  2350. * @warning If the stream is actually not supported then the behaviour is
  2351. * undefined, and may include returning entirely incorrect output
  2352. * while indicating success.
  2353. */
  2354. #define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2)
  2355. /**
  2356. * @}
  2357. */
  2358. #if FF_API_AVPICTURE
  2359. /**
  2360. * @defgroup lavc_picture AVPicture
  2361. *
  2362. * Functions for working with AVPicture
  2363. * @{
  2364. */
  2365. /**
  2366. * Picture data structure.
  2367. *
  2368. * Up to four components can be stored into it, the last component is
  2369. * alpha.
  2370. * @deprecated use AVFrame or imgutils functions instead
  2371. */
  2372. typedef struct AVPicture {
  2373. attribute_deprecated
  2374. uint8_t *data[AV_NUM_DATA_POINTERS]; ///< pointers to the image data planes
  2375. attribute_deprecated
  2376. int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
  2377. } AVPicture;
  2378. /**
  2379. * @}
  2380. */
  2381. #endif
  2382. enum AVSubtitleType {
  2383. SUBTITLE_NONE,
  2384. SUBTITLE_BITMAP, ///< A bitmap, pict will be set
  2385. /**
  2386. * Plain text, the text field must be set by the decoder and is
  2387. * authoritative. ass and pict fields may contain approximations.
  2388. */
  2389. SUBTITLE_TEXT,
  2390. /**
  2391. * Formatted text, the ass field must be set by the decoder and is
  2392. * authoritative. pict and text fields may contain approximations.
  2393. */
  2394. SUBTITLE_ASS,
  2395. };
  2396. #define AV_SUBTITLE_FLAG_FORCED 0x00000001
  2397. typedef struct AVSubtitleRect {
  2398. int x; ///< top left corner of pict, undefined when pict is not set
  2399. int y; ///< top left corner of pict, undefined when pict is not set
  2400. int w; ///< width of pict, undefined when pict is not set
  2401. int h; ///< height of pict, undefined when pict is not set
  2402. int nb_colors; ///< number of colors in pict, undefined when pict is not set
  2403. #if FF_API_AVPICTURE
  2404. /**
  2405. * @deprecated unused
  2406. */
  2407. attribute_deprecated
  2408. AVPicture pict;
  2409. #endif
  2410. /**
  2411. * data+linesize for the bitmap of this subtitle.
  2412. * Can be set for text/ass as well once they are rendered.
  2413. */
  2414. uint8_t *data[4];
  2415. int linesize[4];
  2416. enum AVSubtitleType type;
  2417. char *text; ///< 0 terminated plain UTF-8 text
  2418. /**
  2419. * 0 terminated ASS/SSA compatible event line.
  2420. * The presentation of this is unaffected by the other values in this
  2421. * struct.
  2422. */
  2423. char *ass;
  2424. int flags;
  2425. } AVSubtitleRect;
  2426. typedef struct AVSubtitle {
  2427. uint16_t format; /* 0 = graphics */
  2428. uint32_t start_display_time; /* relative to packet pts, in ms */
  2429. uint32_t end_display_time; /* relative to packet pts, in ms */
  2430. unsigned num_rects;
  2431. AVSubtitleRect **rects;
  2432. int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
  2433. } AVSubtitle;
  2434. #if FF_API_NEXT
  2435. /**
  2436. * If c is NULL, returns the first registered codec,
  2437. * if c is non-NULL, returns the next registered codec after c,
  2438. * or NULL if c is the last one.
  2439. */
  2440. attribute_deprecated
  2441. AVCodec *av_codec_next(const AVCodec *c);
  2442. #endif
  2443. /**
  2444. * Return the LIBAVCODEC_VERSION_INT constant.
  2445. */
  2446. unsigned avcodec_version(void);
  2447. /**
  2448. * Return the libavcodec build-time configuration.
  2449. */
  2450. const char *avcodec_configuration(void);
  2451. /**
  2452. * Return the libavcodec license.
  2453. */
  2454. const char *avcodec_license(void);
  2455. #if FF_API_NEXT
  2456. /**
  2457. * Register the codec codec and initialize libavcodec.
  2458. *
  2459. * @warning either this function or avcodec_register_all() must be called
  2460. * before any other libavcodec functions.
  2461. *
  2462. * @see avcodec_register_all()
  2463. */
  2464. attribute_deprecated
  2465. void avcodec_register(AVCodec *codec);
  2466. /**
  2467. * Register all the codecs, parsers and bitstream filters which were enabled at
  2468. * configuration time. If you do not call this function you can select exactly
  2469. * which formats you want to support, by using the individual registration
  2470. * functions.
  2471. *
  2472. * @see avcodec_register
  2473. * @see av_register_codec_parser
  2474. * @see av_register_bitstream_filter
  2475. */
  2476. attribute_deprecated
  2477. void avcodec_register_all(void);
  2478. #endif
  2479. /**
  2480. * Allocate an AVCodecContext and set its fields to default values. The
  2481. * resulting struct should be freed with avcodec_free_context().
  2482. *
  2483. * @param codec if non-NULL, allocate private data and initialize defaults
  2484. * for the given codec. It is illegal to then call avcodec_open2()
  2485. * with a different codec.
  2486. * If NULL, then the codec-specific defaults won't be initialized,
  2487. * which may result in suboptimal default settings (this is
  2488. * important mainly for encoders, e.g. libx264).
  2489. *
  2490. * @return An AVCodecContext filled with default values or NULL on failure.
  2491. */
  2492. AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
  2493. /**
  2494. * Free the codec context and everything associated with it and write NULL to
  2495. * the provided pointer.
  2496. */
  2497. void avcodec_free_context(AVCodecContext **avctx);
  2498. #if FF_API_GET_CONTEXT_DEFAULTS
  2499. /**
  2500. * @deprecated This function should not be used, as closing and opening a codec
  2501. * context multiple time is not supported. A new codec context should be
  2502. * allocated for each new use.
  2503. */
  2504. int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec);
  2505. #endif
  2506. /**
  2507. * Get the AVClass for AVCodecContext. It can be used in combination with
  2508. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  2509. *
  2510. * @see av_opt_find().
  2511. */
  2512. const AVClass *avcodec_get_class(void);
  2513. #if FF_API_COPY_CONTEXT
  2514. /**
  2515. * Get the AVClass for AVFrame. It can be used in combination with
  2516. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  2517. *
  2518. * @see av_opt_find().
  2519. */
  2520. const AVClass *avcodec_get_frame_class(void);
  2521. /**
  2522. * Get the AVClass for AVSubtitleRect. It can be used in combination with
  2523. * AV_OPT_SEARCH_FAKE_OBJ for examining options.
  2524. *
  2525. * @see av_opt_find().
  2526. */
  2527. const AVClass *avcodec_get_subtitle_rect_class(void);
  2528. /**
  2529. * Copy the settings of the source AVCodecContext into the destination
  2530. * AVCodecContext. The resulting destination codec context will be
  2531. * unopened, i.e. you are required to call avcodec_open2() before you
  2532. * can use this AVCodecContext to decode/encode video/audio data.
  2533. *
  2534. * @param dest target codec context, should be initialized with
  2535. * avcodec_alloc_context3(NULL), but otherwise uninitialized
  2536. * @param src source codec context
  2537. * @return AVERROR() on error (e.g. memory allocation error), 0 on success
  2538. *
  2539. * @deprecated The semantics of this function are ill-defined and it should not
  2540. * be used. If you need to transfer the stream parameters from one codec context
  2541. * to another, use an intermediate AVCodecParameters instance and the
  2542. * avcodec_parameters_from_context() / avcodec_parameters_to_context()
  2543. * functions.
  2544. */
  2545. attribute_deprecated
  2546. int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
  2547. #endif
  2548. /**
  2549. * Fill the parameters struct based on the values from the supplied codec
  2550. * context. Any allocated fields in par are freed and replaced with duplicates
  2551. * of the corresponding fields in codec.
  2552. *
  2553. * @return >= 0 on success, a negative AVERROR code on failure
  2554. */
  2555. int avcodec_parameters_from_context(AVCodecParameters *par,
  2556. const AVCodecContext *codec);
  2557. /**
  2558. * Fill the codec context based on the values from the supplied codec
  2559. * parameters. Any allocated fields in codec that have a corresponding field in
  2560. * par are freed and replaced with duplicates of the corresponding field in par.
  2561. * Fields in codec that do not have a counterpart in par are not touched.
  2562. *
  2563. * @return >= 0 on success, a negative AVERROR code on failure.
  2564. */
  2565. int avcodec_parameters_to_context(AVCodecContext *codec,
  2566. const AVCodecParameters *par);
  2567. /**
  2568. * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
  2569. * function the context has to be allocated with avcodec_alloc_context3().
  2570. *
  2571. * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
  2572. * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  2573. * retrieving a codec.
  2574. *
  2575. * @warning This function is not thread safe!
  2576. *
  2577. * @note Always call this function before using decoding routines (such as
  2578. * @ref avcodec_receive_frame()).
  2579. *
  2580. * @code
  2581. * avcodec_register_all();
  2582. * av_dict_set(&opts, "b", "2.5M", 0);
  2583. * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
  2584. * if (!codec)
  2585. * exit(1);
  2586. *
  2587. * context = avcodec_alloc_context3(codec);
  2588. *
  2589. * if (avcodec_open2(context, codec, opts) < 0)
  2590. * exit(1);
  2591. * @endcode
  2592. *
  2593. * @param avctx The context to initialize.
  2594. * @param codec The codec to open this context for. If a non-NULL codec has been
  2595. * previously passed to avcodec_alloc_context3() or
  2596. * for this context, then this parameter MUST be either NULL or
  2597. * equal to the previously passed codec.
  2598. * @param options A dictionary filled with AVCodecContext and codec-private options.
  2599. * On return this object will be filled with options that were not found.
  2600. *
  2601. * @return zero on success, a negative value on error
  2602. * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
  2603. * av_dict_set(), av_opt_find().
  2604. */
  2605. int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
  2606. /**
  2607. * Close a given AVCodecContext and free all the data associated with it
  2608. * (but not the AVCodecContext itself).
  2609. *
  2610. * Calling this function on an AVCodecContext that hasn't been opened will free
  2611. * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
  2612. * codec. Subsequent calls will do nothing.
  2613. *
  2614. * @note Do not use this function. Use avcodec_free_context() to destroy a
  2615. * codec context (either open or closed). Opening and closing a codec context
  2616. * multiple times is not supported anymore -- use multiple codec contexts
  2617. * instead.
  2618. */
  2619. int avcodec_close(AVCodecContext *avctx);
  2620. /**
  2621. * Free all allocated data in the given subtitle struct.
  2622. *
  2623. * @param sub AVSubtitle to free.
  2624. */
  2625. void avsubtitle_free(AVSubtitle *sub);
  2626. /**
  2627. * @}
  2628. */
  2629. /**
  2630. * @addtogroup lavc_decoding
  2631. * @{
  2632. */
  2633. /**
  2634. * The default callback for AVCodecContext.get_buffer2(). It is made public so
  2635. * it can be called by custom get_buffer2() implementations for decoders without
  2636. * AV_CODEC_CAP_DR1 set.
  2637. */
  2638. int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags);
  2639. /**
  2640. * Modify width and height values so that they will result in a memory
  2641. * buffer that is acceptable for the codec if you do not use any horizontal
  2642. * padding.
  2643. *
  2644. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  2645. */
  2646. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  2647. /**
  2648. * Modify width and height values so that they will result in a memory
  2649. * buffer that is acceptable for the codec if you also ensure that all
  2650. * line sizes are a multiple of the respective linesize_align[i].
  2651. *
  2652. * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
  2653. */
  2654. void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height,
  2655. int linesize_align[AV_NUM_DATA_POINTERS]);
  2656. /**
  2657. * Converts AVChromaLocation to swscale x/y chroma position.
  2658. *
  2659. * The positions represent the chroma (0,0) position in a coordinates system
  2660. * with luma (0,0) representing the origin and luma(1,1) representing 256,256
  2661. *
  2662. * @param xpos horizontal chroma sample position
  2663. * @param ypos vertical chroma sample position
  2664. */
  2665. int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos);
  2666. /**
  2667. * Converts swscale x/y chroma position to AVChromaLocation.
  2668. *
  2669. * The positions represent the chroma (0,0) position in a coordinates system
  2670. * with luma (0,0) representing the origin and luma(1,1) representing 256,256
  2671. *
  2672. * @param xpos horizontal chroma sample position
  2673. * @param ypos vertical chroma sample position
  2674. */
  2675. enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos);
  2676. /**
  2677. * Decode the audio frame of size avpkt->size from avpkt->data into frame.
  2678. *
  2679. * Some decoders may support multiple frames in a single AVPacket. Such
  2680. * decoders would then just decode the first frame and the return value would be
  2681. * less than the packet size. In this case, avcodec_decode_audio4 has to be
  2682. * called again with an AVPacket containing the remaining data in order to
  2683. * decode the second frame, etc... Even if no frames are returned, the packet
  2684. * needs to be fed to the decoder with remaining data until it is completely
  2685. * consumed or an error occurs.
  2686. *
  2687. * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
  2688. * and output. This means that for some packets they will not immediately
  2689. * produce decoded output and need to be flushed at the end of decoding to get
  2690. * all the decoded data. Flushing is done by calling this function with packets
  2691. * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
  2692. * returning samples. It is safe to flush even those decoders that are not
  2693. * marked with AV_CODEC_CAP_DELAY, then no samples will be returned.
  2694. *
  2695. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  2696. * larger than the actual read bytes because some optimized bitstream
  2697. * readers read 32 or 64 bits at once and could read over the end.
  2698. *
  2699. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  2700. * before packets may be fed to the decoder.
  2701. *
  2702. * @param avctx the codec context
  2703. * @param[out] frame The AVFrame in which to store decoded audio samples.
  2704. * The decoder will allocate a buffer for the decoded frame by
  2705. * calling the AVCodecContext.get_buffer2() callback.
  2706. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  2707. * reference counted and the returned reference belongs to the
  2708. * caller. The caller must release the frame using av_frame_unref()
  2709. * when the frame is no longer needed. The caller may safely write
  2710. * to the frame if av_frame_is_writable() returns 1.
  2711. * When AVCodecContext.refcounted_frames is set to 0, the returned
  2712. * reference belongs to the decoder and is valid only until the
  2713. * next call to this function or until closing or flushing the
  2714. * decoder. The caller may not write to it.
  2715. * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
  2716. * non-zero. Note that this field being set to zero
  2717. * does not mean that an error has occurred. For
  2718. * decoders with AV_CODEC_CAP_DELAY set, no given decode
  2719. * call is guaranteed to produce a frame.
  2720. * @param[in] avpkt The input AVPacket containing the input buffer.
  2721. * At least avpkt->data and avpkt->size should be set. Some
  2722. * decoders might also require additional fields to be set.
  2723. * @return A negative error code is returned if an error occurred during
  2724. * decoding, otherwise the number of bytes consumed from the input
  2725. * AVPacket is returned.
  2726. *
  2727. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  2728. */
  2729. attribute_deprecated
  2730. int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame,
  2731. int *got_frame_ptr, const AVPacket *avpkt);
  2732. /**
  2733. * Decode the video frame of size avpkt->size from avpkt->data into picture.
  2734. * Some decoders may support multiple frames in a single AVPacket, such
  2735. * decoders would then just decode the first frame.
  2736. *
  2737. * @warning The input buffer must be AV_INPUT_BUFFER_PADDING_SIZE larger than
  2738. * the actual read bytes because some optimized bitstream readers read 32 or 64
  2739. * bits at once and could read over the end.
  2740. *
  2741. * @warning The end of the input buffer buf should be set to 0 to ensure that
  2742. * no overreading happens for damaged MPEG streams.
  2743. *
  2744. * @note Codecs which have the AV_CODEC_CAP_DELAY capability set have a delay
  2745. * between input and output, these need to be fed with avpkt->data=NULL,
  2746. * avpkt->size=0 at the end to return the remaining frames.
  2747. *
  2748. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  2749. * before packets may be fed to the decoder.
  2750. *
  2751. * @param avctx the codec context
  2752. * @param[out] picture The AVFrame in which the decoded video frame will be stored.
  2753. * Use av_frame_alloc() to get an AVFrame. The codec will
  2754. * allocate memory for the actual bitmap by calling the
  2755. * AVCodecContext.get_buffer2() callback.
  2756. * When AVCodecContext.refcounted_frames is set to 1, the frame is
  2757. * reference counted and the returned reference belongs to the
  2758. * caller. The caller must release the frame using av_frame_unref()
  2759. * when the frame is no longer needed. The caller may safely write
  2760. * to the frame if av_frame_is_writable() returns 1.
  2761. * When AVCodecContext.refcounted_frames is set to 0, the returned
  2762. * reference belongs to the decoder and is valid only until the
  2763. * next call to this function or until closing or flushing the
  2764. * decoder. The caller may not write to it.
  2765. *
  2766. * @param[in] avpkt The input AVPacket containing the input buffer.
  2767. * You can create such packet with av_init_packet() and by then setting
  2768. * data and size, some decoders might in addition need other fields like
  2769. * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
  2770. * fields possible.
  2771. * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
  2772. * @return On error a negative value is returned, otherwise the number of bytes
  2773. * used or zero if no frame could be decompressed.
  2774. *
  2775. * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
  2776. */
  2777. attribute_deprecated
  2778. int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
  2779. int *got_picture_ptr,
  2780. const AVPacket *avpkt);
  2781. /**
  2782. * Decode a subtitle message.
  2783. * Return a negative value on error, otherwise return the number of bytes used.
  2784. * If no subtitle could be decompressed, got_sub_ptr is zero.
  2785. * Otherwise, the subtitle is stored in *sub.
  2786. * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for
  2787. * simplicity, because the performance difference is expected to be negligible
  2788. * and reusing a get_buffer written for video codecs would probably perform badly
  2789. * due to a potentially very different allocation pattern.
  2790. *
  2791. * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
  2792. * and output. This means that for some packets they will not immediately
  2793. * produce decoded output and need to be flushed at the end of decoding to get
  2794. * all the decoded data. Flushing is done by calling this function with packets
  2795. * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
  2796. * returning subtitles. It is safe to flush even those decoders that are not
  2797. * marked with AV_CODEC_CAP_DELAY, then no subtitles will be returned.
  2798. *
  2799. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  2800. * before packets may be fed to the decoder.
  2801. *
  2802. * @param avctx the codec context
  2803. * @param[out] sub The preallocated AVSubtitle in which the decoded subtitle will be stored,
  2804. * must be freed with avsubtitle_free if *got_sub_ptr is set.
  2805. * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
  2806. * @param[in] avpkt The input AVPacket containing the input buffer.
  2807. */
  2808. int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
  2809. int *got_sub_ptr,
  2810. AVPacket *avpkt);
  2811. /**
  2812. * Supply raw packet data as input to a decoder.
  2813. *
  2814. * Internally, this call will copy relevant AVCodecContext fields, which can
  2815. * influence decoding per-packet, and apply them when the packet is actually
  2816. * decoded. (For example AVCodecContext.skip_frame, which might direct the
  2817. * decoder to drop the frame contained by the packet sent with this function.)
  2818. *
  2819. * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
  2820. * larger than the actual read bytes because some optimized bitstream
  2821. * readers read 32 or 64 bits at once and could read over the end.
  2822. *
  2823. * @warning Do not mix this API with the legacy API (like avcodec_decode_video2())
  2824. * on the same AVCodecContext. It will return unexpected results now
  2825. * or in future libavcodec versions.
  2826. *
  2827. * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
  2828. * before packets may be fed to the decoder.
  2829. *
  2830. * @param avctx codec context
  2831. * @param[in] avpkt The input AVPacket. Usually, this will be a single video
  2832. * frame, or several complete audio frames.
  2833. * Ownership of the packet remains with the caller, and the
  2834. * decoder will not write to the packet. The decoder may create
  2835. * a reference to the packet data (or copy it if the packet is
  2836. * not reference-counted).
  2837. * Unlike with older APIs, the packet is always fully consumed,
  2838. * and if it contains multiple frames (e.g. some audio codecs),
  2839. * will require you to call avcodec_receive_frame() multiple
  2840. * times afterwards before you can send a new packet.
  2841. * It can be NULL (or an AVPacket with data set to NULL and
  2842. * size set to 0); in this case, it is considered a flush
  2843. * packet, which signals the end of the stream. Sending the
  2844. * first flush packet will return success. Subsequent ones are
  2845. * unnecessary and will return AVERROR_EOF. If the decoder
  2846. * still has frames buffered, it will return them after sending
  2847. * a flush packet.
  2848. *
  2849. * @return 0 on success, otherwise negative error code:
  2850. * AVERROR(EAGAIN): input is not accepted in the current state - user
  2851. * must read output with avcodec_receive_frame() (once
  2852. * all output is read, the packet should be resent, and
  2853. * the call will not fail with EAGAIN).
  2854. * AVERROR_EOF: the decoder has been flushed, and no new packets can
  2855. * be sent to it (also returned if more than 1 flush
  2856. * packet is sent)
  2857. * AVERROR(EINVAL): codec not opened, it is an encoder, or requires flush
  2858. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  2859. * other errors: legitimate decoding errors
  2860. */
  2861. int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt);
  2862. /**
  2863. * Return decoded output data from a decoder.
  2864. *
  2865. * @param avctx codec context
  2866. * @param frame This will be set to a reference-counted video or audio
  2867. * frame (depending on the decoder type) allocated by the
  2868. * decoder. Note that the function will always call
  2869. * av_frame_unref(frame) before doing anything else.
  2870. *
  2871. * @return
  2872. * 0: success, a frame was returned
  2873. * AVERROR(EAGAIN): output is not available in this state - user must try
  2874. * to send new input
  2875. * AVERROR_EOF: the decoder has been fully flushed, and there will be
  2876. * no more output frames
  2877. * AVERROR(EINVAL): codec not opened, or it is an encoder
  2878. * AVERROR_INPUT_CHANGED: current decoded frame has changed parameters
  2879. * with respect to first decoded frame. Applicable
  2880. * when flag AV_CODEC_FLAG_DROPCHANGED is set.
  2881. * other negative values: legitimate decoding errors
  2882. */
  2883. int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
  2884. /**
  2885. * Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()
  2886. * to retrieve buffered output packets.
  2887. *
  2888. * @param avctx codec context
  2889. * @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
  2890. * Ownership of the frame remains with the caller, and the
  2891. * encoder will not write to the frame. The encoder may create
  2892. * a reference to the frame data (or copy it if the frame is
  2893. * not reference-counted).
  2894. * It can be NULL, in which case it is considered a flush
  2895. * packet. This signals the end of the stream. If the encoder
  2896. * still has packets buffered, it will return them after this
  2897. * call. Once flushing mode has been entered, additional flush
  2898. * packets are ignored, and sending frames will return
  2899. * AVERROR_EOF.
  2900. *
  2901. * For audio:
  2902. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  2903. * can have any number of samples.
  2904. * If it is not set, frame->nb_samples must be equal to
  2905. * avctx->frame_size for all frames except the last.
  2906. * The final frame may be smaller than avctx->frame_size.
  2907. * @return 0 on success, otherwise negative error code:
  2908. * AVERROR(EAGAIN): input is not accepted in the current state - user
  2909. * must read output with avcodec_receive_packet() (once
  2910. * all output is read, the packet should be resent, and
  2911. * the call will not fail with EAGAIN).
  2912. * AVERROR_EOF: the encoder has been flushed, and no new frames can
  2913. * be sent to it
  2914. * AVERROR(EINVAL): codec not opened, refcounted_frames not set, it is a
  2915. * decoder, or requires flush
  2916. * AVERROR(ENOMEM): failed to add packet to internal queue, or similar
  2917. * other errors: legitimate encoding errors
  2918. */
  2919. int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame);
  2920. /**
  2921. * Read encoded data from the encoder.
  2922. *
  2923. * @param avctx codec context
  2924. * @param avpkt This will be set to a reference-counted packet allocated by the
  2925. * encoder. Note that the function will always call
  2926. * av_packet_unref(avpkt) before doing anything else.
  2927. * @return 0 on success, otherwise negative error code:
  2928. * AVERROR(EAGAIN): output is not available in the current state - user
  2929. * must try to send input
  2930. * AVERROR_EOF: the encoder has been fully flushed, and there will be
  2931. * no more output packets
  2932. * AVERROR(EINVAL): codec not opened, or it is a decoder
  2933. * other errors: legitimate encoding errors
  2934. */
  2935. int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt);
  2936. /**
  2937. * Create and return a AVHWFramesContext with values adequate for hardware
  2938. * decoding. This is meant to get called from the get_format callback, and is
  2939. * a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx.
  2940. * This API is for decoding with certain hardware acceleration modes/APIs only.
  2941. *
  2942. * The returned AVHWFramesContext is not initialized. The caller must do this
  2943. * with av_hwframe_ctx_init().
  2944. *
  2945. * Calling this function is not a requirement, but makes it simpler to avoid
  2946. * codec or hardware API specific details when manually allocating frames.
  2947. *
  2948. * Alternatively to this, an API user can set AVCodecContext.hw_device_ctx,
  2949. * which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes
  2950. * it unnecessary to call this function or having to care about
  2951. * AVHWFramesContext initialization at all.
  2952. *
  2953. * There are a number of requirements for calling this function:
  2954. *
  2955. * - It must be called from get_format with the same avctx parameter that was
  2956. * passed to get_format. Calling it outside of get_format is not allowed, and
  2957. * can trigger undefined behavior.
  2958. * - The function is not always supported (see description of return values).
  2959. * Even if this function returns successfully, hwaccel initialization could
  2960. * fail later. (The degree to which implementations check whether the stream
  2961. * is actually supported varies. Some do this check only after the user's
  2962. * get_format callback returns.)
  2963. * - The hw_pix_fmt must be one of the choices suggested by get_format. If the
  2964. * user decides to use a AVHWFramesContext prepared with this API function,
  2965. * the user must return the same hw_pix_fmt from get_format.
  2966. * - The device_ref passed to this function must support the given hw_pix_fmt.
  2967. * - After calling this API function, it is the user's responsibility to
  2968. * initialize the AVHWFramesContext (returned by the out_frames_ref parameter),
  2969. * and to set AVCodecContext.hw_frames_ctx to it. If done, this must be done
  2970. * before returning from get_format (this is implied by the normal
  2971. * AVCodecContext.hw_frames_ctx API rules).
  2972. * - The AVHWFramesContext parameters may change every time time get_format is
  2973. * called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So
  2974. * you are inherently required to go through this process again on every
  2975. * get_format call.
  2976. * - It is perfectly possible to call this function without actually using
  2977. * the resulting AVHWFramesContext. One use-case might be trying to reuse a
  2978. * previously initialized AVHWFramesContext, and calling this API function
  2979. * only to test whether the required frame parameters have changed.
  2980. * - Fields that use dynamically allocated values of any kind must not be set
  2981. * by the user unless setting them is explicitly allowed by the documentation.
  2982. * If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque,
  2983. * the new free callback must call the potentially set previous free callback.
  2984. * This API call may set any dynamically allocated fields, including the free
  2985. * callback.
  2986. *
  2987. * The function will set at least the following fields on AVHWFramesContext
  2988. * (potentially more, depending on hwaccel API):
  2989. *
  2990. * - All fields set by av_hwframe_ctx_alloc().
  2991. * - Set the format field to hw_pix_fmt.
  2992. * - Set the sw_format field to the most suited and most versatile format. (An
  2993. * implication is that this will prefer generic formats over opaque formats
  2994. * with arbitrary restrictions, if possible.)
  2995. * - Set the width/height fields to the coded frame size, rounded up to the
  2996. * API-specific minimum alignment.
  2997. * - Only _if_ the hwaccel requires a pre-allocated pool: set the initial_pool_size
  2998. * field to the number of maximum reference surfaces possible with the codec,
  2999. * plus 1 surface for the user to work (meaning the user can safely reference
  3000. * at most 1 decoded surface at a time), plus additional buffering introduced
  3001. * by frame threading. If the hwaccel does not require pre-allocation, the
  3002. * field is left to 0, and the decoder will allocate new surfaces on demand
  3003. * during decoding.
  3004. * - Possibly AVHWFramesContext.hwctx fields, depending on the underlying
  3005. * hardware API.
  3006. *
  3007. * Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but
  3008. * with basic frame parameters set.
  3009. *
  3010. * The function is stateless, and does not change the AVCodecContext or the
  3011. * device_ref AVHWDeviceContext.
  3012. *
  3013. * @param avctx The context which is currently calling get_format, and which
  3014. * implicitly contains all state needed for filling the returned
  3015. * AVHWFramesContext properly.
  3016. * @param device_ref A reference to the AVHWDeviceContext describing the device
  3017. * which will be used by the hardware decoder.
  3018. * @param hw_pix_fmt The hwaccel format you are going to return from get_format.
  3019. * @param out_frames_ref On success, set to a reference to an _uninitialized_
  3020. * AVHWFramesContext, created from the given device_ref.
  3021. * Fields will be set to values required for decoding.
  3022. * Not changed if an error is returned.
  3023. * @return zero on success, a negative value on error. The following error codes
  3024. * have special semantics:
  3025. * AVERROR(ENOENT): the decoder does not support this functionality. Setup
  3026. * is always manual, or it is a decoder which does not
  3027. * support setting AVCodecContext.hw_frames_ctx at all,
  3028. * or it is a software format.
  3029. * AVERROR(EINVAL): it is known that hardware decoding is not supported for
  3030. * this configuration, or the device_ref is not supported
  3031. * for the hwaccel referenced by hw_pix_fmt.
  3032. */
  3033. int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
  3034. AVBufferRef *device_ref,
  3035. enum AVPixelFormat hw_pix_fmt,
  3036. AVBufferRef **out_frames_ref);
  3037. /**
  3038. * @defgroup lavc_parsing Frame parsing
  3039. * @{
  3040. */
  3041. enum AVPictureStructure {
  3042. AV_PICTURE_STRUCTURE_UNKNOWN, //< unknown
  3043. AV_PICTURE_STRUCTURE_TOP_FIELD, //< coded as top field
  3044. AV_PICTURE_STRUCTURE_BOTTOM_FIELD, //< coded as bottom field
  3045. AV_PICTURE_STRUCTURE_FRAME, //< coded as frame
  3046. };
  3047. typedef struct AVCodecParserContext {
  3048. void *priv_data;
  3049. struct AVCodecParser *parser;
  3050. int64_t frame_offset; /* offset of the current frame */
  3051. int64_t cur_offset; /* current offset
  3052. (incremented by each av_parser_parse()) */
  3053. int64_t next_frame_offset; /* offset of the next frame */
  3054. /* video info */
  3055. int pict_type; /* XXX: Put it back in AVCodecContext. */
  3056. /**
  3057. * This field is used for proper frame duration computation in lavf.
  3058. * It signals, how much longer the frame duration of the current frame
  3059. * is compared to normal frame duration.
  3060. *
  3061. * frame_duration = (1 + repeat_pict) * time_base
  3062. *
  3063. * It is used by codecs like H.264 to display telecined material.
  3064. */
  3065. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
  3066. int64_t pts; /* pts of the current frame */
  3067. int64_t dts; /* dts of the current frame */
  3068. /* private data */
  3069. int64_t last_pts;
  3070. int64_t last_dts;
  3071. int fetch_timestamp;
  3072. #define AV_PARSER_PTS_NB 4
  3073. int cur_frame_start_index;
  3074. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  3075. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  3076. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  3077. int flags;
  3078. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
  3079. #define PARSER_FLAG_ONCE 0x0002
  3080. /// Set if the parser has a valid file offset
  3081. #define PARSER_FLAG_FETCHED_OFFSET 0x0004
  3082. #define PARSER_FLAG_USE_CODEC_TS 0x1000
  3083. int64_t offset; ///< byte offset from starting packet start
  3084. int64_t cur_frame_end[AV_PARSER_PTS_NB];
  3085. /**
  3086. * Set by parser to 1 for key frames and 0 for non-key frames.
  3087. * It is initialized to -1, so if the parser doesn't set this flag,
  3088. * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
  3089. * will be used.
  3090. */
  3091. int key_frame;
  3092. #if FF_API_CONVERGENCE_DURATION
  3093. /**
  3094. * @deprecated unused
  3095. */
  3096. attribute_deprecated
  3097. int64_t convergence_duration;
  3098. #endif
  3099. // Timestamp generation support:
  3100. /**
  3101. * Synchronization point for start of timestamp generation.
  3102. *
  3103. * Set to >0 for sync point, 0 for no sync point and <0 for undefined
  3104. * (default).
  3105. *
  3106. * For example, this corresponds to presence of H.264 buffering period
  3107. * SEI message.
  3108. */
  3109. int dts_sync_point;
  3110. /**
  3111. * Offset of the current timestamp against last timestamp sync point in
  3112. * units of AVCodecContext.time_base.
  3113. *
  3114. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3115. * contain a valid timestamp offset.
  3116. *
  3117. * Note that the timestamp of sync point has usually a nonzero
  3118. * dts_ref_dts_delta, which refers to the previous sync point. Offset of
  3119. * the next frame after timestamp sync point will be usually 1.
  3120. *
  3121. * For example, this corresponds to H.264 cpb_removal_delay.
  3122. */
  3123. int dts_ref_dts_delta;
  3124. /**
  3125. * Presentation delay of current frame in units of AVCodecContext.time_base.
  3126. *
  3127. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
  3128. * contain valid non-negative timestamp delta (presentation time of a frame
  3129. * must not lie in the past).
  3130. *
  3131. * This delay represents the difference between decoding and presentation
  3132. * time of the frame.
  3133. *
  3134. * For example, this corresponds to H.264 dpb_output_delay.
  3135. */
  3136. int pts_dts_delta;
  3137. /**
  3138. * Position of the packet in file.
  3139. *
  3140. * Analogous to cur_frame_pts/dts
  3141. */
  3142. int64_t cur_frame_pos[AV_PARSER_PTS_NB];
  3143. /**
  3144. * Byte position of currently parsed frame in stream.
  3145. */
  3146. int64_t pos;
  3147. /**
  3148. * Previous frame byte position.
  3149. */
  3150. int64_t last_pos;
  3151. /**
  3152. * Duration of the current frame.
  3153. * For audio, this is in units of 1 / AVCodecContext.sample_rate.
  3154. * For all other types, this is in units of AVCodecContext.time_base.
  3155. */
  3156. int duration;
  3157. enum AVFieldOrder field_order;
  3158. /**
  3159. * Indicate whether a picture is coded as a frame, top field or bottom field.
  3160. *
  3161. * For example, H.264 field_pic_flag equal to 0 corresponds to
  3162. * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
  3163. * equal to 1 and bottom_field_flag equal to 0 corresponds to
  3164. * AV_PICTURE_STRUCTURE_TOP_FIELD.
  3165. */
  3166. enum AVPictureStructure picture_structure;
  3167. /**
  3168. * Picture number incremented in presentation or output order.
  3169. * This field may be reinitialized at the first picture of a new sequence.
  3170. *
  3171. * For example, this corresponds to H.264 PicOrderCnt.
  3172. */
  3173. int output_picture_number;
  3174. /**
  3175. * Dimensions of the decoded video intended for presentation.
  3176. */
  3177. int width;
  3178. int height;
  3179. /**
  3180. * Dimensions of the coded video.
  3181. */
  3182. int coded_width;
  3183. int coded_height;
  3184. /**
  3185. * The format of the coded data, corresponds to enum AVPixelFormat for video
  3186. * and for enum AVSampleFormat for audio.
  3187. *
  3188. * Note that a decoder can have considerable freedom in how exactly it
  3189. * decodes the data, so the format reported here might be different from the
  3190. * one returned by a decoder.
  3191. */
  3192. int format;
  3193. } AVCodecParserContext;
  3194. typedef struct AVCodecParser {
  3195. int codec_ids[5]; /* several codec IDs are permitted */
  3196. int priv_data_size;
  3197. int (*parser_init)(AVCodecParserContext *s);
  3198. /* This callback never returns an error, a negative value means that
  3199. * the frame start was in a previous packet. */
  3200. int (*parser_parse)(AVCodecParserContext *s,
  3201. AVCodecContext *avctx,
  3202. const uint8_t **poutbuf, int *poutbuf_size,
  3203. const uint8_t *buf, int buf_size);
  3204. void (*parser_close)(AVCodecParserContext *s);
  3205. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  3206. struct AVCodecParser *next;
  3207. } AVCodecParser;
  3208. /**
  3209. * Iterate over all registered codec parsers.
  3210. *
  3211. * @param opaque a pointer where libavcodec will store the iteration state. Must
  3212. * point to NULL to start the iteration.
  3213. *
  3214. * @return the next registered codec parser or NULL when the iteration is
  3215. * finished
  3216. */
  3217. const AVCodecParser *av_parser_iterate(void **opaque);
  3218. attribute_deprecated
  3219. AVCodecParser *av_parser_next(const AVCodecParser *c);
  3220. attribute_deprecated
  3221. void av_register_codec_parser(AVCodecParser *parser);
  3222. AVCodecParserContext *av_parser_init(int codec_id);
  3223. /**
  3224. * Parse a packet.
  3225. *
  3226. * @param s parser context.
  3227. * @param avctx codec context.
  3228. * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
  3229. * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
  3230. * @param buf input buffer.
  3231. * @param buf_size buffer size in bytes without the padding. I.e. the full buffer
  3232. size is assumed to be buf_size + AV_INPUT_BUFFER_PADDING_SIZE.
  3233. To signal EOF, this should be 0 (so that the last frame
  3234. can be output).
  3235. * @param pts input presentation timestamp.
  3236. * @param dts input decoding timestamp.
  3237. * @param pos input byte position in stream.
  3238. * @return the number of bytes of the input bitstream used.
  3239. *
  3240. * Example:
  3241. * @code
  3242. * while(in_len){
  3243. * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
  3244. * in_data, in_len,
  3245. * pts, dts, pos);
  3246. * in_data += len;
  3247. * in_len -= len;
  3248. *
  3249. * if(size)
  3250. * decode_frame(data, size);
  3251. * }
  3252. * @endcode
  3253. */
  3254. int av_parser_parse2(AVCodecParserContext *s,
  3255. AVCodecContext *avctx,
  3256. uint8_t **poutbuf, int *poutbuf_size,
  3257. const uint8_t *buf, int buf_size,
  3258. int64_t pts, int64_t dts,
  3259. int64_t pos);
  3260. /**
  3261. * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
  3262. * @deprecated use AVBitStreamFilter
  3263. */
  3264. int av_parser_change(AVCodecParserContext *s,
  3265. AVCodecContext *avctx,
  3266. uint8_t **poutbuf, int *poutbuf_size,
  3267. const uint8_t *buf, int buf_size, int keyframe);
  3268. void av_parser_close(AVCodecParserContext *s);
  3269. /**
  3270. * @}
  3271. * @}
  3272. */
  3273. /**
  3274. * @addtogroup lavc_encoding
  3275. * @{
  3276. */
  3277. /**
  3278. * Encode a frame of audio.
  3279. *
  3280. * Takes input samples from frame and writes the next output packet, if
  3281. * available, to avpkt. The output packet does not necessarily contain data for
  3282. * the most recent frame, as encoders can delay, split, and combine input frames
  3283. * internally as needed.
  3284. *
  3285. * @param avctx codec context
  3286. * @param avpkt output AVPacket.
  3287. * The user can supply an output buffer by setting
  3288. * avpkt->data and avpkt->size prior to calling the
  3289. * function, but if the size of the user-provided data is not
  3290. * large enough, encoding will fail. If avpkt->data and
  3291. * avpkt->size are set, avpkt->destruct must also be set. All
  3292. * other AVPacket fields will be reset by the encoder using
  3293. * av_init_packet(). If avpkt->data is NULL, the encoder will
  3294. * allocate it. The encoder will set avpkt->size to the size
  3295. * of the output packet.
  3296. *
  3297. * If this function fails or produces no output, avpkt will be
  3298. * freed using av_packet_unref().
  3299. * @param[in] frame AVFrame containing the raw audio data to be encoded.
  3300. * May be NULL when flushing an encoder that has the
  3301. * AV_CODEC_CAP_DELAY capability set.
  3302. * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
  3303. * can have any number of samples.
  3304. * If it is not set, frame->nb_samples must be equal to
  3305. * avctx->frame_size for all frames except the last.
  3306. * The final frame may be smaller than avctx->frame_size.
  3307. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  3308. * output packet is non-empty, and to 0 if it is
  3309. * empty. If the function returns an error, the
  3310. * packet can be assumed to be invalid, and the
  3311. * value of got_packet_ptr is undefined and should
  3312. * not be used.
  3313. * @return 0 on success, negative error code on failure
  3314. *
  3315. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  3316. */
  3317. attribute_deprecated
  3318. int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
  3319. const AVFrame *frame, int *got_packet_ptr);
  3320. /**
  3321. * Encode a frame of video.
  3322. *
  3323. * Takes input raw video data from frame and writes the next output packet, if
  3324. * available, to avpkt. The output packet does not necessarily contain data for
  3325. * the most recent frame, as encoders can delay and reorder input frames
  3326. * internally as needed.
  3327. *
  3328. * @param avctx codec context
  3329. * @param avpkt output AVPacket.
  3330. * The user can supply an output buffer by setting
  3331. * avpkt->data and avpkt->size prior to calling the
  3332. * function, but if the size of the user-provided data is not
  3333. * large enough, encoding will fail. All other AVPacket fields
  3334. * will be reset by the encoder using av_init_packet(). If
  3335. * avpkt->data is NULL, the encoder will allocate it.
  3336. * The encoder will set avpkt->size to the size of the
  3337. * output packet. The returned data (if any) belongs to the
  3338. * caller, he is responsible for freeing it.
  3339. *
  3340. * If this function fails or produces no output, avpkt will be
  3341. * freed using av_packet_unref().
  3342. * @param[in] frame AVFrame containing the raw video data to be encoded.
  3343. * May be NULL when flushing an encoder that has the
  3344. * AV_CODEC_CAP_DELAY capability set.
  3345. * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
  3346. * output packet is non-empty, and to 0 if it is
  3347. * empty. If the function returns an error, the
  3348. * packet can be assumed to be invalid, and the
  3349. * value of got_packet_ptr is undefined and should
  3350. * not be used.
  3351. * @return 0 on success, negative error code on failure
  3352. *
  3353. * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead
  3354. */
  3355. attribute_deprecated
  3356. int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
  3357. const AVFrame *frame, int *got_packet_ptr);
  3358. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  3359. const AVSubtitle *sub);
  3360. /**
  3361. * @}
  3362. */
  3363. #if FF_API_AVPICTURE
  3364. /**
  3365. * @addtogroup lavc_picture
  3366. * @{
  3367. */
  3368. /**
  3369. * @deprecated unused
  3370. */
  3371. attribute_deprecated
  3372. int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
  3373. /**
  3374. * @deprecated unused
  3375. */
  3376. attribute_deprecated
  3377. void avpicture_free(AVPicture *picture);
  3378. /**
  3379. * @deprecated use av_image_fill_arrays() instead.
  3380. */
  3381. attribute_deprecated
  3382. int avpicture_fill(AVPicture *picture, const uint8_t *ptr,
  3383. enum AVPixelFormat pix_fmt, int width, int height);
  3384. /**
  3385. * @deprecated use av_image_copy_to_buffer() instead.
  3386. */
  3387. attribute_deprecated
  3388. int avpicture_layout(const AVPicture *src, enum AVPixelFormat pix_fmt,
  3389. int width, int height,
  3390. unsigned char *dest, int dest_size);
  3391. /**
  3392. * @deprecated use av_image_get_buffer_size() instead.
  3393. */
  3394. attribute_deprecated
  3395. int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height);
  3396. /**
  3397. * @deprecated av_image_copy() instead.
  3398. */
  3399. attribute_deprecated
  3400. void av_picture_copy(AVPicture *dst, const AVPicture *src,
  3401. enum AVPixelFormat pix_fmt, int width, int height);
  3402. /**
  3403. * @deprecated unused
  3404. */
  3405. attribute_deprecated
  3406. int av_picture_crop(AVPicture *dst, const AVPicture *src,
  3407. enum AVPixelFormat pix_fmt, int top_band, int left_band);
  3408. /**
  3409. * @deprecated unused
  3410. */
  3411. attribute_deprecated
  3412. int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt,
  3413. int padtop, int padbottom, int padleft, int padright, int *color);
  3414. /**
  3415. * @}
  3416. */
  3417. #endif
  3418. /**
  3419. * @defgroup lavc_misc Utility functions
  3420. * @ingroup libavc
  3421. *
  3422. * Miscellaneous utility functions related to both encoding and decoding
  3423. * (or neither).
  3424. * @{
  3425. */
  3426. /**
  3427. * @defgroup lavc_misc_pixfmt Pixel formats
  3428. *
  3429. * Functions for working with pixel formats.
  3430. * @{
  3431. */
  3432. #if FF_API_GETCHROMA
  3433. /**
  3434. * @deprecated Use av_pix_fmt_get_chroma_sub_sample
  3435. */
  3436. attribute_deprecated
  3437. void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
  3438. #endif
  3439. /**
  3440. * Return a value representing the fourCC code associated to the
  3441. * pixel format pix_fmt, or 0 if no associated fourCC code can be
  3442. * found.
  3443. */
  3444. unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt);
  3445. /**
  3446. * @deprecated see av_get_pix_fmt_loss()
  3447. */
  3448. int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
  3449. int has_alpha);
  3450. /**
  3451. * Find the best pixel format to convert to given a certain source pixel
  3452. * format. When converting from one pixel format to another, information loss
  3453. * may occur. For example, when converting from RGB24 to GRAY, the color
  3454. * information will be lost. Similarly, other losses occur when converting from
  3455. * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches which of
  3456. * the given pixel formats should be used to suffer the least amount of loss.
  3457. * The pixel formats from which it chooses one, are determined by the
  3458. * pix_fmt_list parameter.
  3459. *
  3460. *
  3461. * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
  3462. * @param[in] src_pix_fmt source pixel format
  3463. * @param[in] has_alpha Whether the source pixel format alpha channel is used.
  3464. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
  3465. * @return The best pixel format to convert to or -1 if none was found.
  3466. */
  3467. enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *pix_fmt_list,
  3468. enum AVPixelFormat src_pix_fmt,
  3469. int has_alpha, int *loss_ptr);
  3470. /**
  3471. * @deprecated see av_find_best_pix_fmt_of_2()
  3472. */
  3473. enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
  3474. enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
  3475. attribute_deprecated
  3476. enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
  3477. enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
  3478. enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  3479. /**
  3480. * @}
  3481. */
  3482. #if FF_API_TAG_STRING
  3483. /**
  3484. * Put a string representing the codec tag codec_tag in buf.
  3485. *
  3486. * @param buf buffer to place codec tag in
  3487. * @param buf_size size in bytes of buf
  3488. * @param codec_tag codec tag to assign
  3489. * @return the length of the string that would have been generated if
  3490. * enough space had been available, excluding the trailing null
  3491. *
  3492. * @deprecated see av_fourcc_make_string() and av_fourcc2str().
  3493. */
  3494. attribute_deprecated
  3495. size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
  3496. #endif
  3497. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  3498. /**
  3499. * Return a name for the specified profile, if available.
  3500. *
  3501. * @param codec the codec that is searched for the given profile
  3502. * @param profile the profile value for which a name is requested
  3503. * @return A name for the profile if found, NULL otherwise.
  3504. */
  3505. const char *av_get_profile_name(const AVCodec *codec, int profile);
  3506. /**
  3507. * Return a name for the specified profile, if available.
  3508. *
  3509. * @param codec_id the ID of the codec to which the requested profile belongs
  3510. * @param profile the profile value for which a name is requested
  3511. * @return A name for the profile if found, NULL otherwise.
  3512. *
  3513. * @note unlike av_get_profile_name(), which searches a list of profiles
  3514. * supported by a specific decoder or encoder implementation, this
  3515. * function searches the list of profiles from the AVCodecDescriptor
  3516. */
  3517. const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
  3518. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
  3519. int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
  3520. //FIXME func typedef
  3521. /**
  3522. * Fill AVFrame audio data and linesize pointers.
  3523. *
  3524. * The buffer buf must be a preallocated buffer with a size big enough
  3525. * to contain the specified samples amount. The filled AVFrame data
  3526. * pointers will point to this buffer.
  3527. *
  3528. * AVFrame extended_data channel pointers are allocated if necessary for
  3529. * planar audio.
  3530. *
  3531. * @param frame the AVFrame
  3532. * frame->nb_samples must be set prior to calling the
  3533. * function. This function fills in frame->data,
  3534. * frame->extended_data, frame->linesize[0].
  3535. * @param nb_channels channel count
  3536. * @param sample_fmt sample format
  3537. * @param buf buffer to use for frame data
  3538. * @param buf_size size of buffer
  3539. * @param align plane size sample alignment (0 = default)
  3540. * @return >=0 on success, negative error code on failure
  3541. * @todo return the size in bytes required to store the samples in
  3542. * case of success, at the next libavutil bump
  3543. */
  3544. int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
  3545. enum AVSampleFormat sample_fmt, const uint8_t *buf,
  3546. int buf_size, int align);
  3547. /**
  3548. * Reset the internal codec state / flush internal buffers. Should be called
  3549. * e.g. when seeking or when switching to a different stream.
  3550. *
  3551. * @note for decoders, when refcounted frames are not used
  3552. * (i.e. avctx->refcounted_frames is 0), this invalidates the frames previously
  3553. * returned from the decoder. When refcounted frames are used, the decoder just
  3554. * releases any references it might keep internally, but the caller's reference
  3555. * remains valid.
  3556. *
  3557. * @note for encoders, this function will only do something if the encoder
  3558. * declares support for AV_CODEC_CAP_ENCODER_FLUSH. When called, the encoder
  3559. * will drain any remaining packets, and can then be re-used for a different
  3560. * stream (as opposed to sending a null frame which will leave the encoder
  3561. * in a permanent EOF state after draining). This can be desirable if the
  3562. * cost of tearing down and replacing the encoder instance is high.
  3563. */
  3564. void avcodec_flush_buffers(AVCodecContext *avctx);
  3565. /**
  3566. * Return codec bits per sample.
  3567. *
  3568. * @param[in] codec_id the codec
  3569. * @return Number of bits per sample or zero if unknown for the given codec.
  3570. */
  3571. int av_get_bits_per_sample(enum AVCodecID codec_id);
  3572. /**
  3573. * Return the PCM codec associated with a sample format.
  3574. * @param be endianness, 0 for little, 1 for big,
  3575. * -1 (or anything else) for native
  3576. * @return AV_CODEC_ID_PCM_* or AV_CODEC_ID_NONE
  3577. */
  3578. enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be);
  3579. /**
  3580. * Return codec bits per sample.
  3581. * Only return non-zero if the bits per sample is exactly correct, not an
  3582. * approximation.
  3583. *
  3584. * @param[in] codec_id the codec
  3585. * @return Number of bits per sample or zero if unknown for the given codec.
  3586. */
  3587. int av_get_exact_bits_per_sample(enum AVCodecID codec_id);
  3588. /**
  3589. * Return audio frame duration.
  3590. *
  3591. * @param avctx codec context
  3592. * @param frame_bytes size of the frame, or 0 if unknown
  3593. * @return frame duration, in samples, if known. 0 if not able to
  3594. * determine.
  3595. */
  3596. int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
  3597. /**
  3598. * This function is the same as av_get_audio_frame_duration(), except it works
  3599. * with AVCodecParameters instead of an AVCodecContext.
  3600. */
  3601. int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
  3602. #if FF_API_OLD_BSF
  3603. typedef struct AVBitStreamFilterContext {
  3604. void *priv_data;
  3605. const struct AVBitStreamFilter *filter;
  3606. AVCodecParserContext *parser;
  3607. struct AVBitStreamFilterContext *next;
  3608. /**
  3609. * Internal default arguments, used if NULL is passed to av_bitstream_filter_filter().
  3610. * Not for access by library users.
  3611. */
  3612. char *args;
  3613. } AVBitStreamFilterContext;
  3614. /**
  3615. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  3616. * is deprecated. Use the new bitstream filtering API (using AVBSFContext).
  3617. */
  3618. attribute_deprecated
  3619. void av_register_bitstream_filter(AVBitStreamFilter *bsf);
  3620. /**
  3621. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  3622. * is deprecated. Use av_bsf_get_by_name(), av_bsf_alloc(), and av_bsf_init()
  3623. * from the new bitstream filtering API (using AVBSFContext).
  3624. */
  3625. attribute_deprecated
  3626. AVBitStreamFilterContext *av_bitstream_filter_init(const char *name);
  3627. /**
  3628. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  3629. * is deprecated. Use av_bsf_send_packet() and av_bsf_receive_packet() from the
  3630. * new bitstream filtering API (using AVBSFContext).
  3631. */
  3632. attribute_deprecated
  3633. int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc,
  3634. AVCodecContext *avctx, const char *args,
  3635. uint8_t **poutbuf, int *poutbuf_size,
  3636. const uint8_t *buf, int buf_size, int keyframe);
  3637. /**
  3638. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  3639. * is deprecated. Use av_bsf_free() from the new bitstream filtering API (using
  3640. * AVBSFContext).
  3641. */
  3642. attribute_deprecated
  3643. void av_bitstream_filter_close(AVBitStreamFilterContext *bsf);
  3644. /**
  3645. * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
  3646. * is deprecated. Use av_bsf_iterate() from the new bitstream filtering API (using
  3647. * AVBSFContext).
  3648. */
  3649. attribute_deprecated
  3650. const AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f);
  3651. #endif
  3652. #if FF_API_NEXT
  3653. attribute_deprecated
  3654. const AVBitStreamFilter *av_bsf_next(void **opaque);
  3655. #endif
  3656. /* memory */
  3657. /**
  3658. * Same behaviour av_fast_malloc but the buffer has additional
  3659. * AV_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
  3660. *
  3661. * In addition the whole buffer will initially and after resizes
  3662. * be 0-initialized so that no uninitialized data will ever appear.
  3663. */
  3664. void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
  3665. /**
  3666. * Same behaviour av_fast_padded_malloc except that buffer will always
  3667. * be 0-initialized after call.
  3668. */
  3669. void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
  3670. /**
  3671. * Encode extradata length to a buffer. Used by xiph codecs.
  3672. *
  3673. * @param s buffer to write to; must be at least (v/255+1) bytes long
  3674. * @param v size of extradata in bytes
  3675. * @return number of bytes written to the buffer.
  3676. */
  3677. unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
  3678. #if FF_API_USER_VISIBLE_AVHWACCEL
  3679. /**
  3680. * Register the hardware accelerator hwaccel.
  3681. *
  3682. * @deprecated This function doesn't do anything.
  3683. */
  3684. attribute_deprecated
  3685. void av_register_hwaccel(AVHWAccel *hwaccel);
  3686. /**
  3687. * If hwaccel is NULL, returns the first registered hardware accelerator,
  3688. * if hwaccel is non-NULL, returns the next registered hardware accelerator
  3689. * after hwaccel, or NULL if hwaccel is the last one.
  3690. *
  3691. * @deprecated AVHWaccel structures contain no user-serviceable parts, so
  3692. * this function should not be used.
  3693. */
  3694. attribute_deprecated
  3695. AVHWAccel *av_hwaccel_next(const AVHWAccel *hwaccel);
  3696. #endif
  3697. #if FF_API_LOCKMGR
  3698. /**
  3699. * Lock operation used by lockmgr
  3700. *
  3701. * @deprecated Deprecated together with av_lockmgr_register().
  3702. */
  3703. enum AVLockOp {
  3704. AV_LOCK_CREATE, ///< Create a mutex
  3705. AV_LOCK_OBTAIN, ///< Lock the mutex
  3706. AV_LOCK_RELEASE, ///< Unlock the mutex
  3707. AV_LOCK_DESTROY, ///< Free mutex resources
  3708. };
  3709. /**
  3710. * Register a user provided lock manager supporting the operations
  3711. * specified by AVLockOp. The "mutex" argument to the function points
  3712. * to a (void *) where the lockmgr should store/get a pointer to a user
  3713. * allocated mutex. It is NULL upon AV_LOCK_CREATE and equal to the
  3714. * value left by the last call for all other ops. If the lock manager is
  3715. * unable to perform the op then it should leave the mutex in the same
  3716. * state as when it was called and return a non-zero value. However,
  3717. * when called with AV_LOCK_DESTROY the mutex will always be assumed to
  3718. * have been successfully destroyed. If av_lockmgr_register succeeds
  3719. * it will return a non-negative value, if it fails it will return a
  3720. * negative value and destroy all mutex and unregister all callbacks.
  3721. * av_lockmgr_register is not thread-safe, it must be called from a
  3722. * single thread before any calls which make use of locking are used.
  3723. *
  3724. * @param cb User defined callback. av_lockmgr_register invokes calls
  3725. * to this callback and the previously registered callback.
  3726. * The callback will be used to create more than one mutex
  3727. * each of which must be backed by its own underlying locking
  3728. * mechanism (i.e. do not use a single static object to
  3729. * implement your lock manager). If cb is set to NULL the
  3730. * lockmgr will be unregistered.
  3731. *
  3732. * @deprecated This function does nothing, and always returns 0. Be sure to
  3733. * build with thread support to get basic thread safety.
  3734. */
  3735. attribute_deprecated
  3736. int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
  3737. #endif
  3738. /**
  3739. * @return a positive value if s is open (i.e. avcodec_open2() was called on it
  3740. * with no corresponding avcodec_close()), 0 otherwise.
  3741. */
  3742. int avcodec_is_open(AVCodecContext *s);
  3743. /**
  3744. * Allocate a CPB properties structure and initialize its fields to default
  3745. * values.
  3746. *
  3747. * @param size if non-NULL, the size of the allocated struct will be written
  3748. * here. This is useful for embedding it in side data.
  3749. *
  3750. * @return the newly allocated struct or NULL on failure
  3751. */
  3752. AVCPBProperties *av_cpb_properties_alloc(size_t *size);
  3753. /**
  3754. * @}
  3755. */
  3756. #endif /* AVCODEC_AVCODEC_H */