在上文FFmpeg 结构体学习(五): AVCodec 分析我们学习了AVCodec结构体的相关内容。本文,我们将讲述一下AVCodecContext。

AVCodecContext是包含变量较多的结构体(感觉差不多是变量最多的结构体)。下面我们来分析一下该结构体里重要变量的含义和作用。

一、源码整理

首先我们先看一下结构体AVCodecContext的定义的结构体源码(位于libavcodec/avcodec.h):

  1. /**
  2. * main external API structure.
  3. * New fields can be added to the end with minor version bumps.
  4. * Removal, reordering and changes to existing fields require a major
  5. * version bump.
  6. * Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user
  7. * applications.
  8. * sizeof(AVCodecContext) must not be used outside libav*.
  9. */
  10. typedef struct AVCodecContext {
  11. /**
  12. * information on struct for av_log
  13. * - set by avcodec_alloc_context3
  14. */
  15. const AVClass *av_class;
  16. int log_level_offset;
  17.  
  18. enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
  19. const struct AVCodec *codec;
  20. char codec_name[];
  21. enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
  22.  
  23. /**
  24. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  25. * This is used to work around some encoder bugs.
  26. * A demuxer should set this to what is stored in the field used to identify the codec.
  27. * If there are multiple such fields in a container then the demuxer should choose the one
  28. * which maximizes the information about the used codec.
  29. * If the codec tag field in a container is larger than 32 bits then the demuxer should
  30. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  31. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  32. * first.
  33. * - encoding: Set by user, if not then the default based on codec_id will be used.
  34. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  35. */
  36. unsigned int codec_tag;
  37.  
  38. /**
  39. * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  40. * This is used to work around some encoder bugs.
  41. * - encoding: unused
  42. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  43. */
  44. unsigned int stream_codec_tag;
  45.  
  46. #if FF_API_SUB_ID
  47. /**
  48. * @deprecated this field is unused
  49. */
  50. attribute_deprecated int sub_id;
  51. #endif
  52.  
  53. void *priv_data;
  54.  
  55. /**
  56. * Private context used for internal data.
  57. *
  58. * Unlike priv_data, this is not codec-specific. It is used in general
  59. * libavcodec functions.
  60. */
  61. struct AVCodecInternal *internal;
  62.  
  63. /**
  64. * Private data of the user, can be used to carry app specific stuff.
  65. * - encoding: Set by user.
  66. * - decoding: Set by user.
  67. */
  68. void *opaque;
  69.  
  70. /**
  71. * the average bitrate
  72. * - encoding: Set by user; unused for constant quantizer encoding.
  73. * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
  74. */
  75. int bit_rate;
  76.  
  77. /**
  78. * number of bits the bitstream is allowed to diverge from the reference.
  79. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  80. * - encoding: Set by user; unused for constant quantizer encoding.
  81. * - decoding: unused
  82. */
  83. int bit_rate_tolerance;
  84.  
  85. /**
  86. * Global quality for codecs which cannot change it per frame.
  87. * This should be proportional to MPEG-1/2/4 qscale.
  88. * - encoding: Set by user.
  89. * - decoding: unused
  90. */
  91. int global_quality;
  92.  
  93. /**
  94. * - encoding: Set by user.
  95. * - decoding: unused
  96. */
  97. int compression_level;
  98. #define FF_COMPRESSION_DEFAULT -1
  99.  
  100. /**
  101. * CODEC_FLAG_*.
  102. * - encoding: Set by user.
  103. * - decoding: Set by user.
  104. */
  105. int flags;
  106.  
  107. /**
  108. * CODEC_FLAG2_*
  109. * - encoding: Set by user.
  110. * - decoding: Set by user.
  111. */
  112. int flags2;
  113.  
  114. /**
  115. * some codecs need / can use extradata like Huffman tables.
  116. * mjpeg: Huffman tables
  117. * rv10: additional flags
  118. * mpeg4: global headers (they can be in the bitstream or here)
  119. * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
  120. * than extradata_size to avoid prolems if it is read with the bitstream reader.
  121. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  122. * - encoding: Set/allocated/freed by libavcodec.
  123. * - decoding: Set/allocated/freed by user.
  124. */
  125. uint8_t *extradata;
  126. int extradata_size;
  127.  
  128. /**
  129. * This is the fundamental unit of time (in seconds) in terms
  130. * of which frame timestamps are represented. For fixed-fps content,
  131. * timebase should be 1/framerate and timestamp increments should be
  132. * identically 1.
  133. * - encoding: MUST be set by user.
  134. * - decoding: Set by libavcodec.
  135. */
  136. AVRational time_base;
  137.  
  138. /**
  139. * For some codecs, the time base is closer to the field rate than the frame rate.
  140. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
  141. * if no telecine is used ...
  142. *
  143. * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
  144. */
  145. int ticks_per_frame;
  146.  
  147. /**
  148. * Encoding: Number of frames delay there will be from the encoder input to
  149. * the decoder output. (we assume the decoder matches the spec)
  150. * Decoding: Number of frames delay in addition to what a standard decoder
  151. * as specified in the spec would produce.
  152. *
  153. * Video:
  154. * Number of frames the decoded output will be delayed relative to the
  155. * encoded input.
  156. *
  157. * Audio:
  158. * For encoding, this is the number of "priming" samples added to the
  159. * beginning of the stream. The decoded output will be delayed by this
  160. * many samples relative to the input to the encoder. Note that this
  161. * field is purely informational and does not directly affect the pts
  162. * output by the encoder, which should always be based on the actual
  163. * presentation time, including any delay.
  164. * For decoding, this is the number of samples the decoder needs to
  165. * output before the decoder's output is valid. When seeking, you should
  166. * start decoding this many samples prior to your desired seek point.
  167. *
  168. * - encoding: Set by libavcodec.
  169. * - decoding: Set by libavcodec.
  170. */
  171. int delay;
  172.  
  173. /* video only */
  174. /**
  175. * picture width / height.
  176. * - encoding: MUST be set by user.
  177. * - decoding: Set by libavcodec.
  178. * Note: For compatibility it is possible to set this instead of
  179. * coded_width/height before decoding.
  180. */
  181. int width, height;
  182.  
  183. /**
  184. * Bitstream width / height, may be different from width/height if lowres enabled.
  185. * - encoding: unused
  186. * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
  187. */
  188. int coded_width, coded_height;
  189.  
  190. #define FF_ASPECT_EXTENDED 15
  191.  
  192. /**
  193. * the number of pictures in a group of pictures, or 0 for intra_only
  194. * - encoding: Set by user.
  195. * - decoding: unused
  196. */
  197. int gop_size;
  198.  
  199. /**
  200. * Pixel format, see AV_PIX_FMT_xxx.
  201. * May be set by the demuxer if known from headers.
  202. * May be overridden by the decoder if it knows better.
  203. * - encoding: Set by user.
  204. * - decoding: Set by user if known, overridden by libavcodec if known
  205. */
  206. enum AVPixelFormat pix_fmt;
  207.  
  208. /**
  209. * Motion estimation algorithm used for video coding.
  210. * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
  211. * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
  212. * - encoding: MUST be set by user.
  213. * - decoding: unused
  214. */
  215. int me_method;
  216.  
  217. /**
  218. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  219. * decoder to draw a horizontal band. It improves cache usage. Not
  220. * all codecs can do that. You must check the codec capabilities
  221. * beforehand.
  222. * When multithreading is used, it may be called from multiple threads
  223. * at the same time; threads might draw different parts of the same AVFrame,
  224. * or multiple AVFrames, and there is no guarantee that slices will be drawn
  225. * in order.
  226. * The function is also used by hardware acceleration APIs.
  227. * It is called at least once during frame decoding to pass
  228. * the data needed for hardware render.
  229. * In that mode instead of pixel data, AVFrame points to
  230. * a structure specific to the acceleration API. The application
  231. * reads the structure and can change some fields to indicate progress
  232. * or mark state.
  233. * - encoding: unused
  234. * - decoding: Set by user.
  235. * @param height the height of the slice
  236. * @param y the y position of the slice
  237. * @param type 1->top field, 2->bottom field, 3->frame
  238. * @param offset offset into the AVFrame.data from which the slice should be read
  239. */
  240. void (*draw_horiz_band)(struct AVCodecContext *s,
  241. const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
  242. int y, int type, int height);
  243.  
  244. /**
  245. * callback to negotiate the pixelFormat
  246. * @param fmt is the list of formats which are supported by the codec,
  247. * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
  248. * The first is always the native one.
  249. * @return the chosen format
  250. * - encoding: unused
  251. * - decoding: Set by user, if not set the native format will be chosen.
  252. */
  253. enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
  254.  
  255. /**
  256. * maximum number of B-frames between non-B-frames
  257. * Note: The output will be delayed by max_b_frames+1 relative to the input.
  258. * - encoding: Set by user.
  259. * - decoding: unused
  260. */
  261. int max_b_frames;
  262.  
  263. /**
  264. * qscale factor between IP and B-frames
  265. * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
  266. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  267. * - encoding: Set by user.
  268. * - decoding: unused
  269. */
  270. float b_quant_factor;
  271.  
  272. /** obsolete FIXME remove */
  273. int rc_strategy;
  274. #define FF_RC_STRATEGY_XVID 1
  275.  
  276. int b_frame_strategy;
  277.  
  278. #if FF_API_MPV_GLOBAL_OPTS
  279. /**
  280. * luma single coefficient elimination threshold
  281. * - encoding: Set by user.
  282. * - decoding: unused
  283. */
  284. attribute_deprecated int luma_elim_threshold;
  285.  
  286. /**
  287. * chroma single coeff elimination threshold
  288. * - encoding: Set by user.
  289. * - decoding: unused
  290. */
  291. attribute_deprecated int chroma_elim_threshold;
  292. #endif
  293.  
  294. /**
  295. * qscale offset between IP and B-frames
  296. * - encoding: Set by user.
  297. * - decoding: unused
  298. */
  299. float b_quant_offset;
  300.  
  301. /**
  302. * Size of the frame reordering buffer in the decoder.
  303. * For MPEG-2 it is 1 IPB or 0 low delay IP.
  304. * - encoding: Set by libavcodec.
  305. * - decoding: Set by libavcodec.
  306. */
  307. int has_b_frames;
  308.  
  309. /**
  310. * 0-> h263 quant 1-> mpeg quant
  311. * - encoding: Set by user.
  312. * - decoding: unused
  313. */
  314. int mpeg_quant;
  315.  
  316. /**
  317. * qscale factor between P and I-frames
  318. * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
  319. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  320. * - encoding: Set by user.
  321. * - decoding: unused
  322. */
  323. float i_quant_factor;
  324.  
  325. /**
  326. * qscale offset between P and I-frames
  327. * - encoding: Set by user.
  328. * - decoding: unused
  329. */
  330. float i_quant_offset;
  331.  
  332. /**
  333. * luminance masking (0-> disabled)
  334. * - encoding: Set by user.
  335. * - decoding: unused
  336. */
  337. float lumi_masking;
  338.  
  339. /**
  340. * temporary complexity masking (0-> disabled)
  341. * - encoding: Set by user.
  342. * - decoding: unused
  343. */
  344. float temporal_cplx_masking;
  345.  
  346. /**
  347. * spatial complexity masking (0-> disabled)
  348. * - encoding: Set by user.
  349. * - decoding: unused
  350. */
  351. float spatial_cplx_masking;
  352.  
  353. /**
  354. * p block masking (0-> disabled)
  355. * - encoding: Set by user.
  356. * - decoding: unused
  357. */
  358. float p_masking;
  359.  
  360. /**
  361. * darkness masking (0-> disabled)
  362. * - encoding: Set by user.
  363. * - decoding: unused
  364. */
  365. float dark_masking;
  366.  
  367. /**
  368. * slice count
  369. * - encoding: Set by libavcodec.
  370. * - decoding: Set by user (or 0).
  371. */
  372. int slice_count;
  373. /**
  374. * prediction method (needed for huffyuv)
  375. * - encoding: Set by user.
  376. * - decoding: unused
  377. */
  378. int prediction_method;
  379. #define FF_PRED_LEFT 0
  380. #define FF_PRED_PLANE 1
  381. #define FF_PRED_MEDIAN 2
  382.  
  383. /**
  384. * slice offsets in the frame in bytes
  385. * - encoding: Set/allocated by libavcodec.
  386. * - decoding: Set/allocated by user (or NULL).
  387. */
  388. int *slice_offset;
  389.  
  390. /**
  391. * sample aspect ratio (0 if unknown)
  392. * That is the width of a pixel divided by the height of the pixel.
  393. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  394. * - encoding: Set by user.
  395. * - decoding: Set by libavcodec.
  396. */
  397. AVRational sample_aspect_ratio;
  398.  
  399. /**
  400. * motion estimation comparison function
  401. * - encoding: Set by user.
  402. * - decoding: unused
  403. */
  404. int me_cmp;
  405. /**
  406. * subpixel motion estimation comparison function
  407. * - encoding: Set by user.
  408. * - decoding: unused
  409. */
  410. int me_sub_cmp;
  411. /**
  412. * macroblock comparison function (not supported yet)
  413. * - encoding: Set by user.
  414. * - decoding: unused
  415. */
  416. int mb_cmp;
  417. /**
  418. * interlaced DCT comparison function
  419. * - encoding: Set by user.
  420. * - decoding: unused
  421. */
  422. int ildct_cmp;
  423. #define FF_CMP_SAD 0
  424. #define FF_CMP_SSE 1
  425. #define FF_CMP_SATD 2
  426. #define FF_CMP_DCT 3
  427. #define FF_CMP_PSNR 4
  428. #define FF_CMP_BIT 5
  429. #define FF_CMP_RD 6
  430. #define FF_CMP_ZERO 7
  431. #define FF_CMP_VSAD 8
  432. #define FF_CMP_VSSE 9
  433. #define FF_CMP_NSSE 10
  434. #define FF_CMP_W53 11
  435. #define FF_CMP_W97 12
  436. #define FF_CMP_DCTMAX 13
  437. #define FF_CMP_DCT264 14
  438. #define FF_CMP_CHROMA 256
  439.  
  440. /**
  441. * ME diamond size & shape
  442. * - encoding: Set by user.
  443. * - decoding: unused
  444. */
  445. int dia_size;
  446.  
  447. /**
  448. * amount of previous MV predictors (2a+1 x 2a+1 square)
  449. * - encoding: Set by user.
  450. * - decoding: unused
  451. */
  452. int last_predictor_count;
  453.  
  454. /**
  455. * prepass for motion estimation
  456. * - encoding: Set by user.
  457. * - decoding: unused
  458. */
  459. int pre_me;
  460.  
  461. /**
  462. * motion estimation prepass comparison function
  463. * - encoding: Set by user.
  464. * - decoding: unused
  465. */
  466. int me_pre_cmp;
  467.  
  468. /**
  469. * ME prepass diamond size & shape
  470. * - encoding: Set by user.
  471. * - decoding: unused
  472. */
  473. int pre_dia_size;
  474.  
  475. /**
  476. * subpel ME quality
  477. * - encoding: Set by user.
  478. * - decoding: unused
  479. */
  480. int me_subpel_quality;
  481.  
  482. /**
  483. * DTG active format information (additional aspect ratio
  484. * information only used in DVB MPEG-2 transport streams)
  485. * 0 if not set.
  486. *
  487. * - encoding: unused
  488. * - decoding: Set by decoder.
  489. */
  490. int dtg_active_format;
  491. #define FF_DTG_AFD_SAME 8
  492. #define FF_DTG_AFD_4_3 9
  493. #define FF_DTG_AFD_16_9 10
  494. #define FF_DTG_AFD_14_9 11
  495. #define FF_DTG_AFD_4_3_SP_14_9 13
  496. #define FF_DTG_AFD_16_9_SP_14_9 14
  497. #define FF_DTG_AFD_SP_4_3 15
  498.  
  499. /**
  500. * maximum motion estimation search range in subpel units
  501. * If 0 then no limit.
  502. *
  503. * - encoding: Set by user.
  504. * - decoding: unused
  505. */
  506. int me_range;
  507.  
  508. /**
  509. * intra quantizer bias
  510. * - encoding: Set by user.
  511. * - decoding: unused
  512. */
  513. int intra_quant_bias;
  514. #define FF_DEFAULT_QUANT_BIAS 999999
  515.  
  516. /**
  517. * inter quantizer bias
  518. * - encoding: Set by user.
  519. * - decoding: unused
  520. */
  521. int inter_quant_bias;
  522.  
  523. #if FF_API_COLOR_TABLE_ID
  524. /**
  525. * color table ID
  526. * - encoding: unused
  527. * - decoding: Which clrtable should be used for 8bit RGB images.
  528. * Tables have to be stored somewhere. FIXME
  529. */
  530. attribute_deprecated int color_table_id;
  531. #endif
  532.  
  533. /**
  534. * slice flags
  535. * - encoding: unused
  536. * - decoding: Set by user.
  537. */
  538. int slice_flags;
  539. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  540. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
  541. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  542.  
  543. /**
  544. * XVideo Motion Acceleration
  545. * - encoding: forbidden
  546. * - decoding: set by decoder
  547. */
  548. int xvmc_acceleration;
  549.  
  550. /**
  551. * macroblock decision mode
  552. * - encoding: Set by user.
  553. * - decoding: unused
  554. */
  555. int mb_decision;
  556. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  557. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  558. #define FF_MB_DECISION_RD 2 ///< rate distortion
  559.  
  560. /**
  561. * custom intra quantization matrix
  562. * - encoding: Set by user, can be NULL.
  563. * - decoding: Set by libavcodec.
  564. */
  565. uint16_t *intra_matrix;
  566.  
  567. /**
  568. * custom inter quantization matrix
  569. * - encoding: Set by user, can be NULL.
  570. * - decoding: Set by libavcodec.
  571. */
  572. uint16_t *inter_matrix;
  573.  
  574. /**
  575. * scene change detection threshold
  576. * 0 is default, larger means fewer detected scene changes.
  577. * - encoding: Set by user.
  578. * - decoding: unused
  579. */
  580. int scenechange_threshold;
  581.  
  582. /**
  583. * noise reduction strength
  584. * - encoding: Set by user.
  585. * - decoding: unused
  586. */
  587. int noise_reduction;
  588.  
  589. #if FF_API_INTER_THRESHOLD
  590. /**
  591. * @deprecated this field is unused
  592. */
  593. attribute_deprecated int inter_threshold;
  594. #endif
  595.  
  596. #if FF_API_MPV_GLOBAL_OPTS
  597. /**
  598. * @deprecated use mpegvideo private options instead
  599. */
  600. attribute_deprecated int quantizer_noise_shaping;
  601. #endif
  602.  
  603. /**
  604. * Motion estimation threshold below which no motion estimation is
  605. * performed, but instead the user specified motion vectors are used.
  606. *
  607. * - encoding: Set by user.
  608. * - decoding: unused
  609. */
  610. int me_threshold;
  611.  
  612. /**
  613. * Macroblock threshold below which the user specified macroblock types will be used.
  614. * - encoding: Set by user.
  615. * - decoding: unused
  616. */
  617. int mb_threshold;
  618.  
  619. /**
  620. * precision of the intra DC coefficient - 8
  621. * - encoding: Set by user.
  622. * - decoding: unused
  623. */
  624. int intra_dc_precision;
  625.  
  626. /**
  627. * Number of macroblock rows at the top which are skipped.
  628. * - encoding: unused
  629. * - decoding: Set by user.
  630. */
  631. int skip_top;
  632.  
  633. /**
  634. * Number of macroblock rows at the bottom which are skipped.
  635. * - encoding: unused
  636. * - decoding: Set by user.
  637. */
  638. int skip_bottom;
  639.  
  640. /**
  641. * Border processing masking, raises the quantizer for mbs on the borders
  642. * of the picture.
  643. * - encoding: Set by user.
  644. * - decoding: unused
  645. */
  646. float border_masking;
  647.  
  648. /**
  649. * minimum MB lagrange multipler
  650. * - encoding: Set by user.
  651. * - decoding: unused
  652. */
  653. int mb_lmin;
  654.  
  655. /**
  656. * maximum MB lagrange multipler
  657. * - encoding: Set by user.
  658. * - decoding: unused
  659. */
  660. int mb_lmax;
  661.  
  662. /**
  663. *
  664. * - encoding: Set by user.
  665. * - decoding: unused
  666. */
  667. int me_penalty_compensation;
  668.  
  669. /**
  670. *
  671. * - encoding: Set by user.
  672. * - decoding: unused
  673. */
  674. int bidir_refine;
  675.  
  676. /**
  677. *
  678. * - encoding: Set by user.
  679. * - decoding: unused
  680. */
  681. int brd_scale;
  682.  
  683. /**
  684. * minimum GOP size
  685. * - encoding: Set by user.
  686. * - decoding: unused
  687. */
  688. int keyint_min;
  689.  
  690. /**
  691. * number of reference frames
  692. * - encoding: Set by user.
  693. * - decoding: Set by lavc.
  694. */
  695. int refs;
  696.  
  697. /**
  698. * chroma qp offset from luma
  699. * - encoding: Set by user.
  700. * - decoding: unused
  701. */
  702. int chromaoffset;
  703.  
  704. /**
  705. * Multiplied by qscale for each frame and added to scene_change_score.
  706. * - encoding: Set by user.
  707. * - decoding: unused
  708. */
  709. int scenechange_factor;
  710.  
  711. /**
  712. *
  713. * Note: Value depends upon the compare function used for fullpel ME.
  714. * - encoding: Set by user.
  715. * - decoding: unused
  716. */
  717. int mv0_threshold;
  718.  
  719. /**
  720. * Adjust sensitivity of b_frame_strategy 1.
  721. * - encoding: Set by user.
  722. * - decoding: unused
  723. */
  724. int b_sensitivity;
  725.  
  726. /**
  727. * Chromaticity coordinates of the source primaries.
  728. * - encoding: Set by user
  729. * - decoding: Set by libavcodec
  730. */
  731. enum AVColorPrimaries color_primaries;
  732.  
  733. /**
  734. * Color Transfer Characteristic.
  735. * - encoding: Set by user
  736. * - decoding: Set by libavcodec
  737. */
  738. enum AVColorTransferCharacteristic color_trc;
  739.  
  740. /**
  741. * YUV colorspace type.
  742. * - encoding: Set by user
  743. * - decoding: Set by libavcodec
  744. */
  745. enum AVColorSpace colorspace;
  746.  
  747. /**
  748. * MPEG vs JPEG YUV range.
  749. * - encoding: Set by user
  750. * - decoding: Set by libavcodec
  751. */
  752. enum AVColorRange color_range;
  753.  
  754. /**
  755. * This defines the location of chroma samples.
  756. * - encoding: Set by user
  757. * - decoding: Set by libavcodec
  758. */
  759. enum AVChromaLocation chroma_sample_location;
  760.  
  761. /**
  762. * Number of slices.
  763. * Indicates number of picture subdivisions. Used for parallelized
  764. * decoding.
  765. * - encoding: Set by user
  766. * - decoding: unused
  767. */
  768. int slices;
  769.  
  770. /** Field order
  771. * - encoding: set by libavcodec
  772. * - decoding: Set by user.
  773. */
  774. enum AVFieldOrder field_order;
  775.  
  776. /* audio only */
  777. int sample_rate; ///< samples per second
  778. int channels; ///< number of audio channels
  779.  
  780. /**
  781. * audio sample format
  782. * - encoding: Set by user.
  783. * - decoding: Set by libavcodec.
  784. */
  785. enum AVSampleFormat sample_fmt; ///< sample format
  786.  
  787. /* The following data should not be initialized. */
  788. /**
  789. * Samples per packet, initialized when calling 'init'.
  790. */
  791. int frame_size;
  792.  
  793. /**
  794. * Frame counter, set by libavcodec.
  795. *
  796. * - decoding: total number of frames returned from the decoder so far.
  797. * - encoding: total number of frames passed to the encoder so far.
  798. *
  799. * @note the counter is not incremented if encoding/decoding resulted in
  800. * an error.
  801. */
  802. int frame_number;
  803.  
  804. /**
  805. * number of bytes per packet if constant and known or 0
  806. * Used by some WAV based audio codecs.
  807. */
  808. int block_align;
  809.  
  810. /**
  811. * Audio cutoff bandwidth (0 means "automatic")
  812. * - encoding: Set by user.
  813. * - decoding: unused
  814. */
  815. int cutoff;
  816.  
  817. #if FF_API_REQUEST_CHANNELS
  818. /**
  819. * Decoder should decode to this many channels if it can (0 for default)
  820. * - encoding: unused
  821. * - decoding: Set by user.
  822. * @deprecated Deprecated in favor of request_channel_layout.
  823. */
  824. int request_channels;
  825. #endif
  826.  
  827. /**
  828. * Audio channel layout.
  829. * - encoding: set by user.
  830. * - decoding: set by user, may be overwritten by libavcodec.
  831. */
  832. uint64_t channel_layout;
  833.  
  834. /**
  835. * Request decoder to use this channel layout if it can (0 for default)
  836. * - encoding: unused
  837. * - decoding: Set by user.
  838. */
  839. uint64_t request_channel_layout;
  840.  
  841. /**
  842. * Type of service that the audio stream conveys.
  843. * - encoding: Set by user.
  844. * - decoding: Set by libavcodec.
  845. */
  846. enum AVAudioServiceType audio_service_type;
  847.  
  848. /**
  849. * desired sample format
  850. * - encoding: Not used.
  851. * - decoding: Set by user.
  852. * Decoder will decode to this format if it can.
  853. */
  854. enum AVSampleFormat request_sample_fmt;
  855.  
  856. /**
  857. * Called at the beginning of each frame to get a buffer for it.
  858. *
  859. * The function will set AVFrame.data[], AVFrame.linesize[].
  860. * AVFrame.extended_data[] must also be set, but it should be the same as
  861. * AVFrame.data[] except for planar audio with more channels than can fit
  862. * in AVFrame.data[]. In that case, AVFrame.data[] shall still contain as
  863. * many data pointers as it can hold.
  864. *
  865. * if CODEC_CAP_DR1 is not set then get_buffer() must call
  866. * avcodec_default_get_buffer() instead of providing buffers allocated by
  867. * some other means.
  868. *
  869. * AVFrame.data[] should be 32- or 16-byte-aligned unless the CPU doesn't
  870. * need it. avcodec_default_get_buffer() aligns the output buffer properly,
  871. * but if get_buffer() is overridden then alignment considerations should
  872. * be taken into account.
  873. *
  874. * @see avcodec_default_get_buffer()
  875. *
  876. * Video:
  877. *
  878. * If pic.reference is set then the frame will be read later by libavcodec.
  879. * avcodec_align_dimensions2() should be used to find the required width and
  880. * height, as they normally need to be rounded up to the next multiple of 16.
  881. *
  882. * If frame multithreading is used and thread_safe_callbacks is set,
  883. * it may be called from a different thread, but not from more than one at
  884. * once. Does not need to be reentrant.
  885. *
  886. * @see release_buffer(), reget_buffer()
  887. * @see avcodec_align_dimensions2()
  888. *
  889. * Audio:
  890. *
  891. * Decoders request a buffer of a particular size by setting
  892. * AVFrame.nb_samples prior to calling get_buffer(). The decoder may,
  893. * however, utilize only part of the buffer by setting AVFrame.nb_samples
  894. * to a smaller value in the output frame.
  895. *
  896. * Decoders cannot use the buffer after returning from
  897. * avcodec_decode_audio4(), so they will not call release_buffer(), as it
  898. * is assumed to be released immediately upon return.
  899. *
  900. * As a convenience, av_samples_get_buffer_size() and
  901. * av_samples_fill_arrays() in libavutil may be used by custom get_buffer()
  902. * functions to find the required data size and to fill data pointers and
  903. * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
  904. * since all planes must be the same size.
  905. *
  906. * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
  907. *
  908. * - encoding: unused
  909. * - decoding: Set by libavcodec, user can override.
  910. */
  911. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  912.  
  913. /**
  914. * Called to release buffers which were allocated with get_buffer.
  915. * A released buffer can be reused in get_buffer().
  916. * pic.data[*] must be set to NULL.
  917. * May be called from a different thread if frame multithreading is used,
  918. * but not by more than one thread at once, so does not need to be reentrant.
  919. * - encoding: unused
  920. * - decoding: Set by libavcodec, user can override.
  921. */
  922. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  923.  
  924. /**
  925. * Called at the beginning of a frame to get cr buffer for it.
  926. * Buffer type (size, hints) must be the same. libavcodec won't check it.
  927. * libavcodec will pass previous buffer in pic, function should return
  928. * same buffer or new buffer with old frame "painted" into it.
  929. * If pic.data[0] == NULL must behave like get_buffer().
  930. * if CODEC_CAP_DR1 is not set then reget_buffer() must call
  931. * avcodec_default_reget_buffer() instead of providing buffers allocated by
  932. * some other means.
  933. * - encoding: unused
  934. * - decoding: Set by libavcodec, user can override.
  935. */
  936. int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
  937.  
  938. /* - encoding parameters */
  939. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  940. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  941.  
  942. /**
  943. * minimum quantizer
  944. * - encoding: Set by user.
  945. * - decoding: unused
  946. */
  947. int qmin;
  948.  
  949. /**
  950. * maximum quantizer
  951. * - encoding: Set by user.
  952. * - decoding: unused
  953. */
  954. int qmax;
  955.  
  956. /**
  957. * maximum quantizer difference between frames
  958. * - encoding: Set by user.
  959. * - decoding: unused
  960. */
  961. int max_qdiff;
  962.  
  963. /**
  964. * ratecontrol qmin qmax limiting method
  965. * 0-> clipping, 1-> use a nice continuous function to limit qscale wthin qmin/qmax.
  966. * - encoding: Set by user.
  967. * - decoding: unused
  968. */
  969. float rc_qsquish;
  970.  
  971. float rc_qmod_amp;
  972. int rc_qmod_freq;
  973.  
  974. /**
  975. * decoder bitstream buffer size
  976. * - encoding: Set by user.
  977. * - decoding: unused
  978. */
  979. int rc_buffer_size;
  980.  
  981. /**
  982. * ratecontrol override, see RcOverride
  983. * - encoding: Allocated/set/freed by user.
  984. * - decoding: unused
  985. */
  986. int rc_override_count;
  987. RcOverride *rc_override;
  988.  
  989. /**
  990. * rate control equation
  991. * - encoding: Set by user
  992. * - decoding: unused
  993. */
  994. const char *rc_eq;
  995.  
  996. /**
  997. * maximum bitrate
  998. * - encoding: Set by user.
  999. * - decoding: unused
  1000. */
  1001. int rc_max_rate;
  1002.  
  1003. /**
  1004. * minimum bitrate
  1005. * - encoding: Set by user.
  1006. * - decoding: unused
  1007. */
  1008. int rc_min_rate;
  1009.  
  1010. float rc_buffer_aggressivity;
  1011.  
  1012. /**
  1013. * initial complexity for pass1 ratecontrol
  1014. * - encoding: Set by user.
  1015. * - decoding: unused
  1016. */
  1017. float rc_initial_cplx;
  1018.  
  1019. /**
  1020. * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
  1021. * - encoding: Set by user.
  1022. * - decoding: unused.
  1023. */
  1024. float rc_max_available_vbv_use;
  1025.  
  1026. /**
  1027. * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
  1028. * - encoding: Set by user.
  1029. * - decoding: unused.
  1030. */
  1031. float rc_min_vbv_overflow_use;
  1032.  
  1033. /**
  1034. * Number of bits which should be loaded into the rc buffer before decoding starts.
  1035. * - encoding: Set by user.
  1036. * - decoding: unused
  1037. */
  1038. int rc_initial_buffer_occupancy;
  1039.  
  1040. #define FF_CODER_TYPE_VLC 0
  1041. #define FF_CODER_TYPE_AC 1
  1042. #define FF_CODER_TYPE_RAW 2
  1043. #define FF_CODER_TYPE_RLE 3
  1044. #define FF_CODER_TYPE_DEFLATE 4
  1045. /**
  1046. * coder type
  1047. * - encoding: Set by user.
  1048. * - decoding: unused
  1049. */
  1050. int coder_type;
  1051.  
  1052. /**
  1053. * context model
  1054. * - encoding: Set by user.
  1055. * - decoding: unused
  1056. */
  1057. int context_model;
  1058.  
  1059. /**
  1060. * minimum Lagrange multipler
  1061. * - encoding: Set by user.
  1062. * - decoding: unused
  1063. */
  1064. int lmin;
  1065.  
  1066. /**
  1067. * maximum Lagrange multipler
  1068. * - encoding: Set by user.
  1069. * - decoding: unused
  1070. */
  1071. int lmax;
  1072.  
  1073. /**
  1074. * frame skip threshold
  1075. * - encoding: Set by user.
  1076. * - decoding: unused
  1077. */
  1078. int frame_skip_threshold;
  1079.  
  1080. /**
  1081. * frame skip factor
  1082. * - encoding: Set by user.
  1083. * - decoding: unused
  1084. */
  1085. int frame_skip_factor;
  1086.  
  1087. /**
  1088. * frame skip exponent
  1089. * - encoding: Set by user.
  1090. * - decoding: unused
  1091. */
  1092. int frame_skip_exp;
  1093.  
  1094. /**
  1095. * frame skip comparison function
  1096. * - encoding: Set by user.
  1097. * - decoding: unused
  1098. */
  1099. int frame_skip_cmp;
  1100.  
  1101. /**
  1102. * trellis RD quantization
  1103. * - encoding: Set by user.
  1104. * - decoding: unused
  1105. */
  1106. int trellis;
  1107.  
  1108. /**
  1109. * - encoding: Set by user.
  1110. * - decoding: unused
  1111. */
  1112. int min_prediction_order;
  1113.  
  1114. /**
  1115. * - encoding: Set by user.
  1116. * - decoding: unused
  1117. */
  1118. int max_prediction_order;
  1119.  
  1120. /**
  1121. * GOP timecode frame start number
  1122. * - encoding: Set by user, in non drop frame format
  1123. * - decoding: Set by libavcodec (timecode in the 25 bits format, -1 if unset)
  1124. */
  1125. int64_t timecode_frame_start;
  1126.  
  1127. /* The RTP callback: This function is called */
  1128. /* every time the encoder has a packet to send. */
  1129. /* It depends on the encoder if the data starts */
  1130. /* with a Start Code (it should). H.263 does. */
  1131. /* mb_nb contains the number of macroblocks */
  1132. /* encoded in the RTP payload. */
  1133. void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
  1134.  
  1135. int rtp_payload_size; /* The size of the RTP payload: the coder will */
  1136. /* do its best to deliver a chunk with size */
  1137. /* below rtp_payload_size, the chunk will start */
  1138. /* with a start code on some codecs like H.263. */
  1139. /* This doesn't take account of any particular */
  1140. /* headers inside the transmitted RTP payload. */
  1141.  
  1142. /* statistics, used for 2-pass encoding */
  1143. int mv_bits;
  1144. int header_bits;
  1145. int i_tex_bits;
  1146. int p_tex_bits;
  1147. int i_count;
  1148. int p_count;
  1149. int skip_count;
  1150. int misc_bits;
  1151.  
  1152. /**
  1153. * number of bits used for the previously encoded frame
  1154. * - encoding: Set by libavcodec.
  1155. * - decoding: unused
  1156. */
  1157. int frame_bits;
  1158.  
  1159. /**
  1160. * pass1 encoding statistics output buffer
  1161. * - encoding: Set by libavcodec.
  1162. * - decoding: unused
  1163. */
  1164. char *stats_out;
  1165.  
  1166. /**
  1167. * pass2 encoding statistics input buffer
  1168. * Concatenated stuff from stats_out of pass1 should be placed here.
  1169. * - encoding: Allocated/set/freed by user.
  1170. * - decoding: unused
  1171. */
  1172. char *stats_in;
  1173.  
  1174. /**
  1175. * Work around bugs in encoders which sometimes cannot be detected automatically.
  1176. * - encoding: Set by user
  1177. * - decoding: Set by user
  1178. */
  1179. int workaround_bugs;
  1180. #define FF_BUG_AUTODETECT 1 ///< autodetection
  1181. #define FF_BUG_OLD_MSMPEG4 2
  1182. #define FF_BUG_XVID_ILACE 4
  1183. #define FF_BUG_UMP4 8
  1184. #define FF_BUG_NO_PADDING 16
  1185. #define FF_BUG_AMV 32
  1186. #define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
  1187. #define FF_BUG_QPEL_CHROMA 64
  1188. #define FF_BUG_STD_QPEL 128
  1189. #define FF_BUG_QPEL_CHROMA2 256
  1190. #define FF_BUG_DIRECT_BLOCKSIZE 512
  1191. #define FF_BUG_EDGE 1024
  1192. #define FF_BUG_HPEL_CHROMA 2048
  1193. #define FF_BUG_DC_CLIP 4096
  1194. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  1195. #define FF_BUG_TRUNCATED 16384
  1196.  
  1197. /**
  1198. * strictly follow the standard (MPEG4, ...).
  1199. * - encoding: Set by user.
  1200. * - decoding: Set by user.
  1201. * Setting this to STRICT or higher means the encoder and decoder will
  1202. * generally do stupid things, whereas setting it to unofficial or lower
  1203. * will mean the encoder might produce output that is not supported by all
  1204. * spec-compliant decoders. Decoders don't differentiate between normal,
  1205. * unofficial and experimental (that is, they always try to decode things
  1206. * when they can) unless they are explicitly asked to behave stupidly
  1207. * (=strictly conform to the specs)
  1208. */
  1209. int strict_std_compliance;
  1210. #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
  1211. #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
  1212. #define FF_COMPLIANCE_NORMAL 0
  1213. #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
  1214. #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
  1215.  
  1216. /**
  1217. * error concealment flags
  1218. * - encoding: unused
  1219. * - decoding: Set by user.
  1220. */
  1221. int error_concealment;
  1222. #define FF_EC_GUESS_MVS 1
  1223. #define FF_EC_DEBLOCK 2
  1224.  
  1225. /**
  1226. * debug
  1227. * - encoding: Set by user.
  1228. * - decoding: Set by user.
  1229. */
  1230. int debug;
  1231. #define FF_DEBUG_PICT_INFO 1
  1232. #define FF_DEBUG_RC 2
  1233. #define FF_DEBUG_BITSTREAM 4
  1234. #define FF_DEBUG_MB_TYPE 8
  1235. #define FF_DEBUG_QP 16
  1236. #define FF_DEBUG_MV 32
  1237. #define FF_DEBUG_DCT_COEFF 0x00000040
  1238. #define FF_DEBUG_SKIP 0x00000080
  1239. #define FF_DEBUG_STARTCODE 0x00000100
  1240. #define FF_DEBUG_PTS 0x00000200
  1241. #define FF_DEBUG_ER 0x00000400
  1242. #define FF_DEBUG_MMCO 0x00000800
  1243. #define FF_DEBUG_BUGS 0x00001000
  1244. #define FF_DEBUG_VIS_QP 0x00002000
  1245. #define FF_DEBUG_VIS_MB_TYPE 0x00004000
  1246. #define FF_DEBUG_BUFFERS 0x00008000
  1247. #define FF_DEBUG_THREADS 0x00010000
  1248.  
  1249. /**
  1250. * debug
  1251. * - encoding: Set by user.
  1252. * - decoding: Set by user.
  1253. */
  1254. int debug_mv;
  1255. #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
  1256. #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
  1257. #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
  1258.  
  1259. /**
  1260. * Error recognition; may misdetect some more or less valid parts as errors.
  1261. * - encoding: unused
  1262. * - decoding: Set by user.
  1263. */
  1264. int err_recognition;
  1265. #define AV_EF_CRCCHECK (1<<0)
  1266. #define AV_EF_BITSTREAM (1<<1)
  1267. #define AV_EF_BUFFER (1<<2)
  1268. #define AV_EF_EXPLODE (1<<3)
  1269.  
  1270. #define AV_EF_CAREFUL (1<<16)
  1271. #define AV_EF_COMPLIANT (1<<17)
  1272. #define AV_EF_AGGRESSIVE (1<<18)
  1273.  
  1274. /**
  1275. * opaque 64bit number (generally a PTS) that will be reordered and
  1276. * output in AVFrame.reordered_opaque
  1277. * @deprecated in favor of pkt_pts
  1278. * - encoding: unused
  1279. * - decoding: Set by user.
  1280. */
  1281. int64_t reordered_opaque;
  1282.  
  1283. /**
  1284. * Hardware accelerator in use
  1285. * - encoding: unused.
  1286. * - decoding: Set by libavcodec
  1287. */
  1288. struct AVHWAccel *hwaccel;
  1289.  
  1290. /**
  1291. * Hardware accelerator context.
  1292. * For some hardware accelerators, a global context needs to be
  1293. * provided by the user. In that case, this holds display-dependent
  1294. * data FFmpeg cannot instantiate itself. Please refer to the
  1295. * FFmpeg HW accelerator documentation to know how to fill this
  1296. * is. e.g. for VA API, this is a struct vaapi_context.
  1297. * - encoding: unused
  1298. * - decoding: Set by user
  1299. */
  1300. void *hwaccel_context;
  1301.  
  1302. /**
  1303. * error
  1304. * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
  1305. * - decoding: unused
  1306. */
  1307. uint64_t error[AV_NUM_DATA_POINTERS];
  1308.  
  1309. /**
  1310. * DCT algorithm, see FF_DCT_* below
  1311. * - encoding: Set by user.
  1312. * - decoding: unused
  1313. */
  1314. int dct_algo;
  1315. #define FF_DCT_AUTO 0
  1316. #define FF_DCT_FASTINT 1
  1317. #define FF_DCT_INT 2
  1318. #define FF_DCT_MMX 3
  1319. #define FF_DCT_ALTIVEC 5
  1320. #define FF_DCT_FAAN 6
  1321.  
  1322. /**
  1323. * IDCT algorithm, see FF_IDCT_* below.
  1324. * - encoding: Set by user.
  1325. * - decoding: Set by user.
  1326. */
  1327. int idct_algo;
  1328. #define FF_IDCT_AUTO 0
  1329. #define FF_IDCT_INT 1
  1330. #define FF_IDCT_SIMPLE 2
  1331. #define FF_IDCT_SIMPLEMMX 3
  1332. #define FF_IDCT_LIBMPEG2MMX 4
  1333. #define FF_IDCT_MMI 5
  1334. #define FF_IDCT_ARM 7
  1335. #define FF_IDCT_ALTIVEC 8
  1336. #define FF_IDCT_SH4 9
  1337. #define FF_IDCT_SIMPLEARM 10
  1338. #define FF_IDCT_H264 11
  1339. #define FF_IDCT_VP3 12
  1340. #define FF_IDCT_IPP 13
  1341. #define FF_IDCT_XVIDMMX 14
  1342. #define FF_IDCT_CAVS 15
  1343. #define FF_IDCT_SIMPLEARMV5TE 16
  1344. #define FF_IDCT_SIMPLEARMV6 17
  1345. #define FF_IDCT_SIMPLEVIS 18
  1346. #define FF_IDCT_WMV2 19
  1347. #define FF_IDCT_FAAN 20
  1348. #define FF_IDCT_EA 21
  1349. #define FF_IDCT_SIMPLENEON 22
  1350. #define FF_IDCT_SIMPLEALPHA 23
  1351. #define FF_IDCT_BINK 24
  1352.  
  1353. #if FF_API_DSP_MASK
  1354. /**
  1355. * Unused.
  1356. * @deprecated use av_set_cpu_flags_mask() instead.
  1357. */
  1358. attribute_deprecated unsigned dsp_mask;
  1359. #endif
  1360.  
  1361. /**
  1362. * bits per sample/pixel from the demuxer (needed for huffyuv).
  1363. * - encoding: Set by libavcodec.
  1364. * - decoding: Set by user.
  1365. */
  1366. int bits_per_coded_sample;
  1367.  
  1368. /**
  1369. * Bits per sample/pixel of internal libavcodec pixel/sample format.
  1370. * - encoding: set by user.
  1371. * - decoding: set by libavcodec.
  1372. */
  1373. int bits_per_raw_sample;
  1374.  
  1375. /**
  1376. * low resolution decoding, 1-> 1/2 size, 2->1/4 size
  1377. * - encoding: unused
  1378. * - decoding: Set by user.
  1379. */
  1380. int lowres;
  1381.  
  1382. /**
  1383. * the picture in the bitstream
  1384. * - encoding: Set by libavcodec.
  1385. * - decoding: Set by libavcodec.
  1386. */
  1387. AVFrame *coded_frame;
  1388.  
  1389. /**
  1390. * thread count
  1391. * is used to decide how many independent tasks should be passed to execute()
  1392. * - encoding: Set by user.
  1393. * - decoding: Set by user.
  1394. */
  1395. int thread_count;
  1396.  
  1397. /**
  1398. * Which multithreading methods to use.
  1399. * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
  1400. * so clients which cannot provide future frames should not use it.
  1401. *
  1402. * - encoding: Set by user, otherwise the default is used.
  1403. * - decoding: Set by user, otherwise the default is used.
  1404. */
  1405. int thread_type;
  1406. #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
  1407. #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
  1408.  
  1409. /**
  1410. * Which multithreading methods are in use by the codec.
  1411. * - encoding: Set by libavcodec.
  1412. * - decoding: Set by libavcodec.
  1413. */
  1414. int active_thread_type;
  1415.  
  1416. /**
  1417. * Set by the client if its custom get_buffer() callback can be called
  1418. * synchronously from another thread, which allows faster multithreaded decoding.
  1419. * draw_horiz_band() will be called from other threads regardless of this setting.
  1420. * Ignored if the default get_buffer() is used.
  1421. * - encoding: Set by user.
  1422. * - decoding: Set by user.
  1423. */
  1424. int thread_safe_callbacks;
  1425.  
  1426. /**
  1427. * The codec may call this to execute several independent things.
  1428. * It will return only after finishing all tasks.
  1429. * The user may replace this with some multithreaded implementation,
  1430. * the default implementation will execute the parts serially.
  1431. * @param count the number of things to execute
  1432. * - encoding: Set by libavcodec, user can override.
  1433. * - decoding: Set by libavcodec, user can override.
  1434. */
  1435. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
  1436.  
  1437. /**
  1438. * The codec may call this to execute several independent things.
  1439. * It will return only after finishing all tasks.
  1440. * The user may replace this with some multithreaded implementation,
  1441. * the default implementation will execute the parts serially.
  1442. * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
  1443. * @param c context passed also to func
  1444. * @param count the number of things to execute
  1445. * @param arg2 argument passed unchanged to func
  1446. * @param ret return values of executed functions, must have space for "count" values. May be NULL.
  1447. * @param func function that will be called count times, with jobnr from 0 to count-1.
  1448. * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
  1449. * two instances of func executing at the same time will have the same threadnr.
  1450. * @return always 0 currently, but code should handle a future improvement where when any call to func
  1451. * returns < 0 no further calls to func may be done and < 0 is returned.
  1452. * - encoding: Set by libavcodec, user can override.
  1453. * - decoding: Set by libavcodec, user can override.
  1454. */
  1455. int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
  1456.  
  1457. /**
  1458. * thread opaque
  1459. * Can be used by execute() to store some per AVCodecContext stuff.
  1460. * - encoding: set by execute()
  1461. * - decoding: set by execute()
  1462. */
  1463. void *thread_opaque;
  1464.  
  1465. /**
  1466. * noise vs. sse weight for the nsse comparsion function
  1467. * - encoding: Set by user.
  1468. * - decoding: unused
  1469. */
  1470. int nsse_weight;
  1471.  
  1472. /**
  1473. * profile
  1474. * - encoding: Set by user.
  1475. * - decoding: Set by libavcodec.
  1476. */
  1477. int profile;
  1478. #define FF_PROFILE_UNKNOWN -99
  1479. #define FF_PROFILE_RESERVED -100
  1480.  
  1481. #define FF_PROFILE_AAC_MAIN 0
  1482. #define FF_PROFILE_AAC_LOW 1
  1483. #define FF_PROFILE_AAC_SSR 2
  1484. #define FF_PROFILE_AAC_LTP 3
  1485. #define FF_PROFILE_AAC_HE 4
  1486. #define FF_PROFILE_AAC_HE_V2 28
  1487. #define FF_PROFILE_AAC_LD 22
  1488. #define FF_PROFILE_AAC_ELD 38
  1489.  
  1490. #define FF_PROFILE_DTS 20
  1491. #define FF_PROFILE_DTS_ES 30
  1492. #define FF_PROFILE_DTS_96_24 40
  1493. #define FF_PROFILE_DTS_HD_HRA 50
  1494. #define FF_PROFILE_DTS_HD_MA 60
  1495.  
  1496. #define FF_PROFILE_MPEG2_422 0
  1497. #define FF_PROFILE_MPEG2_HIGH 1
  1498. #define FF_PROFILE_MPEG2_SS 2
  1499. #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
  1500. #define FF_PROFILE_MPEG2_MAIN 4
  1501. #define FF_PROFILE_MPEG2_SIMPLE 5
  1502.  
  1503. #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
  1504. #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
  1505.  
  1506. #define FF_PROFILE_H264_BASELINE 66
  1507. #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
  1508. #define FF_PROFILE_H264_MAIN 77
  1509. #define FF_PROFILE_H264_EXTENDED 88
  1510. #define FF_PROFILE_H264_HIGH 100
  1511. #define FF_PROFILE_H264_HIGH_10 110
  1512. #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
  1513. #define FF_PROFILE_H264_HIGH_422 122
  1514. #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
  1515. #define FF_PROFILE_H264_HIGH_444 144
  1516. #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
  1517. #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
  1518. #define FF_PROFILE_H264_CAVLC_444 44
  1519.  
  1520. #define FF_PROFILE_VC1_SIMPLE 0
  1521. #define FF_PROFILE_VC1_MAIN 1
  1522. #define FF_PROFILE_VC1_COMPLEX 2
  1523. #define FF_PROFILE_VC1_ADVANCED 3
  1524.  
  1525. #define FF_PROFILE_MPEG4_SIMPLE 0
  1526. #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
  1527. #define FF_PROFILE_MPEG4_CORE 2
  1528. #define FF_PROFILE_MPEG4_MAIN 3
  1529. #define FF_PROFILE_MPEG4_N_BIT 4
  1530. #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
  1531. #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
  1532. #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
  1533. #define FF_PROFILE_MPEG4_HYBRID 8
  1534. #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
  1535. #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
  1536. #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
  1537. #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
  1538. #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
  1539. #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
  1540. #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
  1541.  
  1542. /**
  1543. * level
  1544. * - encoding: Set by user.
  1545. * - decoding: Set by libavcodec.
  1546. */
  1547. int level;
  1548. #define FF_LEVEL_UNKNOWN -99
  1549.  
  1550. /**
  1551. *
  1552. * - encoding: unused
  1553. * - decoding: Set by user.
  1554. */
  1555. enum AVDiscard skip_loop_filter;
  1556.  
  1557. /**
  1558. *
  1559. * - encoding: unused
  1560. * - decoding: Set by user.
  1561. */
  1562. enum AVDiscard skip_idct;
  1563.  
  1564. /**
  1565. *
  1566. * - encoding: unused
  1567. * - decoding: Set by user.
  1568. */
  1569. enum AVDiscard skip_frame;
  1570.  
  1571. /**
  1572. * Header containing style information for text subtitles.
  1573. * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
  1574. * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  1575. * the Format line following. It shouldn't include any Dialogue line.
  1576. * - encoding: Set/allocated/freed by user (before avcodec_open2())
  1577. * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
  1578. */
  1579. uint8_t *subtitle_header;
  1580. int subtitle_header_size;
  1581.  
  1582. /**
  1583. * Simulates errors in the bitstream to test error concealment.
  1584. * - encoding: Set by user.
  1585. * - decoding: unused
  1586. */
  1587. int error_rate;
  1588.  
  1589. /**
  1590. * Current packet as passed into the decoder, to avoid having
  1591. * to pass the packet into every function. Currently only valid
  1592. * inside lavc and get/release_buffer callbacks.
  1593. * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts
  1594. * - encoding: unused
  1595. */
  1596. AVPacket *pkt;
  1597.  
  1598. /**
  1599. * VBV delay coded in the last frame (in periods of a 27 MHz clock).
  1600. * Used for compliant TS muxing.
  1601. * - encoding: Set by libavcodec.
  1602. * - decoding: unused.
  1603. */
  1604. uint64_t vbv_delay;
  1605.  
  1606. /**
  1607. * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
  1608. * Code outside libavcodec should access this field using:
  1609. * avcodec_set_pkt_timebase(avctx)
  1610. * - encoding unused.
  1611. * - decodimg set by user
  1612. */
  1613. AVRational pkt_timebase;
  1614.  
  1615. /**
  1616. * AVCodecDescriptor
  1617. * Code outside libavcodec should access this field using:
  1618. * avcodec_get_codec_descriptior(avctx)
  1619. * - encoding: unused.
  1620. * - decoding: set by libavcodec.
  1621. */
  1622. const AVCodecDescriptor *codec_descriptor;
  1623.  
  1624. /**
  1625. * Current statistics for PTS correction.
  1626. * - decoding: maintained and used by libavcodec, not intended to be used by user apps
  1627. * - encoding: unused
  1628. */
  1629. int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
  1630. int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
  1631. int64_t pts_correction_last_pts; /// PTS of the last frame
  1632. int64_t pts_correction_last_dts; /// DTS of the last frame
  1633. } AVCodecContext;

