当前位置:   article > 正文

FFMPEG数据结构_ffopgtg

ffopgtg

目录

AVFrame:保存数据解码后的数据

AVPacket存储未解码的数据

AVFormatcontext 

AVFormatInput

AVOutputFormat 

AVCodecContext 

 AVStream


FFMPEG中结构体很多。最关键的结构体可以分成以下几类:

a)        解协议(http,rtsp,rtmp,mms)

AVIOContext,URLProtocol,URLContext主要存储视音频使用的协议的类型以及状态。URLProtocol存储输入视音频使用的封装格式。每种协议都对应一个URLProtocol结构。(注意:FFMPEG中文件也被当做一种协议“file”)

b)        解封装(flv,avi,rmvb,mp4)

AVFormatContext主要存储视音频封装格式中包含的信息AVInputFormat存储输入视音频使用的封装格式。每种视音频封装格式都对应一个AVInputFormat 结构。

c)        解码(h264,mpeg2,aac,mp3)

每个AVStream存储一个视频/音频流的相关数据;每个AVStream对应一个AVCodecContext,存储该视频/音频流使用解码方式的相关数据;每个AVCodecContext中对应一个AVCodec,包含该视频/音频对应的解码器。每种解码器都对应一个AVCodec结构。

d) 存数据

视频的话,每个结构一般是存一帧;音频可能有好几帧

解码前数据:AVPacket

解码后数据:AVFrame
 

AVFrame:保存数据解码后的数据

  1. /*
  2. *雷霄骅
  3. *leixiaohua1020@126.com
  4. *中国传媒大学/数字电视技术
  5. */
  6. /**
  7. * Audio Video Frame.
  8. * New fields can be added to the end of AVFRAME with minor version
  9. * bumps. Similarly fields that are marked as to be only accessed by
  10. * av_opt_ptr() can be reordered. This allows 2 forks to add fields
  11. * without breaking compatibility with each other.
  12. * Removal, reordering and changes in the remaining cases require
  13. * a major version bump.
  14. * sizeof(AVFrame) must not be used outside libavcodec.
  15. */
  16. typedef struct AVFrame {
  17. #define AV_NUM_DATA_POINTERS 8
  18. /**图像数据
  19. * pointer to the picture/channel planes.
  20. * This might be different from the first allocated byte
  21. * - encoding: Set by user
  22. * - decoding: set by AVCodecContext.get_buffer()
  23. */
  24. //解码后原始数据,针对视频可能是(YUV,RGB),音频的数据为(PCM)
  25. uint8_t *data[AV_NUM_DATA_POINTERS];
  26. /**
  27. * Size, in bytes, of the data for each picture/channel plane.
  28. *
  29. * For audio, only linesize[0] may be set. For planar audio, each channel
  30. * plane must be the same size.
  31. *
  32. * - encoding: Set by user
  33. * - decoding: set by AVCodecContext.get_buffer()
  34. */
  35. // data中每行数据的大小
  36. int linesize[AV_NUM_DATA_POINTERS];
  37. /**
  38. * pointers to the data planes/channels.
  39. *
  40. * For video, this should simply point to data[].
  41. *
  42. * For planar audio, each channel has a separate data pointer, and
  43. * linesize[0] contains the size of each channel buffer.
  44. * For packed audio, there is just one data pointer, and linesize[0]
  45. * contains the total size of the buffer for all channels.
  46. *
  47. * Note: Both data and extended_data will always be set by get_buffer(),
  48. * but for planar audio with more channels that can fit in data,
  49. * extended_data must be used by the decoder in order to access all
  50. * channels.
  51. *
  52. * encoding: unused
  53. * decoding: set by AVCodecContext.get_buffer()
  54. */
  55. //扩展数据,指向数据平面/通道指针,对于音频的舒缓每个通道一个但对于的数据指针
  56. //对于视频数据应该指向data[]
  57. uint8_t **extended_data;
  58. /**宽高
  59. * width and height of the video frame
  60. * - encoding: unused
  61. * - decoding: Read by user.
  62. */
  63. //视频数据的宽度和高度
  64. int width, height;
  65. /**
  66. * number of audio samples (per channel) described by this frame
  67. * - encoding: Set by user
  68. * - decoding: Set by libavcodec
  69. */
  70. //音频的一个AVframe中的包含多个视频帧
  71. int nb_samples;
  72. /**
  73. * format of the frame, -1 if unknown or unset
  74. * Values correspond to enum AVPixelFormat for video frames,
  75. * enum AVSampleFormat for audio)
  76. * - encoding: unused
  77. * - decoding: Read by user.
  78. */
  79. // 解码后原始数据的类型(YUV420,yuv422,RBG24)
  80. int format;
  81. /**
  82. * 1 -> keyframe, 0-> not
  83. * - encoding: Set by libavcodec.
  84. * - decoding: Set by libavcodec.
  85. */
  86. //是否是关键帧
  87. int key_frame;
  88. /**帧类型(I,B,P)
  89. * Picture type of the frame, see ?_TYPE below.
  90. * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
  91. * - decoding: Set by libavcodec.
  92. */
  93. // 视频数据帧的类型
  94. enum AVPictureType pict_type;
  95. /**
  96. * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.
  97. * This isn't used by libavcodec unless the default get/release_buffer() is used.
  98. * - encoding:
  99. * - decoding:
  100. */
  101. uint8_t *base[AV_NUM_DATA_POINTERS];
  102. /**
  103. * sample aspect ratio for the video frame, 0/1 if unknown/unspecified
  104. * - encoding: unused
  105. * - decoding: Read by user.
  106. */
  107. //视频数据宽高的比率
  108. AVRational sample_aspect_ratio;
  109. /**
  110. * presentation timestamp in time_base units (time when frame should be shown to user)
  111. * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.
  112. * - encoding: MUST be set by user.
  113. * - decoding: Set by libavcodec.
  114. */
  115. // 显示事件戳
  116. int64_t pts;
  117. /**
  118. * reordered pts from the last AVPacket that has been input into the decoder
  119. * - encoding: unused
  120. * - decoding: Read by user.
  121. */
  122. //
  123. int64_t pkt_pts;
  124. /**
  125. * dts from the last AVPacket that has been input into the decoder
  126. * - encoding: unused
  127. * - decoding: Read by user.
  128. */
  129. int64_t pkt_dts;
  130. /**
  131. * picture number in bitstream order
  132. * - encoding: set by
  133. * - decoding: Set by libavcodec.
  134. */
  135. int coded_picture_number;
  136. /**
  137. * picture number in display order
  138. * - encoding: set by
  139. * - decoding: Set by libavcodec.
  140. */
  141. int display_picture_number;
  142. /**
  143. * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
  144. * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
  145. * - decoding: Set by libavcodec.
  146. */
  147. int quality;
  148. /**
  149. * is this picture used as reference
  150. * The values for this are the same as the MpegEncContext.picture_structure
  151. * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
  152. * Set to 4 for delayed, non-reference frames.
  153. * - encoding: unused
  154. * - decoding: Set by libavcodec. (before get_buffer() call)).
  155. */
  156. int reference;
  157. /**QP表
  158. * QP table
  159. * - encoding: unused
  160. * - decoding: Set by libavcodec.
  161. */
  162. int8_t *qscale_table;
  163. /**
  164. * QP store stride
  165. * - encoding: unused
  166. * - decoding: Set by libavcodec.
  167. */
  168. int qstride;
  169. /**
  170. *
  171. */
  172. int qscale_type;
  173. /**跳过宏块表
  174. * mbskip_table[mb]>=1 if MB didn't change
  175. * stride= mb_width = (width+15)>>4
  176. * - encoding: unused
  177. * - decoding: Set by libavcodec.
  178. */
  179. uint8_t *mbskip_table;
  180. /**运动矢量表
  181. * motion vector table
  182. * @code
  183. * example:
  184. * int mv_sample_log2= 4 - motion_subsample_log2;
  185. * int mb_width= (width+15)>>4;
  186. * int mv_stride= (mb_width << mv_sample_log2) + 1;
  187. * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
  188. * @endcode
  189. * - encoding: Set by user.
  190. * - decoding: Set by libavcodec.
  191. */
  192. int16_t (*motion_val[2])[2];
  193. /**宏块类型表
  194. * macroblock type table
  195. * mb_type_base + mb_width + 2
  196. * - encoding: Set by user.
  197. * - decoding: Set by libavcodec.
  198. */
  199. uint32_t *mb_type;
  200. /**DCT系数
  201. * DCT coefficients
  202. * - encoding: unused
  203. * - decoding: Set by libavcodec.
  204. */
  205. short *dct_coeff;
  206. /**参考帧列表
  207. * motion reference frame index
  208. * the order in which these are stored can depend on the codec.
  209. * - encoding: Set by user.
  210. * - decoding: Set by libavcodec.
  211. */
  212. int8_t *ref_index[2];
  213. /**
  214. * for some private data of the user
  215. * - encoding: unused
  216. * - decoding: Set by user.
  217. */
  218. void *opaque;
  219. /**
  220. * error
  221. * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.
  222. * - decoding: unused
  223. */
  224. uint64_t error[AV_NUM_DATA_POINTERS];
  225. /**
  226. * type of the buffer (to keep track of who has to deallocate data[*])
  227. * - encoding: Set by the one who allocates it.
  228. * - decoding: Set by the one who allocates it.
  229. * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.
  230. */
  231. int type;
  232. /**
  233. * When decoding, this signals how much the picture must be delayed.
  234. * extra_delay = repeat_pict / (2*fps)
  235. * - encoding: unused
  236. * - decoding: Set by libavcodec.
  237. */
  238. int repeat_pict;
  239. /**
  240. * The content of the picture is interlaced.
  241. * - encoding: Set by user.
  242. * - decoding: Set by libavcodec. (default 0)
  243. */
  244. int interlaced_frame;
  245. /**
  246. * If the content is interlaced, is top field displayed first.
  247. * - encoding: Set by user.
  248. * - decoding: Set by libavcodec.
  249. */
  250. int top_field_first;
  251. /**
  252. * Tell user application that palette has changed from previous frame.
  253. * - encoding: ??? (no palette-enabled encoder yet)
  254. * - decoding: Set by libavcodec. (default 0).
  255. */
  256. int palette_has_changed;
  257. /**
  258. * codec suggestion on buffer type if != 0
  259. * - encoding: unused
  260. * - decoding: Set by libavcodec. (before get_buffer() call)).
  261. */
  262. int buffer_hints;
  263. /**
  264. * Pan scan.
  265. * - encoding: Set by user.
  266. * - decoding: Set by libavcodec.
  267. */
  268. AVPanScan *pan_scan;
  269. /**
  270. * reordered opaque 64bit (generally an integer or a double precision float
  271. * PTS but can be anything).
  272. * The user sets AVCodecContext.reordered_opaque to represent the input at
  273. * that time,
  274. * the decoder reorders values as needed and sets AVFrame.reordered_opaque
  275. * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
  276. * @deprecated in favor of pkt_pts
  277. * - encoding: unused
  278. * - decoding: Read by user.
  279. */
  280. int64_t reordered_opaque;
  281. /**
  282. * hardware accelerator private data (FFmpeg-allocated)
  283. * - encoding: unused
  284. * - decoding: Set by libavcodec
  285. */
  286. void *hwaccel_picture_private;
  287. /**
  288. * the AVCodecContext which ff_thread_get_buffer() was last called on
  289. * - encoding: Set by libavcodec.
  290. * - decoding: Set by libavcodec.
  291. */
  292. struct AVCodecContext *owner;
  293. /**
  294. * used by multithreading to store frame-specific info
  295. * - encoding: Set by libavcodec.
  296. * - decoding: Set by libavcodec.
  297. */
  298. void *thread_opaque;
  299. /**
  300. * log2 of the size of the block which a single vector in motion_val represents:
  301. * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
  302. * - encoding: unused
  303. * - decoding: Set by libavcodec.
  304. */
  305. uint8_t motion_subsample_log2;
  306. /**(音频)采样率
  307. * Sample rate of the audio data.
  308. *
  309. * - encoding: unused
  310. * - decoding: read by user
  311. */
  312. int sample_rate;
  313. /**
  314. * Channel layout of the audio data.
  315. *
  316. * - encoding: unused
  317. * - decoding: read by user.
  318. */
  319. uint64_t channel_layout;
  320. /**
  321. * frame timestamp estimated using various heuristics, in stream time base
  322. * Code outside libavcodec should access this field using:
  323. * av_frame_get_best_effort_timestamp(frame)
  324. * - encoding: unused
  325. * - decoding: set by libavcodec, read by user.
  326. */
  327. int64_t best_effort_timestamp;
  328. /**
  329. * reordered pos from the last AVPacket that has been input into the decoder
  330. * Code outside libavcodec should access this field using:
  331. * av_frame_get_pkt_pos(frame)
  332. * - encoding: unused
  333. * - decoding: Read by user.
  334. */
  335. int64_t pkt_pos;
  336. /**
  337. * duration of the corresponding packet, expressed in
  338. * AVStream->time_base units, 0 if unknown.
  339. * Code outside libavcodec should access this field using:
  340. * av_frame_get_pkt_duration(frame)
  341. * - encoding: unused
  342. * - decoding: Read by user.
  343. */
  344. int64_t pkt_duration;
  345. /**
  346. * metadata.
  347. * Code outside libavcodec should access this field using:
  348. * av_frame_get_metadata(frame)
  349. * - encoding: Set by user.
  350. * - decoding: Set by libavcodec.
  351. */
  352. AVDictionary *metadata;
  353. /**
  354. * decode error flags of the frame, set to a combination of
  355. * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there
  356. * were errors during the decoding.
  357. * Code outside libavcodec should access this field using:
  358. * av_frame_get_decode_error_flags(frame)
  359. * - encoding: unused
  360. * - decoding: set by libavcodec, read by user.
  361. */
  362. int decode_error_flags;
  363. #define FF_DECODE_ERROR_INVALID_BITSTREAM 1
  364. #define FF_DECODE_ERROR_MISSING_REFERENCE 2
  365. /**
  366. * number of audio channels, only used for audio.
  367. * Code outside libavcodec should access this field using:
  368. * av_frame_get_channels(frame)
  369. * - encoding: unused
  370. * - decoding: Read by user.
  371. */
  372. int64_t channels;
  373. } AVFrame;

