avcodec.h 175 KB

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