avcodec.h 111 KB

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