AVPacket存储未解码的数据

  1. typedef struct AVPacket {
  2. //对数据包数据所在数缓冲区的引用
  3. AVBufferRef *buf;
  4. /**
  5. * Presentation timestamp in AVStream->time_base units; the time at which
  6. * the decompressed packet will be presented to the user.
  7. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  8. * pts MUST be larger or equal to dts as presentation cannot happen before
  9. * decompression, unless one wants to view hex dumps. Some formats misuse
  10. * the terms dts and pts/cts to mean something different. Such timestamps
  11. * must be converted to true pts/dts before they are stored in AVPacket.
  12. */
  13. // 显示时间戳
  14. int64_t pts;
  15. /**
  16. * Decompression timestamp in AVStream->time_base units; the time at which
  17. * the packet is decompressed.
  18. * Can be AV_NOPTS_VALUE if it is not stored in the file.
  19. */
  20. // 解码事件戳
  21. int64_t dts;
  22. //保存压缩数据的指针
  23. uint8_t *data;
  24. //压缩收据的大小
  25. int size;
  26. // 包存在数据的的数据流的ID
  27. int stream_index;
  28. /**
  29. * A combination of AV_PKT_FLAG values
  30. */
  31. // 数据为最低为1表示该数据为的关键帧率
  32. int flags;
  33. /**
  34. * Additional packet data that can be provided by the container.
  35. * Packet can contain several types of side information.
  36. */
  37. AVPacketSideData *side_data;
  38. int side_data_elems;
  39. //单位数据包的持续时间
  40. int64_t duration;
  41. //在数据流中的具体位置
  42. int64_t pos; ///< byte position in stream, -1 if unknown
  43. //保存用户的私有数据
  44. void *opaque;
  45. /**
  46. * AVBufferRef for free use by the API user. FFmpeg will never check the
  47. * contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when
  48. * the packet is unreferenced. av_packet_copy_props() calls create a new
  49. * reference with av_buffer_ref() for the target packet's opaque_ref field.
  50. *
  51. * This is unrelated to the opaque field, although it serves a similar
  52. * purpose.
  53. */
  54. AVBufferRef *opaque_ref;
  55. /**
  56. * Time base of the packet's timestamps.
  57. * In the future, this field may be set on packets output by encoders or
  58. * demuxers, but its value will be by default ignored on input to decoders
  59. * or muxers.
  60. */
  61. // 数据包的时间基
  62. AVRational time_base;
  63. } AVPacket;
  1. typedef struct AVBufferRef {
  2. AVBuffer *buffer;
  3. /**
  4. * The data buffer. It is considered writable if and only if
  5. * this is the only reference to the buffer, in which case
  6. * av_buffer_is_writable() returns 1.
  7. */
  8. uint8_t *data;
  9. /**
  10. * Size of data in bytes.
  11. */
  12. size_t size;
  13. } AVBufferRef;

 AVBuffer:数据缓冲区

  1. struct AVBuffer {
  2. //指向一段长度为size的neicun
  3. uint8_t *data; /**< data described by this buffer */
  4. size_t size; /**< size of data in bytes */
  5. // 引用计数,表示有多山个AVBufferRef对象引用了自己
  6. atomic_uint refcount;
  7. /**
  8. * a callback for freeing the data
  9. */
  10. void (*free)(void *opaque, uint8_t *data);
  11. //一个指针,指向一个用户自定义类型的对象,也可为空,FFmpeg 不关心。
  12. void *opaque;
  13. //一些辅助自身状态的标志变量
  14. int flags;
  15. int flags_internal;
  16. };

AVFormatcontext