二、AVCodecContext 重点字段

下面挑一些关键的变量来看看(这里只考虑解码):

enum AVMediaType codec_type:编解码器的类型(视频,音频...)

struct AVCodec  *codec:采用的解码器AVCodec(H.,MPEG2...)

int bit_rate:平均比特率

uint8_t *extradata; int extradata_size:针对特定编码器包含的附加信息(例如对于H.264解码器来说,存储SPS,PPS等)

AVRational time_base:根据该参数,可以把PTS转化为实际的时间(单位为秒s)

int width, height:如果是视频的话,代表宽和高

int refs:运动估计参考帧的个数(H.264的话会有多帧,MPEG2这类的一般就没有了)

int sample_rate:采样率(音频)

int channels:声道数(音频)

enum AVSampleFormat sample_fmt:采样格式

int profile:型(H.264里面就有,其他编码标准应该也有)

int level:级(和profile差不太多)

在这里需要注意:AVCodecContext中很多的参数是编码的时候使用的,而不是解码的时候使用的。

其实这些参数都比较容易理解。就不多费篇幅了。在这里看一下以下几个参数:

1.codec_type

编解码器类型有以下几种:

enum AVMediaType {
AVMEDIA_TYPE_UNKNOWN = -, ///< Usually treated as AVMEDIA_TYPE_DATA
AVMEDIA_TYPE_VIDEO,
AVMEDIA_TYPE_AUDIO,
AVMEDIA_TYPE_DATA, ///< Opaque data information usually continuous
AVMEDIA_TYPE_SUBTITLE,
AVMEDIA_TYPE_ATTACHMENT, ///< Opaque data information usually sparse
AVMEDIA_TYPE_NB
};

