avcodec.h 111 KB

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