此结构包含了一个视频流的格式内容。其中AVInputFormat或者AVOutputFormat,但是同一时间AVFormatContext内只能存在其中一个),AVStream,AVPacket这几个重要的结构以及一些其他信息,比如title,author,copyright等,后还有一些可能在编解码中会用到的信息,比如 duration、file_size、 bit_rate等。

  1. typedef struct AVFormatContext
  2. {
  3. /**
  4. * A class for logging and @ref avoptions. Set by avformat_alloc_context().
  5. * Exports (de)muxer private options if they exist.
  6. */
  7. const AVClass *av_class;
  8. // 输入容器的格式
  9. // avformat_open_input() 设置
  10. ff_const59 struct AVInputFormat *iformat;
  11. // 输出容器的个数
  12. // avformat_write_header()设置
  13. ff_const59 struct AVOutputFormat *oformat;
  14. // * - muxing: set by avformat_write_header()
  15. // * - demuxing: set by avformat_open_input()
  16. // 格式私有数据
  17. void *priv_data;
  18. // I/O context. 在解复用时候,在avformat_open_input()调用之前设置
  19. AVIOContext *pb;
  20. // 流信息
  21. int ctx_flags;
  22. // 流的数量
  23. unsigned int nb_streams;
  24. // 文件流的链表
  25. AVStream **streams;
  26. #if FF_API_FORMAT_FILENAME
  27. // 流所属的文件名
  28. char filename[1024];
  29. #endif
  30. // 流的url地址
  31. char *url;
  32. // 开始帧的位置,只有在解复用的时候用到
  33. int64_t start_time;
  34. // 流的时长
  35. int64_t duration;
  36. // 整个流的比特率
  37. int64_t bit_rate;
  38. // 整个packet的大小
  39. unsigned int packet_size;
  40. // 最大的延迟
  41. int max_delay;
  42. // 解码器的状态
  43. int flags;
  44. #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
  45. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
  46. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
  47. #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
  48. #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container
  49. #define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
  50. #define AVFMT_FLAG_NOBUFFER 0x0040 ///< Do not buffer frames when possible
  51. #define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
  52. #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
  53. #define AVFMT_FLAG_FLUSH_PACKETS 0x0200 ///< Flush the AVIOContext every packet.
  54. /**
  55. * When muxing, try to avoid writing any random/volatile data to the output.
  56. * This includes any random IDs, real-time timestamps/dates, muxer version, etc.
  57. *
  58. * This flag is mainly intended for testing.
  59. */
  60. #define AVFMT_FLAG_BITEXACT 0x0400
  61. #if FF_API_LAVF_MP4A_LATM
  62. #define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Deprecated, does nothing.
  63. #endif
  64. #define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
  65. #if FF_API_LAVF_PRIV_OPT
  66. #define AVFMT_FLAG_PRIV_OPT 0x20000 ///< Enable use of private options by delaying codec open (deprecated, will do nothing once av_demuxer_open() is removed)
  67. #endif
  68. #if FF_API_LAVF_KEEPSIDE_FLAG
  69. #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Deprecated, does nothing.
  70. #endif
  71. #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats
  72. #define AVFMT_FLAG_SHORTEST 0x100000 ///< Stop muxing when the shortest stream stops.
  73. #define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as requested by the muxer
  74. // 从输入中读取最大字节数用来确定流的属性
  75. int64_t probesize;
  76. // 读取数据的最大持续时间
  77. int64_t max_analyze_duration;
  78. const uint8_t *key;
  79. int keylen;
  80. unsigned int nb_programs;
  81. AVProgram **programs;
  82. // 视屏编码数据编码器类型 Id
  83. enum AVCodecID video_codec_id;
  84. // 音频编码器的类型 Id
  85. enum AVCodecID audio_codec_id;
  86. // 字幕类型编码器的 ID
  87. enum AVCodecID subtitle_codec_id;
  88. // 每条流中最大内存字节数
  89. unsigned int max_index_size;
  90. // Buffering frames的最大内存字节数
  91. unsigned int max_picture_buffer;
  92. // AVChapters array的chapters的数量
  93. unsigned int nb_chapters;
  94. AVChapter **chapters;
  95. /**
  96. * Metadata that applies to the whole file.
  97. *
  98. * - demuxing: set by libavformat in avformat_open_input()
  99. * - muxing: may be set by the caller before avformat_write_header()
  100. *
  101. * Freed by libavformat in avformat_free_context().
  102. */
  103. // 元数据,应用整个数据过程
  104. AVDictionary *metadata;
  105. // 起始时间,从PTS=0开始
  106. int64_t start_time_realtime;
  107. // 帧率
  108. int fps_probe_size;
  109. // 错误检测
  110. int error_recognition;
  111. /**
  112. * Custom interrupt callbacks for the I/O layer.
  113. *
  114. * demuxing: set by the user before avformat_open_input().
  115. * muxing: set by the user before avformat_write_header()
  116. * (mainly useful for AVFMT_NOFILE formats). The callback
  117. * should also be passed to avio_open2() if it's used to
  118. * open the file.
  119. */
  120. AVIOInterruptCB interrupt_callback;
  121. /**
  122. * Flags to enable debugging.
  123. */
  124. int debug;
  125. #define FF_FDEBUG_TS 0x0001
  126. /**
  127. * Maximum buffering duration for interleaving.
  128. *
  129. * To ensure all the streams are interleaved correctly,
  130. * av_interleaved_write_frame() will wait until it has at least one packet
  131. * for each stream before actually writing any packets to the output file.
  132. * When some streams are "sparse" (i.e. there are large gaps between
  133. * successive packets), this can result in excessive buffering.
  134. *
  135. * This field specifies the maximum difference between the timestamps of the
  136. * first and the last packet in the muxing queue, above which libavformat
  137. * will output a packet regardless of whether it has queued a packet for all
  138. * the streams.
  139. *
  140. * Muxing only, set by the caller before avformat_write_header().
  141. */
  142. int64_t max_interleave_delta;
  143. /**
  144. * Allow non-standard and experimental extension
  145. * @see AVCodecContext.strict_std_compliance
  146. */
  147. int strict_std_compliance;
  148. /**
  149. * Flags indicating events happening on the file, a combination of
  150. * AVFMT_EVENT_FLAG_*.
  151. *
  152. * - demuxing: may be set by the demuxer in avformat_open_input(),
  153. * avformat_find_stream_info() and av_read_frame(). Flags must be cleared
  154. * by the user once the event has been handled.
  155. * - muxing: may be set by the user after avformat_write_header() to
  156. * indicate a user-triggered event. The muxer will clear the flags for
  157. * events it has handled in av_[interleaved]_write_frame().
  158. */
  159. int event_flags;
  160. /**
  161. * - demuxing: the demuxer read new metadata from the file and updated
  162. * AVFormatContext.metadata accordingly
  163. * - muxing: the user updated AVFormatContext.metadata and wishes the muxer to
  164. * write it into the file
  165. */
  166. #define AVFMT_EVENT_FLAG_METADATA_UPDATED 0x0001
  167. /**
  168. * Maximum number of packets to read while waiting for the first timestamp.
  169. * Decoding only.
  170. */
  171. int max_ts_probe;
  172. /**
  173. * Avoid negative timestamps during muxing.
  174. * Any value of the AVFMT_AVOID_NEG_TS_* constants.
  175. * Note, this only works when using av_interleaved_write_frame. (interleave_packet_per_dts is in use)
  176. * - muxing: Set by user
  177. * - demuxing: unused
  178. */
  179. int avoid_negative_ts;
  180. #define AVFMT_AVOID_NEG_TS_AUTO -1 ///< Enabled when required by target format
  181. #define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 ///< Shift timestamps so they are non negative
  182. #define AVFMT_AVOID_NEG_TS_MAKE_ZERO 2 ///< Shift timestamps so that they start at 0
  183. // 数据传输过程中的流ID
  184. int ts_id;
  185. // 音视频提前加载,不是所有格式都支持
  186. int audio_preload;
  187. // 最大chunk时长,不是所有格式都支持
  188. int max_chunk_duration;
  189. // 最大chunk以字节为单位
  190. int max_chunk_size;
  191. // 强制使用wallclock时间戳作为数据包的pts/dts
  192. int use_wallclock_as_timestamps;
  193. /**
  194. * avio flags, used to force AVIO_FLAG_DIRECT.
  195. * - encoding: unused
  196. * - decoding: Set by user
  197. */
  198. int avio_flags;
  199. // 可以通过不同的方式估计持续时间字段
  200. enum AVDurationEstimationMethod duration_estimation_method;
  201. // 当字节流打开流的时候,跳过初始化字节
  202. int64_t skip_initial_bytes;
  203. // 纠正单个时间戳的溢出
  204. unsigned int correct_ts_overflow;
  205. // 强制seek到任意一帧
  206. int seek2any;
  207. // 在每个packet之后
  208. int flush_packets;
  209. // 格式探测评分
  210. int probe_score;
  211. // 读取最大的字节数来确定格式
  212. int format_probesize;
  213. // 由','分隔的所有可用的decoder(解码器)
  214. char *codec_whitelist;
  215. // 由‘,’分隔的所有可用的demuxers(解复用器)
  216. char *format_whitelist;
  217. // libavformat内部私有成员
  218. AVFormatInternal *internal;
  219. // I/O 更改的标志
  220. int io_repositioned;
  221. // 特殊解码器或者相同codec_id的视频Codec
  222. AVCodec *video_codec;
  223. // 特殊解码器或者相同codec_id的音频Codec
  224. AVCodec *audio_codec;
  225. // 特殊解码器或者相同codec_id的字幕Codec
  226. AVCodec *subtitle_codec;
  227. // 特殊解码器或者相同codec_id的数据Codec
  228. AVCodec *data_codec;
  229. /**
  230. * Number of bytes to be written as padding in a metadata header.
  231. * Demuxing: Unused.
  232. * Muxing: Set by user via av_format_set_metadata_header_padding.
  233. */
  234. int metadata_header_padding;
  235. // 用户私有数据
  236. void *opaque;
  237. /**
  238. * Callback used by devices to communicate with application.
  239. */
  240. av_format_control_message control_message_cb;
  241. /**
  242. * Output timestamp offset, in microseconds.
  243. * Muxing: set by user
  244. */
  245. int64_t output_ts_offset;
  246. /**
  247. * dump format separator.
  248. * can be ", " or "\n " or anything else
  249. * - muxing: Set by user.
  250. * - demuxing: Set by user.
  251. */
  252. uint8_t *dump_separator;
  253. /**
  254. * Forced Data codec_id.
  255. * Demuxing: Set by user.
  256. */
  257. enum AVCodecID data_codec_id;
  258. #if FF_API_OLD_OPEN_CALLBACKS
  259. /**
  260. * Called to open further IO contexts when needed for demuxing.
  261. *
  262. * This can be set by the user application to perform security checks on
  263. * the URLs before opening them.
  264. * The function should behave like avio_open2(), AVFormatContext is provided
  265. * as contextual information and to reach AVFormatContext.opaque.
  266. *
  267. * If NULL then some simple checks are used together with avio_open2().
  268. *
  269. * Must not be accessed directly from outside avformat.
  270. * @See av_format_set_open_cb()
  271. *
  272. * Demuxing: Set by user.
  273. *
  274. * @deprecated Use io_open and io_close.
  275. */
  276. attribute_deprecated int (*open_cb)(struct AVFormatContext *s, AVIOContext **p, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options);
  277. #endif
  278. /**
  279. * ',' separated list of allowed protocols.
  280. * - encoding: unused
  281. * - decoding: set by user
  282. */
  283. // 协议白名单
  284. char *protocol_whitelist;
  285. /**
  286. * A callback for opening new IO streams.
  287. *
  288. * Whenever a muxer or a demuxer needs to open an IO stream (typically from
  289. * avformat_open_input() for demuxers, but for certain formats can happen at
  290. * other times as well), it will call this callback to obtain an IO context.
  291. *
  292. * @param s the format context
  293. * @param pb on success, the newly opened IO context should be returned here
  294. * @param url the url to open
  295. * @param flags a combination of AVIO_FLAG_*
  296. * @param options a dictionary of additional options, with the same
  297. * semantics as in avio_open2()
  298. * @return 0 on success, a negative AVERROR code on failure
  299. *
  300. * @note Certain muxers and demuxers do nesting, i.e. they open one or more
  301. * additional internal format contexts. Thus the AVFormatContext pointer
  302. * passed to this callback may be different from the one facing the caller.
  303. * It will, however, have the same 'opaque' field.
  304. */
  305. int (*io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url,
  306. int flags, AVDictionary **options);
  307. /**
  308. * A callback for closing the streams opened with AVFormatContext.io_open().
  309. */
  310. void (*io_close)(struct AVFormatContext *s, AVIOContext *pb);
  311. // 协议的黑名单
  312. char *protocol_blacklist;
  313. // 流的最大数量
  314. int max_streams;
  315. /**
  316. * Skip duration calcuation in estimate_timings_from_pts.
  317. * - encoding: unused
  318. * - decoding: set by user
  319. */
  320. int skip_estimate_duration_from_pts;
  321. // 多少个packet用于检测
  322. int max_probe_packets;
  323. } AVFormatContext;