2.sample_fmt

在FFMPEG中音频采样格式有以下几种:

enum AVSampleFormat {
AV_SAMPLE_FMT_NONE = -,
AV_SAMPLE_FMT_U8, ///< unsigned 8 bits
AV_SAMPLE_FMT_S16, ///< signed 16 bits
AV_SAMPLE_FMT_S32, ///< signed 32 bits
AV_SAMPLE_FMT_FLT, ///< float
AV_SAMPLE_FMT_DBL, ///< double AV_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar
AV_SAMPLE_FMT_S16P, ///< signed 16 bits, planar
AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar
AV_SAMPLE_FMT_FLTP, ///< float, planar
AV_SAMPLE_FMT_DBLP, ///< double, planar AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically
};

3.profile

在FFMPEG中型有以下几种,可以看出AAC,MPEG2,H.264,VC-1,MPEG4都有型的概念。

#define FF_PROFILE_UNKNOWN -99
#define FF_PROFILE_RESERVED -100 #define FF_PROFILE_AAC_MAIN 0
#define FF_PROFILE_AAC_LOW 1
#define FF_PROFILE_AAC_SSR 2
#define FF_PROFILE_AAC_LTP 3
#define FF_PROFILE_AAC_HE 4
#define FF_PROFILE_AAC_HE_V2 28
#define FF_PROFILE_AAC_LD 22
#define FF_PROFILE_AAC_ELD 38 #define FF_PROFILE_DTS 20
#define FF_PROFILE_DTS_ES 30
#define FF_PROFILE_DTS_96_24 40
#define FF_PROFILE_DTS_HD_HRA 50
#define FF_PROFILE_DTS_HD_MA 60 #define FF_PROFILE_MPEG2_422 0
#define FF_PROFILE_MPEG2_HIGH 1
#define FF_PROFILE_MPEG2_SS 2
#define FF_PROFILE_MPEG2_SNR_SCALABLE 3
#define FF_PROFILE_MPEG2_MAIN 4
#define FF_PROFILE_MPEG2_SIMPLE 5 #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
#define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag #define FF_PROFILE_H264_BASELINE 66
#define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
#define FF_PROFILE_H264_MAIN 77
#define FF_PROFILE_H264_EXTENDED 88
#define FF_PROFILE_H264_HIGH 100
#define FF_PROFILE_H264_HIGH_10 110
#define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
#define FF_PROFILE_H264_HIGH_422 122
#define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
#define FF_PROFILE_H264_HIGH_444 144
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
#define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
#define FF_PROFILE_H264_CAVLC_444 44 #define FF_PROFILE_VC1_SIMPLE 0
#define FF_PROFILE_VC1_MAIN 1
#define FF_PROFILE_VC1_COMPLEX 2
#define FF_PROFILE_VC1_ADVANCED 3 #define FF_PROFILE_MPEG4_SIMPLE 0
#define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
#define FF_PROFILE_MPEG4_CORE 2
#define FF_PROFILE_MPEG4_MAIN 3
#define FF_PROFILE_MPEG4_N_BIT 4
#define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
#define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
#define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
#define FF_PROFILE_MPEG4_HYBRID 8
#define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
#define FF_PROFILE_MPEG4_CORE_SCALABLE 10
#define FF_PROFILE_MPEG4_ADVANCED_CODING 11
#define FF_PROFILE_MPEG4_ADVANCED_CORE 12
#define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
#define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15