AVFormatInput

VInputFormat是解复用器(解封装)作用时读取媒体文件并将其拆分为数据块(数据包)。每个数据包,包含一个或者多个编码帧

  1. typedef struct AVInputFormat
  2. {
  3. // 封装格式的短名
  4. const char *name;
  5. // 封装格式的长名字
  6. const char *long_name;
  7. /**
  8. * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
  9. * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
  10. * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
  11. */
  12. int flags;
  13. // 如果扩展被定义就不会进行类型格式的探查
  14. const char *extensions;
  15. // 编码器标签
  16. const struct AVCodecTag *const *codec_tag;
  17. // 私有数据
  18. const AVClass *priv_class; ///< AVClass for the private context
  19. // mime类型,比如video/avc,在probing(探测)时候需要检查
  20. const char *mime_type;
  21. /*****************************************************************
  22. * No fields below this line are part of the public API. They
  23. * may not be used outside of libavformat and can be changed and
  24. * removed at will.
  25. * New public fields should be added right above.
  26. *****************************************************************
  27. */
  28. #if FF_API_NEXT
  29. ff_const59 struct AVInputFormat *next;
  30. #endif
  31. // 原始Demuxer存储的codec i
  32. int raw_codec_id;
  33. // 魔种格式文件的数据大小
  34. int priv_data_size;
  35. /**
  36. * Tell if a given file has a chance of being parsed as this format.
  37. * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
  38. * big so you do not have to check for that unless you need more.
  39. */
  40. int (*read_probe)(const AVProbeData *);
  41. /**
  42. * Read the format header and initialize the AVFormatContext
  43. * structure. Return 0 if OK. 'avformat_new_stream' should be
  44. * called to create new streams.
  45. */
  46. int (*read_header)(struct AVFormatContext *);
  47. /**
  48. * Read one packet and put it in 'pkt'. pts and flags are also
  49. * set. 'avformat_new_stream' can be called only if the flag
  50. * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
  51. * background thread).
  52. * @return 0 on success, < 0 on error.
  53. * Upon returning an error, pkt must be unreferenced by the caller.
  54. */
  55. int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
  56. /**
  57. * Close the stream. The AVFormatContext and AVStreams are not
  58. * freed by this function
  59. */
  60. int (*read_close)(struct AVFormatContext *);
  61. /**
  62. * Seek to a given timestamp relative to the frames in
  63. * stream component stream_index.
  64. * @param stream_index Must not be -1.
  65. * @param flags Selects which direction should be preferred if no exact
  66. * match is available.
  67. * @return >= 0 on success (but not necessarily the new offset)
  68. */
  69. int (*read_seek)(struct AVFormatContext *,
  70. int stream_index, int64_t timestamp, int flags);
  71. /**
  72. * Get the next timestamp in stream[stream_index].time_base units.
  73. * @return the timestamp or AV_NOPTS_VALUE if an error occurred
  74. */
  75. int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
  76. int64_t *pos, int64_t pos_limit);
  77. /**
  78. * Start/resume playing - only meaningful if using a network-based format
  79. * (RTSP).
  80. */
  81. int (*read_play)(struct AVFormatContext *);
  82. /**
  83. * Pause playing - only meaningful if using a network-based format
  84. * (RTSP).
  85. */
  86. int (*read_pause)(struct AVFormatContext *);
  87. /**
  88. * Seek to timestamp ts.
  89. * Seeking will be done so that the point from which all active streams
  90. * can be presented successfully will be closest to ts and within min/max_ts.
  91. * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
  92. */
  93. int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
  94. /**
  95. * Returns device list with it properties.
  96. * @see avdevice_list_devices() for more details.
  97. */
  98. int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list);
  99. #if LIBAVFORMAT_VERSION_MAJOR < 59
  100. /**
  101. * Initialize device capabilities submodule.
  102. * @see avdevice_capabilities_create() for more details.
  103. */
  104. int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);
  105. /**
  106. * Free device capabilities submodule.
  107. * @see avdevice_capabilities_free() for more details.
  108. */
  109. int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);
  110. #endif
  111. } AVInputFormat;

AVOutputFormat 

  1. typedef struct AVOutputFormat
  2. {
  3. // 封装格式名称
  4. const char *name;
  5. // 封装格式的长名称
  6. const char *long_name;
  7. const char *mime_type;
  8. const char *extensions; /**< comma-separated filename extensions */
  9. /* output support */
  10. enum AVCodecID audio_codec; /**< default audio codec */
  11. enum AVCodecID video_codec; /**< default video codec */
  12. enum AVCodecID subtitle_codec; /**< default subtitle codec */
  13. /**
  14. * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER,
  15. * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS,
  16. * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH,
  17. * AVFMT_TS_NONSTRICT, AVFMT_TS_NEGATIVE
  18. */
  19. int flags;
  20. /**
  21. * List of supported codec_id-codec_tag pairs, ordered by "better
  22. * choice first". The arrays are all terminated by AV_CODEC_ID_NONE.
  23. */
  24. const struct AVCodecTag *const *codec_tag;
  25. const AVClass *priv_class; ///< AVClass for the private context
  26. /*****************************************************************
  27. * No fields below this line are part of the public API. They
  28. * may not be used outside of libavformat and can be changed and
  29. * removed at will.
  30. * New public fields should be added right above.
  31. *****************************************************************
  32. */
  33. /**
  34. * The ff_const59 define is not part of the public API and will
  35. * be removed without further warning.
  36. */
  37. #if FF_API_AVIOFORMAT
  38. #define ff_const59
  39. #else
  40. #define ff_const59 const
  41. #endif
  42. #if FF_API_NEXT
  43. ff_const59 struct AVOutputFormat *next;
  44. #endif
  45. /**
  46. * size of private data so that it can be allocated in the wrapper
  47. */
  48. int priv_data_size;
  49. int (*write_header)(struct AVFormatContext *);
  50. /**
  51. * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,
  52. * pkt can be NULL in order to flush data buffered in the muxer.
  53. * When flushing, return 0 if there still is more data to flush,
  54. * or 1 if everything was flushed and there is no more buffered
  55. * data.
  56. */
  57. int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
  58. int (*write_trailer)(struct AVFormatContext *);
  59. /**
  60. * A format-specific function for interleavement.
  61. * If unset, packets will be interleaved by dts.
  62. */
  63. int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
  64. AVPacket *in, int flush);
  65. /**
  66. * Test if the given codec can be stored in this container.
  67. *
  68. * @return 1 if the codec is supported, 0 if it is not.
  69. * A negative number if unknown.
  70. * MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC
  71. */
  72. int (*query_codec)(enum AVCodecID id, int std_compliance);
  73. void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
  74. int64_t *dts, int64_t *wall);
  75. /**
  76. * Allows sending messages from application to device.
  77. */
  78. int (*control_message)(struct AVFormatContext *s, int type,
  79. void *data, size_t data_size);
  80. /**
  81. * Write an uncoded AVFrame.
  82. *
  83. * See av_write_uncoded_frame() for details.
  84. *
  85. * The library will free *frame afterwards, but the muxer can prevent it
  86. * by setting the pointer to NULL.
  87. */
  88. int (*write_uncoded_frame)(struct AVFormatContext *, int stream_index,
  89. AVFrame **frame, unsigned flags);
  90. /**
  91. * Returns device list with it properties.
  92. * @see avdevice_list_devices() for more details.
  93. */
  94. int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list);
  95. #if LIBAVFORMAT_VERSION_MAJOR < 59
  96. /**
  97. * Initialize device capabilities submodule.
  98. * @see avdevice_capabilities_create() for more details.
  99. */
  100. int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);
  101. /**
  102. * Free device capabilities submodule.
  103. * @see avdevice_capabilities_free() for more details.
  104. */
  105. int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);
  106. #endif
  107. enum AVCodecID data_codec; /**< default data codec */
  108. /**
  109. * Initialize format. May allocate data here, and set any AVFormatContext or
  110. * AVStream parameters that need to be set before packets are sent.
  111. * This method must not write output.
  112. *
  113. * Return 0 if streams were fully configured, 1 if not, negative AVERROR on failure
  114. *
  115. * Any allocations made here must be freed in deinit().
  116. */
  117. int (*init)(struct AVFormatContext *);
  118. /**
  119. * Deinitialize format. If present, this is called whenever the muxer is being
  120. * destroyed, regardless of whether or not the header has been written.
  121. *
  122. * If a trailer is being written, this is called after write_trailer().
  123. *
  124. * This is called if init() fails as well.
  125. */
  126. void (*deinit)(struct AVFormatContext *);
  127. /**
  128. * Set up any necessary bitstream filtering and extract any extra data needed
  129. * for the global header.
  130. * Return 0 if more packets from this stream must be checked; 1 if not.
  131. */
  132. int (*check_bitstream)(struct AVFormatContext *, const AVPacket *pkt);
  133. } AVOutputFormat;