FFmpeg 结构体学习(六): AVCodecContext 分析的更多相关文章

  1. FFmpeg 结构体学习(七): AVIOContext 分析

    在上文FFmpeg 结构体学习(六): AVCodecContext 分析我们学习了AVCodec结构体的相关内容.本文,我们将讲述一下AVIOContext. AVIOContext是FFMPEG管 ...

  2. FFmpeg 结构体学习(二): AVStream 分析

    在上文FFmpeg 结构体学习(一): AVFormatContext 分析我们学习了AVFormatContext结构体的相关内容.本文,我们将讲述一下AVStream. AVStream是存储每一 ...

  3. FFmpeg 结构体学习(四): AVFrame 分析

    在上文FFmpeg 结构体学习(三): AVPacket 分析我们学习了AVPacket结构体的相关内容.本文,我们将讲述一下AVFrame. AVFrame是包含码流参数较多的结构体.下面我们来分析 ...

  4. FFmpeg 结构体学习(五): AVCodec 分析

    在上文FFmpeg 结构体学习(四): AVFrame 分析我们学习了AVFrame结构体的相关内容.本文,我们将讲述一下AVCodec. AVCodec是存储编解码器信息的结构体.下面我们来分析一下 ...

  5. FFmpeg 结构体学习(三): AVPacket 分析

    在上文FFmpeg 结构体学习(二): AVStream 分析我们学习了AVStream结构体的相关内容.本文,我们将讲述一下AVPacket. AVPacket是存储压缩编码数据相关信息的结构体.下 ...

  6. FFmpeg 结构体学习(一): AVFormatContext 分析

    在 FFmpeg 学习(六):FFmpeg 核心模块 libavformat 与 libavcodec 分析 中,我们分析了FFmpeg中最重要的两个模块以及重要的结构体之间的关系. 后面的文章,我们 ...

  7. FFmpeg 结构体学习(八):FFMPEG中重要结构体之间的关系

    FFMPEG中结构体很多.最关键的结构体可以分成以下几类: 解协议(http,rtsp,rtmp,mms) AVIOContext,URLProtocol,URLContext主要存储视音频使用的协议 ...

  8. FFMPEG结构体分析:AVCodecContext

    注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrame FFMPEG结构体分析:AVFormatContext FFMPEG结构体分析:AVCodecConte ...

  9. FFMPEG结构体分析:AVCodecContext(转)

    注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrameFFMPEG结构体分析:AVFormatContextFFMPEG结构体分析:AVCodecContext ...