AVCodecContext 

  1. typedef struct AVCodecContext
  2. {
  3. // 一个用来记录和指向avoptions的类。由avformat_all_context()设置。如果(de)muxer存在私有option也会输出
  4. const AVClass *av_class;
  5. int log_level_offset;
  6. // 解码器的类型(视频,音频...)
  7. enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
  8. // 采用编码器的AVcodec
  9. const struct AVCodec *codec;
  10. // 编码器的id
  11. enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
  12. /**
  13. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  14. * This is used to work around some encoder bugs.
  15. * A demuxer should set this to what is stored in the field used to identify the codec.
  16. * If there are multiple such fields in a container then the demuxer should choose the one
  17. * which maximizes the information about the used codec.
  18. * If the codec tag field in a container is larger than 32 bits then the demuxer should
  19. * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
  20. * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
  21. * first.
  22. * - encoding: Set by user, if not then the default based on codec_id will be used.
  23. * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
  24. */
  25. unsigned int codec_tag;
  26. // 私有数据
  27. void *priv_data;
  28. /**
  29. * Private context used for internal data.
  30. *
  31. * Unlike priv_data, this is not codec-specific. It is used in general
  32. * libavcodec functions.
  33. */
  34. struct AVCodecInternal *internal;
  35. /**
  36. * Private data of the user, can be used to carry app specific stuff.
  37. * - encoding: Set by user.
  38. * - decoding: Set by user.
  39. */
  40. void *opaque;
  41. // 平均比特率
  42. int64_t bit_rate;
  43. // 比特流允许偏离参考的比特数
  44. int bit_rate_tolerance;
  45. /**
  46. * Global quality for codecs which cannot change it per frame.
  47. * This should be proportional to MPEG-1/2/4 qscale.
  48. * - encoding: Set by user.
  49. * - decoding: unused
  50. */
  51. int global_quality;
  52. /**
  53. * - encoding: Set by user.
  54. * - decoding: unused
  55. */
  56. int compression_level;
  57. #define FF_COMPRESSION_DEFAULT -1
  58. /**
  59. * AV_CODEC_FLAG_*.
  60. * - encoding: Set by user.
  61. * - decoding: Set by user.
  62. */
  63. int flags;
  64. /**
  65. * AV_CODEC_FLAG2_*
  66. * - encoding: Set by user.
  67. * - decoding: Set by user.
  68. */
  69. int flags2;
  70. /**
  71. * some codecs need / can use extradata like Huffman tables.
  72. * MJPEG: Huffman tables
  73. * rv10: additional flags
  74. * MPEG-4: global headers (they can be in the bitstream or here)
  75. * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
  76. * than extradata_size to avoid problems if it is read with the bitstream reader.
  77. * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
  78. * Must be allocated with the av_malloc() family of functions.
  79. * - encoding: Set/allocated/freed by libavcodec.
  80. * - decoding: Set/allocated/freed by user.
  81. */
  82. uint8_t *extradata;
  83. int extradata_size;
  84. /**
  85. * This is the fundamental unit of time (in seconds) in terms
  86. * of which frame timestamps are represented. For fixed-fps content,
  87. * timebase should be 1/framerate and timestamp increments should be
  88. * identically 1.
  89. * This often, but not always is the inverse of the frame rate or field rate
  90. * for video. 1/time_base is not the average frame rate if the frame rate is not
  91. * constant.
  92. *
  93. * Like containers, elementary streams also can store timestamps, 1/time_base
  94. * is the unit in which these timestamps are specified.
  95. * As example of such codec time base see ISO/IEC 14496-2:2001(E)
  96. * vop_time_increment_resolution and fixed_vop_rate
  97. * (fixed_vop_rate == 0 implies that it is different from the framerate)
  98. *
  99. * - encoding: MUST be set by user.
  100. * - decoding: the use of this field for decoding is deprecated.
  101. * Use framerate instead.
  102. */
  103. AVRational time_base;
  104. /**
  105. * For some codecs, the time base is closer to the field rate than the frame rate.
  106. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
  107. * if no telecine is used ...
  108. *
  109. * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
  110. */
  111. int ticks_per_frame;
  112. /**
  113. * Codec delay.
  114. *
  115. * Encoding: Number of frames delay there will be from the encoder input to
  116. * the decoder output. (we assume the decoder matches the spec)
  117. * Decoding: Number of frames delay in addition to what a standard decoder
  118. * as specified in the spec would produce.
  119. *
  120. * Video:
  121. * Number of frames the decoded output will be delayed relative to the
  122. * encoded input.
  123. *
  124. * Audio:
  125. * For encoding, this field is unused (see initial_padding).
  126. *
  127. * For decoding, this is the number of samples the decoder needs to
  128. * output before the decoder's output is valid. When seeking, you should
  129. * start decoding this many samples prior to your desired seek point.
  130. *
  131. * - encoding: Set by libavcodec.
  132. * - decoding: Set by libavcodec.
  133. */
  134. int delay;
  135. // 视屏图像的尺寸
  136. int width, height;
  137. //比特流的宽高,当解码帧裁剪之后输出,所以可能与width, height值不一样
  138. int coded_width, coded_height;
  139. // 在一组gop中图像中的数量
  140. int gop_size;
  141. // 图像的格式
  142. enum AVPixelFormat pix_fmt;
  143. /**
  144. * If non NULL, 'draw_horiz_band' is called by the libavcodec
  145. * decoder to draw a horizontal band. It improves cache usage. Not
  146. * all codecs can do that. You must check the codec capabilities
  147. * beforehand.
  148. * When multithreading is used, it may be called from multiple threads
  149. * at the same time; threads might draw different parts of the same AVFrame,
  150. * or multiple AVFrames, and there is no guarantee that slices will be drawn
  151. * in order.
  152. * The function is also used by hardware acceleration APIs.
  153. * It is called at least once during frame decoding to pass
  154. * the data needed for hardware render.
  155. * In that mode instead of pixel data, AVFrame points to
  156. * a structure specific to the acceleration API. The application
  157. * reads the structure and can change some fields to indicate progress
  158. * or mark state.
  159. * - encoding: unused
  160. * - decoding: Set by user.
  161. * @param height the height of the slice
  162. * @param y the y position of the slice
  163. * @param type 1->top field, 2->bottom field, 3->frame
  164. * @param offset offset into the AVFrame.data from which the slice should be read
  165. */
  166. void (*draw_horiz_band)(struct AVCodecContext *s,
  167. const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
  168. int y, int type, int height);
  169. /**
  170. * callback to negotiate the pixelFormat
  171. * @param fmt is the list of formats which are supported by the codec,
  172. * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
  173. * The first is always the native one.
  174. * @note The callback may be called again immediately if initialization for
  175. * the selected (hardware-accelerated) pixel format failed.
  176. * @warning Behavior is undefined if the callback returns a value not
  177. * in the fmt list of formats.
  178. * @return the chosen format
  179. * - encoding: unused
  180. * - decoding: Set by user, if not set the native format will be chosen.
  181. */
  182. enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt);
  183. // 非 B 帧之间的最大 B 帧数
  184. int max_b_frames;
  185. // IP 和 B 帧之间的 qscale 因子 如果 > 0,则将使用最后一个 P 帧量化器
  186. float b_quant_factor;
  187. #if FF_API_PRIVATE_OPT
  188. /** @deprecated use encoder private options instead */
  189. attribute_deprecated int b_frame_strategy;
  190. #endif
  191. // qscale offset between IP and B-frames
  192. float b_quant_offset;
  193. // 解码器中帧重新排序缓冲区的大小
  194. int has_b_frames;
  195. #if FF_API_PRIVATE_OPT
  196. /** @deprecated use encoder private options instead */
  197. attribute_deprecated int mpeg_quant;
  198. #endif
  199. /**
  200. * qscale factor between P- and I-frames
  201. * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset).
  202. * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
  203. * - encoding: Set by user.
  204. * - decoding: unused
  205. */
  206. float i_quant_factor;
  207. /**
  208. * qscale offset between P and I-frames
  209. * - encoding: Set by user.
  210. * - decoding: unused
  211. */
  212. float i_quant_offset;
  213. /**
  214. * luminance masking (0-> disabled)
  215. * - encoding: Set by user.
  216. * - decoding: unused
  217. */
  218. float lumi_masking;
  219. /**
  220. * temporary complexity masking (0-> disabled)
  221. * - encoding: Set by user.
  222. * - decoding: unused
  223. */
  224. float temporal_cplx_masking;
  225. /**
  226. * spatial complexity masking (0-> disabled)
  227. * - encoding: Set by user.
  228. * - decoding: unused
  229. */
  230. float spatial_cplx_masking;
  231. /**
  232. * p block masking (0-> disabled)
  233. * - encoding: Set by user.
  234. * - decoding: unused
  235. */
  236. float p_masking;
  237. /**
  238. * darkness masking (0-> disabled)
  239. * - encoding: Set by user.
  240. * - decoding: unused
  241. */
  242. float dark_masking;
  243. /**
  244. * slice count
  245. * - encoding: Set by libavcodec.
  246. * - decoding: Set by user (or 0).
  247. */
  248. int slice_count;
  249. #if FF_API_PRIVATE_OPT
  250. /** @deprecated use encoder private options instead */
  251. attribute_deprecated int prediction_method;
  252. #define FF_PRED_LEFT 0
  253. #define FF_PRED_PLANE 1
  254. #define FF_PRED_MEDIAN 2
  255. #endif
  256. /**
  257. * slice offsets in the frame in bytes
  258. * - encoding: Set/allocated by libavcodec.
  259. * - decoding: Set/allocated by user (or NULL).
  260. */
  261. int *slice_offset;
  262. /**
  263. * sample aspect ratio (0 if unknown)
  264. * That is the width of a pixel divided by the height of the pixel.
  265. * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
  266. * - encoding: Set by user.
  267. * - decoding: Set by libavcodec.
  268. */
  269. AVRational sample_aspect_ratio;
  270. /**
  271. * motion estimation comparison function
  272. * - encoding: Set by user.
  273. * - decoding: unused
  274. */
  275. int me_cmp;
  276. /**
  277. * subpixel motion estimation comparison function
  278. * - encoding: Set by user.
  279. * - decoding: unused
  280. */
  281. int me_sub_cmp;
  282. /**
  283. * macroblock comparison function (not supported yet)
  284. * - encoding: Set by user.
  285. * - decoding: unused
  286. */
  287. int mb_cmp;
  288. /**
  289. * interlaced DCT comparison function
  290. * - encoding: Set by user.
  291. * - decoding: unused
  292. */
  293. int ildct_cmp;
  294. #define FF_CMP_SAD 0
  295. #define FF_CMP_SSE 1
  296. #define FF_CMP_SATD 2
  297. #define FF_CMP_DCT 3
  298. #define FF_CMP_PSNR 4
  299. #define FF_CMP_BIT 5
  300. #define FF_CMP_RD 6
  301. #define FF_CMP_ZERO 7
  302. #define FF_CMP_VSAD 8
  303. #define FF_CMP_VSSE 9
  304. #define FF_CMP_NSSE 10
  305. #define FF_CMP_W53 11
  306. #define FF_CMP_W97 12
  307. #define FF_CMP_DCTMAX 13
  308. #define FF_CMP_DCT264 14
  309. #define FF_CMP_MEDIAN_SAD 15
  310. #define FF_CMP_CHROMA 256
  311. /**
  312. * ME diamond size & shape
  313. * - encoding: Set by user.
  314. * - decoding: unused
  315. */
  316. int dia_size;
  317. /**
  318. * amount of previous MV predictors (2a+1 x 2a+1 square)
  319. * - encoding: Set by user.
  320. * - decoding: unused
  321. */
  322. int last_predictor_count;
  323. #if FF_API_PRIVATE_OPT
  324. /** @deprecated use encoder private options instead */
  325. attribute_deprecated int pre_me;
  326. #endif
  327. /**
  328. * motion estimation prepass comparison function
  329. * - encoding: Set by user.
  330. * - decoding: unused
  331. */
  332. int me_pre_cmp;
  333. /**
  334. * ME prepass diamond size & shape
  335. * - encoding: Set by user.
  336. * - decoding: unused
  337. */
  338. int pre_dia_size;
  339. /**
  340. * subpel ME quality
  341. * - encoding: Set by user.
  342. * - decoding: unused
  343. */
  344. int me_subpel_quality;
  345. /**
  346. * maximum motion estimation search range in subpel units
  347. * If 0 then no limit.
  348. *
  349. * - encoding: Set by user.
  350. * - decoding: unused
  351. */
  352. int me_range;
  353. /**
  354. * slice flags
  355. * - encoding: unused
  356. * - decoding: Set by user.
  357. */
  358. int slice_flags;
  359. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  360. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG-2 field pics)
  361. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  362. /**
  363. * macroblock decision mode
  364. * - encoding: Set by user.
  365. * - decoding: unused
  366. */
  367. int mb_decision;
  368. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  369. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  370. #define FF_MB_DECISION_RD 2 ///< rate distortion
  371. /**
  372. * custom intra quantization matrix
  373. * Must be allocated with the av_malloc() family of functions, and will be freed in
  374. * avcodec_free_context().
  375. * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  376. * - decoding: Set/allocated/freed by libavcodec.
  377. */
  378. uint16_t *intra_matrix;
  379. /**
  380. * custom inter quantization matrix
  381. * Must be allocated with the av_malloc() family of functions, and will be freed in
  382. * avcodec_free_context().
  383. * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
  384. * - decoding: Set/allocated/freed by libavcodec.
  385. */
  386. uint16_t *inter_matrix;
  387. #if FF_API_PRIVATE_OPT
  388. /** @deprecated use encoder private options instead */
  389. attribute_deprecated int scenechange_threshold;
  390. /** @deprecated use encoder private options instead */
  391. attribute_deprecated int noise_reduction;
  392. #endif
  393. /**
  394. * precision of the intra DC coefficient - 8
  395. * - encoding: Set by user.
  396. * - decoding: Set by libavcodec
  397. */
  398. int intra_dc_precision;
  399. /**
  400. * Number of macroblock rows at the top which are skipped.
  401. * - encoding: unused
  402. * - decoding: Set by user.
  403. */
  404. int skip_top;
  405. /**
  406. * Number of macroblock rows at the bottom which are skipped.
  407. * - encoding: unused
  408. * - decoding: Set by user.
  409. */
  410. int skip_bottom;
  411. /**
  412. * minimum MB Lagrange multiplier
  413. * - encoding: Set by user.
  414. * - decoding: unused
  415. */
  416. int mb_lmin;
  417. /**
  418. * maximum MB Lagrange multiplier
  419. * - encoding: Set by user.
  420. * - decoding: unused
  421. */
  422. int mb_lmax;
  423. #if FF_API_PRIVATE_OPT
  424. /**
  425. * @deprecated use encoder private options instead
  426. */
  427. attribute_deprecated int me_penalty_compensation;
  428. #endif
  429. /**
  430. * - encoding: Set by user.
  431. * - decoding: unused
  432. */
  433. int bidir_refine;
  434. #if FF_API_PRIVATE_OPT
  435. /** @deprecated use encoder private options instead */
  436. attribute_deprecated int brd_scale;
  437. #endif
  438. /**
  439. * minimum GOP size
  440. * - encoding: Set by user.
  441. * - decoding: unused
  442. */
  443. int keyint_min;
  444. /**
  445. * number of reference frames
  446. * - encoding: Set by user.
  447. * - decoding: Set by lavc.
  448. */
  449. int refs;
  450. #if FF_API_PRIVATE_OPT
  451. /** @deprecated use encoder private options instead */
  452. attribute_deprecated int chromaoffset;
  453. #endif
  454. /**
  455. * Note: Value depends upon the compare function used for fullpel ME.
  456. * - encoding: Set by user.
  457. * - decoding: unused
  458. */
  459. int mv0_threshold;
  460. #if FF_API_PRIVATE_OPT
  461. /** @deprecated use encoder private options instead */
  462. attribute_deprecated int b_sensitivity;
  463. #endif
  464. /**
  465. * Chromaticity coordinates of the source primaries.
  466. * - encoding: Set by user
  467. * - decoding: Set by libavcodec
  468. */
  469. enum AVColorPrimaries color_primaries;
  470. /**
  471. * Color Transfer Characteristic.
  472. * - encoding: Set by user
  473. * - decoding: Set by libavcodec
  474. */
  475. enum AVColorTransferCharacteristic color_trc;
  476. /**
  477. * YUV colorspace type.
  478. * - encoding: Set by user
  479. * - decoding: Set by libavcodec
  480. */
  481. enum AVColorSpace colorspace;
  482. /**
  483. * MPEG vs JPEG YUV range.
  484. * - encoding: Set by user
  485. * - decoding: Set by libavcodec
  486. */
  487. enum AVColorRange color_range;
  488. /**
  489. * This defines the location of chroma samples.
  490. * - encoding: Set by user
  491. * - decoding: Set by libavcodec
  492. */
  493. enum AVChromaLocation chroma_sample_location;
  494. /**
  495. * Number of slices.
  496. * Indicates number of picture subdivisions. Used for parallelized
  497. * decoding.
  498. * - encoding: Set by user
  499. * - decoding: unused
  500. */
  501. int slices;
  502. /** Field order
  503. * - encoding: set by libavcodec
  504. * - decoding: Set by user.
  505. */
  506. enum AVFieldOrder field_order;
  507. /* audio only */
  508. int sample_rate; ///< samples per second
  509. int channels; ///< number of audio channels
  510. /**
  511. * audio sample format
  512. * - encoding: Set by user.
  513. * - decoding: Set by libavcodec.
  514. */
  515. enum AVSampleFormat sample_fmt; ///< sample format
  516. /* The following data should not be initialized. */
  517. /**
  518. * Number of samples per channel in an audio frame.
  519. *
  520. * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
  521. * except the last must contain exactly frame_size samples per channel.
  522. * May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
  523. * frame size is not restricted.
  524. * - decoding: may be set by some decoders to indicate constant frame size
  525. */
  526. int frame_size;
  527. /**
  528. * Frame counter, set by libavcodec.
  529. *
  530. * - decoding: total number of frames returned from the decoder so far.
  531. * - encoding: total number of frames passed to the encoder so far.
  532. *
  533. * @note the counter is not incremented if encoding/decoding resulted in
  534. * an error.
  535. */
  536. int frame_number;
  537. /**
  538. * number of bytes per packet if constant and known or 0
  539. * Used by some WAV based audio codecs.
  540. */
  541. int block_align;
  542. /**
  543. * Audio cutoff bandwidth (0 means "automatic")
  544. * - encoding: Set by user.
  545. * - decoding: unused
  546. */
  547. int cutoff;
  548. /**
  549. * Audio channel layout.
  550. * - encoding: set by user.
  551. * - decoding: set by user, may be overwritten by libavcodec.
  552. */
  553. uint64_t channel_layout;
  554. /**
  555. * Request decoder to use this channel layout if it can (0 for default)
  556. * - encoding: unused
  557. * - decoding: Set by user.
  558. */
  559. uint64_t request_channel_layout;
  560. /**
  561. * Type of service that the audio stream conveys.
  562. * - encoding: Set by user.
  563. * - decoding: Set by libavcodec.
  564. */
  565. enum AVAudioServiceType audio_service_type;
  566. /**
  567. * desired sample format
  568. * - encoding: Not used.
  569. * - decoding: Set by user.
  570. * Decoder will decode to this format if it can.
  571. */
  572. enum AVSampleFormat request_sample_fmt;
  573. /**
  574. * This callback is called at the beginning of each frame to get data
  575. * buffer(s) for it. There may be one contiguous buffer for all the data or
  576. * there may be a buffer per each data plane or anything in between. What
  577. * this means is, you may set however many entries in buf[] you feel necessary.
  578. * Each buffer must be reference-counted using the AVBuffer API (see description
  579. * of buf[] below).
  580. *
  581. * The following fields will be set in the frame before this callback is
  582. * called:
  583. * - format
  584. * - width, height (video only)
  585. * - sample_rate, channel_layout, nb_samples (audio only)
  586. * Their values may differ from the corresponding values in
  587. * AVCodecContext. This callback must use the frame values, not the codec
  588. * context values, to calculate the required buffer size.
  589. *
  590. * This callback must fill the following fields in the frame:
  591. * - data[]
  592. * - linesize[]
  593. * - extended_data:
  594. * * if the data is planar audio with more than 8 channels, then this
  595. * callback must allocate and fill extended_data to contain all pointers
  596. * to all data planes. data[] must hold as many pointers as it can.
  597. * extended_data must be allocated with av_malloc() and will be freed in
  598. * av_frame_unref().
  599. * * otherwise extended_data must point to data
  600. * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
  601. * the frame's data and extended_data pointers must be contained in these. That
  602. * is, one AVBufferRef for each allocated chunk of memory, not necessarily one
  603. * AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
  604. * and av_buffer_ref().
  605. * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
  606. * this callback and filled with the extra buffers if there are more
  607. * buffers than buf[] can hold. extended_buf will be freed in
  608. * av_frame_unref().
  609. *
  610. * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call
  611. * avcodec_default_get_buffer2() instead of providing buffers allocated by
  612. * some other means.
  613. *
  614. * Each data plane must be aligned to the maximum required by the target
  615. * CPU.
  616. *
  617. * @see avcodec_default_get_buffer2()
  618. *
  619. * Video:
  620. *
  621. * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
  622. * (read and/or written to if it is writable) later by libavcodec.
  623. *
  624. * avcodec_align_dimensions2() should be used to find the required width and
  625. * height, as they normally need to be rounded up to the next multiple of 16.
  626. *
  627. * Some decoders do not support linesizes changing between frames.
  628. *
  629. * If frame multithreading is used, this callback may be called from a
  630. * different thread, but not from more than one at once. Does not need to be
  631. * reentrant.
  632. *
  633. * @see avcodec_align_dimensions2()
  634. *
  635. * Audio:
  636. *
  637. * Decoders request a buffer of a particular size by setting
  638. * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
  639. * however, utilize only part of the buffer by setting AVFrame.nb_samples
  640. * to a smaller value in the output frame.
  641. *
  642. * As a convenience, av_samples_get_buffer_size() and
  643. * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
  644. * functions to find the required data size and to fill data pointers and
  645. * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
  646. * since all planes must be the same size.
  647. *
  648. * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
  649. *
  650. * - encoding: unused
  651. * - decoding: Set by libavcodec, user can override.
  652. */
  653. int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags);
  654. #if FF_API_OLD_ENCDEC
  655. /**
  656. * If non-zero, the decoded audio and video frames returned from
  657. * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted
  658. * and are valid indefinitely. The caller must free them with
  659. * av_frame_unref() when they are not needed anymore.
  660. * Otherwise, the decoded frames must not be freed by the caller and are
  661. * only valid until the next decode call.
  662. *
  663. * This is always automatically enabled if avcodec_receive_frame() is used.
  664. *
  665. * - encoding: unused
  666. * - decoding: set by the caller before avcodec_open2().
  667. */
  668. attribute_deprecated int refcounted_frames;
  669. #endif
  670. /* - encoding parameters */
  671. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  672. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  673. /**
  674. * minimum quantizer
  675. * - encoding: Set by user.
  676. * - decoding: unused
  677. */
  678. int qmin;
  679. /**
  680. * maximum quantizer
  681. * - encoding: Set by user.
  682. * - decoding: unused
  683. */
  684. int qmax;
  685. /**
  686. * maximum quantizer difference between frames
  687. * - encoding: Set by user.
  688. * - decoding: unused
  689. */
  690. int max_qdiff;
  691. /**
  692. * decoder bitstream buffer size
  693. * - encoding: Set by user.
  694. * - decoding: unused
  695. */
  696. int rc_buffer_size;
  697. /**
  698. * ratecontrol override, see RcOverride
  699. * - encoding: Allocated/set/freed by user.
  700. * - decoding: unused
  701. */
  702. int rc_override_count;
  703. RcOverride *rc_override;
  704. /**
  705. * maximum bitrate
  706. * - encoding: Set by user.
  707. * - decoding: Set by user, may be overwritten by libavcodec.
  708. */
  709. int64_t rc_max_rate;
  710. /**
  711. * minimum bitrate
  712. * - encoding: Set by user.
  713. * - decoding: unused
  714. */
  715. int64_t rc_min_rate;
  716. /**
  717. * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
  718. * - encoding: Set by user.
  719. * - decoding: unused.
  720. */
  721. float rc_max_available_vbv_use;
  722. /**
  723. * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
  724. * - encoding: Set by user.
  725. * - decoding: unused.
  726. */
  727. float rc_min_vbv_overflow_use;
  728. /**
  729. * Number of bits which should be loaded into the rc buffer before decoding starts.
  730. * - encoding: Set by user.
  731. * - decoding: unused
  732. */
  733. int rc_initial_buffer_occupancy;
  734. #if FF_API_CODER_TYPE
  735. #define FF_CODER_TYPE_VLC 0
  736. #define FF_CODER_TYPE_AC 1
  737. #define FF_CODER_TYPE_RAW 2
  738. #define FF_CODER_TYPE_RLE 3
  739. /**
  740. * @deprecated use encoder private options instead
  741. */
  742. attribute_deprecated int coder_type;
  743. #endif /* FF_API_CODER_TYPE */
  744. #if FF_API_PRIVATE_OPT
  745. /** @deprecated use encoder private options instead */
  746. attribute_deprecated int context_model;
  747. #endif
  748. #if FF_API_PRIVATE_OPT
  749. /** @deprecated use encoder private options instead */
  750. attribute_deprecated int frame_skip_threshold;
  751. /** @deprecated use encoder private options instead */
  752. attribute_deprecated int frame_skip_factor;
  753. /** @deprecated use encoder private options instead */
  754. attribute_deprecated int frame_skip_exp;
  755. /** @deprecated use encoder private options instead */
  756. attribute_deprecated int frame_skip_cmp;
  757. #endif /* FF_API_PRIVATE_OPT */
  758. /**
  759. * trellis RD quantization
  760. * - encoding: Set by user.
  761. * - decoding: unused
  762. */
  763. int trellis;
  764. #if FF_API_PRIVATE_OPT
  765. /** @deprecated use encoder private options instead */
  766. attribute_deprecated int min_prediction_order;
  767. /** @deprecated use encoder private options instead */
  768. attribute_deprecated int max_prediction_order;
  769. /** @deprecated use encoder private options instead */
  770. attribute_deprecated
  771. int64_t timecode_frame_start;
  772. #endif
  773. #if FF_API_RTP_CALLBACK
  774. /**
  775. * @deprecated unused
  776. */
  777. /* The RTP callback: This function is called */
  778. /* every time the encoder has a packet to send. */
  779. /* It depends on the encoder if the data starts */
  780. /* with a Start Code (it should). H.263 does. */
  781. /* mb_nb contains the number of macroblocks */
  782. /* encoded in the RTP payload. */
  783. attribute_deprecated void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
  784. #endif
  785. #if FF_API_PRIVATE_OPT
  786. /** @deprecated use encoder private options instead */
  787. attribute_deprecated int rtp_payload_size; /* The size of the RTP payload: the coder will */
  788. /* do its best to deliver a chunk with size */
  789. /* below rtp_payload_size, the chunk will start */
  790. /* with a start code on some codecs like H.263. */
  791. /* This doesn't take account of any particular */
  792. /* headers inside the transmitted RTP payload. */
  793. #endif
  794. #if FF_API_STAT_BITS
  795. /* statistics, used for 2-pass encoding */
  796. attribute_deprecated int mv_bits;
  797. attribute_deprecated int header_bits;
  798. attribute_deprecated int i_tex_bits;
  799. attribute_deprecated int p_tex_bits;
  800. attribute_deprecated int i_count;
  801. attribute_deprecated int p_count;
  802. attribute_deprecated int skip_count;
  803. attribute_deprecated int misc_bits;
  804. /** @deprecated this field is unused */
  805. attribute_deprecated int frame_bits;
  806. #endif
  807. /**
  808. * pass1 encoding statistics output buffer
  809. * - encoding: Set by libavcodec.
  810. * - decoding: unused
  811. */
  812. char *stats_out;
  813. /**
  814. * pass2 encoding statistics input buffer
  815. * Concatenated stuff from stats_out of pass1 should be placed here.
  816. * - encoding: Allocated/set/freed by user.
  817. * - decoding: unused
  818. */
  819. char *stats_in;
  820. /**
  821. * Work around bugs in encoders which sometimes cannot be detected automatically.
  822. * - encoding: Set by user
  823. * - decoding: Set by user
  824. */
  825. int workaround_bugs;
  826. #define FF_BUG_AUTODETECT 1 ///< autodetection
  827. #define FF_BUG_XVID_ILACE 4
  828. #define FF_BUG_UMP4 8
  829. #define FF_BUG_NO_PADDING 16
  830. #define FF_BUG_AMV 32
  831. #define FF_BUG_QPEL_CHROMA 64
  832. #define FF_BUG_STD_QPEL 128
  833. #define FF_BUG_QPEL_CHROMA2 256
  834. #define FF_BUG_DIRECT_BLOCKSIZE 512
  835. #define FF_BUG_EDGE 1024
  836. #define FF_BUG_HPEL_CHROMA 2048
  837. #define FF_BUG_DC_CLIP 4096
  838. #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
  839. #define FF_BUG_TRUNCATED 16384
  840. #define FF_BUG_IEDGE 32768
  841. /**
  842. * strictly follow the standard (MPEG-4, ...).
  843. * - encoding: Set by user.
  844. * - decoding: Set by user.
  845. * Setting this to STRICT or higher means the encoder and decoder will
  846. * generally do stupid things, whereas setting it to unofficial or lower
  847. * will mean the encoder might produce output that is not supported by all
  848. * spec-compliant decoders. Decoders don't differentiate between normal,
  849. * unofficial and experimental (that is, they always try to decode things
  850. * when they can) unless they are explicitly asked to behave stupidly
  851. * (=strictly conform to the specs)
  852. */
  853. int strict_std_compliance;
  854. #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
  855. #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
  856. #define FF_COMPLIANCE_NORMAL 0
  857. #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
  858. #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
  859. /**
  860. * error concealment flags
  861. * - encoding: unused
  862. * - decoding: Set by user.
  863. */
  864. int error_concealment;
  865. #define FF_EC_GUESS_MVS 1
  866. #define FF_EC_DEBLOCK 2
  867. #define FF_EC_FAVOR_INTER 256
  868. /**
  869. * debug
  870. * - encoding: Set by user.
  871. * - decoding: Set by user.
  872. */
  873. int debug;
  874. #define FF_DEBUG_PICT_INFO 1
  875. #define FF_DEBUG_RC 2
  876. #define FF_DEBUG_BITSTREAM 4
  877. #define FF_DEBUG_MB_TYPE 8
  878. #define FF_DEBUG_QP 16
  879. #define FF_DEBUG_DCT_COEFF 0x00000040
  880. #define FF_DEBUG_SKIP 0x00000080
  881. #define FF_DEBUG_STARTCODE 0x00000100
  882. #define FF_DEBUG_ER 0x00000400
  883. #define FF_DEBUG_MMCO 0x00000800
  884. #define FF_DEBUG_BUGS 0x00001000
  885. #define FF_DEBUG_BUFFERS 0x00008000
  886. #define FF_DEBUG_THREADS 0x00010000
  887. #define FF_DEBUG_GREEN_MD 0x00800000
  888. #define FF_DEBUG_NOMC 0x01000000
  889. /**
  890. * Error recognition; may misdetect some more or less valid parts as errors.
  891. * - encoding: Set by user.
  892. * - decoding: Set by user.
  893. */
  894. int err_recognition;
  895. /**
  896. * Verify checksums embedded in the bitstream (could be of either encoded or
  897. * decoded data, depending on the codec) and print an error message on mismatch.
  898. * If AV_EF_EXPLODE is also set, a mismatching checksum will result in the
  899. * decoder returning an error.
  900. */
  901. #define AV_EF_CRCCHECK (1 << 0)
  902. #define AV_EF_BITSTREAM (1 << 1) ///< detect bitstream specification deviations
  903. #define AV_EF_BUFFER (1 << 2) ///< detect improper bitstream length
  904. #define AV_EF_EXPLODE (1 << 3) ///< abort decoding on minor error detection
  905. #define AV_EF_IGNORE_ERR (1 << 15) ///< ignore errors and continue
  906. #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
  907. #define AV_EF_COMPLIANT (1 << 17) ///< consider all spec non compliances as errors
  908. #define AV_EF_AGGRESSIVE (1 << 18) ///< consider things that a sane encoder should not do as an error
  909. /**
  910. * opaque 64-bit number (generally a PTS) that will be reordered and
  911. * output in AVFrame.reordered_opaque
  912. * - encoding: Set by libavcodec to the reordered_opaque of the input
  913. * frame corresponding to the last returned packet. Only
  914. * supported by encoders with the
  915. * AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability.
  916. * - decoding: Set by user.
  917. */
  918. int64_t reordered_opaque;
  919. /**
  920. * Hardware accelerator in use
  921. * - encoding: unused.
  922. * - decoding: Set by libavcodec
  923. */
  924. // 硬件加速的器正在使用的
  925. const struct AVHWAccel *hwaccel;
  926. /**
  927. * Hardware accelerator context.
  928. * For some hardware accelerators, a global context needs to be
  929. * provided by the user. In that case, this holds display-dependent
  930. * data FFmpeg cannot instantiate itself. Please refer to the
  931. * FFmpeg HW accelerator documentation to know how to fill this
  932. * is. e.g. for VA API, this is a struct vaapi_context.
  933. * - encoding: unused
  934. * - decoding: Set by user
  935. */
  936. // 加速器上下文
  937. void *hwaccel_context;
  938. /**
  939. * error
  940. * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
  941. * - decoding: unused
  942. */
  943. uint64_t error[AV_NUM_DATA_POINTERS];
  944. /**
  945. * DCT algorithm, see FF_DCT_* below
  946. * - encoding: Set by user.
  947. * - decoding: unused
  948. */
  949. int dct_algo;
  950. #define FF_DCT_AUTO 0
  951. #define FF_DCT_FASTINT 1
  952. #define FF_DCT_INT 2
  953. #define FF_DCT_MMX 3
  954. #define FF_DCT_ALTIVEC 5
  955. #define FF_DCT_FAAN 6
  956. /**
  957. * IDCT algorithm, see FF_IDCT_* below.
  958. * - encoding: Set by user.
  959. * - decoding: Set by user.
  960. */
  961. int idct_algo;
  962. #define FF_IDCT_AUTO 0
  963. #define FF_IDCT_INT 1
  964. #define FF_IDCT_SIMPLE 2
  965. #define FF_IDCT_SIMPLEMMX 3
  966. #define FF_IDCT_ARM 7
  967. #define FF_IDCT_ALTIVEC 8
  968. #define FF_IDCT_SIMPLEARM 10
  969. #define FF_IDCT_XVID

 AVStream

 其中AVStream是存储每一个视频/音频流信息的结构体

  1. typedef struct AVStream
  2. {
  3. // 流的索引在
  4. int index; /**< stream index in AVFormatContext */
  5. /**
  6. * Format-specific stream ID.
  7. * decoding: set by libavformat
  8. * encoding: set by the user, replaced by libavformat if left unset
  9. */
  10. // 流的id
  11. int id;
  12. #if FF_API_LAVF_AVCTX
  13. /**
  14. * @deprecated use the codecpar struct instead
  15. */
  16. attribute_deprecated
  17. // 封装和解码器耦合在一起
  18. AVCodecContext *codec;
  19. #endif
  20. // 私有数据
  21. void *priv_data;
  22. // 时间基
  23. AVRational time_base;
  24. // 第一帧的显示时间
  25. int64_t start_time;
  26. // 该视频或者音频的数据长度
  27. int64_t duration;
  28. // 数据帧的多长
  29. int64_t nb_frames; ///< number of frames in this stream if known or 0
  30. // 去除的数据帧的位置
  31. int disposition; /**< AV_DISPOSITION_* bit field */
  32. // 哪一个数据帧被抛弃
  33. enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
  34. /**
  35. * sample aspect ratio (0 if unknown)
  36. * - encoding: Set by user.
  37. * - decoding: Set by libavformat.
  38. */
  39. // 样本比特率
  40. AVRational sample_aspect_ratio;
  41. // 元数据
  42. AVDictionary *metadata;
  43. /**
  44. * Average framerate
  45. *
  46. * - demuxing: May be set by libavformat when creating the stream or in
  47. * avformat_find_stream_info().
  48. * - muxing: May be set by the caller before avformat_write_header().
  49. */
  50. AVRational avg_frame_rate;
  51. /**
  52. * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
  53. * will contain the attached picture.
  54. *
  55. * decoding: set by libavformat, must not be modified by the caller.
  56. * encoding: unused
  57. */
  58. AVPacket attached_pic;
  59. /**
  60. * An array of side data that applies to the whole stream (i.e. the
  61. * container does not allow it to change between packets).
  62. *
  63. * There may be no overlap between the side data in this array and side data
  64. * in the packets. I.e. a given side data is either exported by the muxer
  65. * (demuxing) / set by the caller (muxing) in this array, then it never
  66. * appears in the packets, or the side data is exported / sent through
  67. * the packets (always in the first packet where the value becomes known or
  68. * changes), then it does not appear in this array.
  69. *
  70. * - demuxing: Set by libavformat when the stream is created.
  71. * - muxing: May be set by the caller before avformat_write_header().
  72. *
  73. * Freed by libavformat in avformat_free_context().
  74. *
  75. * @see av_format_inject_global_side_data()
  76. */
  77. AVPacketSideData *side_data;
  78. /**
  79. * The number of elements in the AVStream.side_data array.
  80. */
  81. int nb_side_data;
  82. /**
  83. * Flags indicating events happening on the stream, a combination of
  84. * AVSTREAM_EVENT_FLAG_*.
  85. *
  86. * - demuxing: may be set by the demuxer in avformat_open_input(),
  87. * avformat_find_stream_info() and av_read_frame(). Flags must be cleared
  88. * by the user once the event has been handled.
  89. * - muxing: may be set by the user after avformat_write_header(). to
  90. * indicate a user-triggered event. The muxer will clear the flags for
  91. * events it has handled in av_[interleaved]_write_frame().
  92. */
  93. int event_flags;
  94. /**
  95. * - demuxing: the demuxer read new metadata from the file and updated
  96. * AVStream.metadata accordingly
  97. * - muxing: the user updated AVStream.metadata and wishes the muxer to write
  98. * it into the file
  99. */
  100. #define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001
  101. /**
  102. * - demuxing: new packets for this stream were read from the file. This
  103. * event is informational only and does not guarantee that new packets
  104. * for this stream will necessarily be returned from av_read_frame().
  105. */
  106. #define AVSTREAM_EVENT_FLAG_NEW_PACKETS (1 << 1)
  107. /**
  108. * Real base framerate of the stream.
  109. * This is the lowest framerate with which all timestamps can be
  110. * represented accurately (it is the least common multiple of all
  111. * framerates in the stream). Note, this value is just a guess!
  112. * For example, if the time base is 1/90000 and all frames have either
  113. * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
  114. */
  115. AVRational r_frame_rate;
  116. #if FF_API_LAVF_FFSERVER
  117. /**
  118. * String containing pairs of key and values describing recommended encoder configuration.
  119. * Pairs are separated by ','.
  120. * Keys are separated from values by '='.
  121. *
  122. * @deprecated unused
  123. */
  124. attribute_deprecated char *recommended_encoder_configuration;
  125. #endif
  126. /**
  127. * Codec parameters associated with this stream. Allocated and freed by
  128. * libavformat in avformat_new_stream() and avformat_free_context()
  129. * respectively.
  130. *
  131. * - demuxing: filled by libavformat on stream creation or in
  132. * avformat_find_stream_info()
  133. * - muxing: filled by the caller before avformat_write_header()
  134. */
  135. AVCodecParameters *codecpar;
  136. /*****************************************************************
  137. * All fields below this line are not part of the public API. They
  138. * may not be used outside of libavformat and can be changed and
  139. * removed at will.
  140. * Internal note: be aware that physically removing these fields
  141. * will break ABI. Replace removed fields with dummy fields, and
  142. * add new fields to AVStreamInternal.
  143. *****************************************************************
  144. */
  145. #if LIBAVFORMAT_VERSION_MAJOR < 59
  146. // kept for ABI compatibility only, do not access in any way
  147. void *unused;
  148. #endif
  149. int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
  150. // Timestamp generation support:
  151. /**
  152. * Timestamp corresponding to the last dts sync point.
  153. *
  154. * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
  155. * a DTS is received from the underlying container. Otherwise set to
  156. * AV_NOPTS_VALUE by default.
  157. */
  158. int64_t first_dts;
  159. int64_t cur_dts;
  160. int64_t last_IP_pts;
  161. int last_IP_duration;
  162. /**
  163. * Number of packets to buffer for codec probing
  164. */
  165. int probe_packets;
  166. /**
  167. * Number of frames that have been demuxed during avformat_find_stream_info()
  168. */
  169. int codec_info_nb_frames;
  170. /* av_read_frame() support */
  171. enum AVStreamParseType need_parsing;
  172. struct AVCodecParserContext *parser;
  173. #if LIBAVFORMAT_VERSION_MAJOR < 59
  174. // kept for ABI compatibility only, do not access in any way
  175. void *unused7;
  176. AVProbeData unused6;
  177. int64_t unused5[16 + 1];
  178. #endif
  179. AVIndexEntry *index_entries; /**< Only used if the format does not
  180. support seeking natively. */
  181. int nb_index_entries;
  182. unsigned int index_entries_allocated_size;
  183. /**
  184. * Stream Identifier
  185. * This is the MPEG-TS stream identifier +1
  186. * 0 means unknown
  187. */
  188. int stream_identifier;
  189. #if LIBAVFORMAT_VERSION_MAJOR < 59
  190. // kept for ABI compatibility only, do not access in any way
  191. int unused8;
  192. int unused9;
  193. int unused10;
  194. #endif
  195. /**
  196. * An opaque field for libavformat internal usage.
  197. * Must not be accessed in any way by callers.
  198. */
  199. AVStreamInternal *internal;
  200. } AVStream;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/65302
推荐阅读
相关标签
  

闽ICP备14008679号