随机推荐

  1. pytest(1)

    安装就讲这么多,别的不多比比 第1个例子(基本法要了解): 这个例子中,还有一些需要注意的知识点: 1 pytest将在当前目录及其子目录中运行test _ * .py或* _test.py形式的所有 ...

  2. React知识杂烩(持续更新)

    每隔半年不看官方文档,你就会不认识React了

  3. Ubuntu16.04安装cuda9.0+cudnn7.0

    Ubuntu16.04安装cuda9.0+cudnn7.0 这篇记录拖了好久,估计是去年6月份就已经安装过几遍,然后一方面因为俺比较懒,一方面后面没有经常在自己电脑上跑算法,比较少装cuda和cudn ...

  4. Jmeter3.2源码编译环境搭建

    1.下载jmeter3.2源码 https://github.com/apache/jmeter/tree/v3_2 https://blog.csdn.net/fly_to_higher/artic ...

  5. js常用代码

    获取URL ?后的查询参数 function query(name) { var reg = new RegExp("(^|&)" + name + "=([^& ...

  6. spring boot 入门之 helloworld

    第一步:创建一个普通的maven项目 第二步:配置springboot基础依赖配置(即配置pom和启动类) POM配置 <project xmlns="http://maven.apa ...

  7. redis对set(无序集合)的相关操作

    redis对set类型(无序集合)操作的相关命令以及如何在python使用这些命令 redis对set类型操作的命令: 命令 语法 概述 返回值 Redis Sadd 命令 sadd key memb ...

  8. [OC] 线程 dispatch_group_t

    - (void)groupEvent{ //创建线程 dispatch_group_t group =dispatch_group_create(); dispatch_queue_t globalQ ...

  9. 动态规划——Remove Boxes

    很久没写博客了,越来越懒了,这次还是要分享LeetCode上一道动态规划的题目,和之前的Ballon Boom那个题(我记得是这个标题吧...)差不多,都是对一个数组的区间进行枚举的题,而且涉及到区间 ...

  10. Linux grep 命令详解

    简介grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能 ...