zoukankan      html  css  js  c++  java
  • ffmpeg 基本数据结构和对象(一): AVPacket、AVPicture、AVFrame

    来源:http://blog.csdn.net/chance_yin/article/details/16817957

    一、AVPacket

    1. /** 
    2.  * AVPacket 作为解码器的输入 或 编码器的输出。 
    3.  * 当作为解码器的输入时,它由demuxer生成,然后传递给解码器 
    4.  * 当作为编码器的输出时,由编码器生成,然后传递给muxer 
    5.  * 在视频中,AVPacket 只能包含不大于1帧的内容,而视频的1帧可能要包含在多个AVPacket中,AVPacket < AVFrame 
    6.  *  
    7.  * 
    8.  * AVPacket 是ffmpeg中少数的几个公共ABI,它只能被libavcodec和libformat在栈上分配 
    9.  * 
    10.  * The side data is always allocated with av_malloc() and is freed in 
    11.  * av_free_packet(). 
    12.  */  
    13. typedef struct AVPacket {  
    14.     /** 
    15.      * packet的内存空间来自于一个叫做“引用计数缓冲区”的地方,这个指针就指向一块引用计数缓冲区 
    16.      */  
    17.     AVBufferRef *buf;  
    18.     /** 
    19.      * 显示时间戳 单位是 AVStream->time_base units 
    20.      */  
    21.     int64_t pts;  
    22.     /** 
    23.      * 解压时间戳,在这个时刻该包需要被解码 
    24.      */  
    25.     int64_t dts;  
    26.     uint8_t *data;  
    27.     int   size;  
    28.     int   stream_index;  
    29.     /** 
    30.      * A combination of AV_PKT_FLAG values 
    31.      */  
    32.     int   flags;  
    33.     /** 
    34.      * 存放额外的包信息 
    35.      */  
    36.     struct {  
    37.         uint8_t *data;  
    38.         int      size;  
    39.         enum AVPacketSideDataType type;  
    40.     } *side_data;  
    41.     int side_data_elems;  
    42.   
    43.     /** 
    44.      * 这个包的时间长度 in AVStream->time_base units, 设置0 表示未知. 
    45.      * duration = next_pts - this_pts i. 
    46.      */  
    47.     int   duration;  
    48.   
    49.     int64_t pos;                            ///< 在数据流中的字节偏移量, -1 if unknown  
    50.   
    51.     int64_t convergence_duration;  
    52. } AVPacket;  


    二、AVPicture

    1. typedef struct AVPicture {  
    2.     uint8_t *data[AV_NUM_DATA_POINTERS];    ///< pointers to the image data planes  
    3.     int linesize[AV_NUM_DATA_POINTERS];     ///< number of bytes per line  
    4. }  


    三、AVFrame

      1. /** 
      2.  * AVFrame表示解码过后的一个数据帧 
      3.  * 
      4.  * AVFrame 通过使用 av_frame_alloc()来创建. 这个函数只是创建了AVFrame结构本身,在结构 
      5.  * 中定义的指向其他内存块的缓冲区指针要用其他方法来分配 
      6.  * 使用 av_frame_free()来释放AVFrame. 
      7.  * 
      8.  */  
      9. typedef struct AVFrame {  
      10. #define AV_NUM_DATA_POINTERS 8  
      11.     /** 
      12.      * pointer to the picture/channel planes. 
      13.      */  
      14.     uint8_t *data[AV_NUM_DATA_POINTERS];  
      15.   
      16.     /** 
      17.      * For video, size in bytes of each picture line. 
      18.      * For audio, size in bytes of each plane. 
      19.      */  
      20.     int linesize[AV_NUM_DATA_POINTERS];  
      21.   
      22.     /** 
      23.      * pointers to the data planes/channels. 
      24.      */  
      25.     uint8_t **extended_data;  
      26.   
      27.     /** 
      28.      * width and height of the video frame 
      29.      */  
      30.     int width, height;  
      31.   
      32.     /** 
      33.      * number of audio samples (per channel) described by this frame 
      34.      */  
      35.     int nb_samples;  
      36.   
      37.     /** 
      38.      * format of the frame, -1 if unknown or unset 
      39.      */  
      40.     int format;  
      41.   
      42.     /** 
      43.      * 1 -> keyframe, 0-> not 
      44.      */  
      45.     int key_frame;  
      46.   
      47.     /** 
      48.      * Picture type of the frame. 
      49.      */  
      50.     enum AVPictureType pict_type;  
      51.   
      52.     /** 
      53.      * Sample aspect ratio for the video frame, 0/1 if unknown/unspecified. 
      54.      */  
      55.     AVRational sample_aspect_ratio;  
      56.   
      57.     /** 
      58.      * Presentation timestamp in time_base units (time when frame should be shown to user). 
      59.      */  
      60.     int64_t pts;  
      61.   
      62.     /** 
      63.      * PTS copied from the AVPacket that was decoded to produce this frame. 
      64.      */  
      65.     int64_t pkt_pts;  
      66.   
      67.     /** 
      68.      * DTS copied from the AVPacket that triggered returning this frame. (if frame threading isnt used) 
      69.      * This is also the Presentation time of this AVFrame calculated from 
      70.      * only AVPacket.dts values without pts values. 
      71.      */  
      72.     int64_t pkt_dts;  
      73.   
      74.     /** 
      75.      * picture number in bitstream order 
      76.      */  
      77.     int coded_picture_number;  
      78.     /** 
      79.      * picture number in display order 
      80.      */  
      81.     int display_picture_number;  
      82.   
      83.     /** 
      84.      * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) 
      85.      */  
      86.     int quality;  
      87.   
      88.     /** 
      89.      * for some private data of the user 
      90.      */  
      91.     void *opaque;  
      92.   
      93.     /** 
      94.      * error 
      95.      */  
      96.     uint64_t error[AV_NUM_DATA_POINTERS];  
      97.   
      98.     /** 
      99.      * When decoding, this signals how much the picture must be delayed. 
      100.      * extra_delay = repeat_pict / (2*fps) 
      101.      */  
      102.     int repeat_pict;  
      103.   
      104.     /** 
      105.      * The content of the picture is interlaced. 
      106.      */  
      107.     int interlaced_frame;  
      108.   
      109.     /** 
      110.      * If the content is interlaced, is top field displayed first. 
      111.      */  
      112.     int top_field_first;  
      113.   
      114.     /** 
      115.      * Tell user application that palette has changed from previous frame. 
      116.      */  
      117.     int palette_has_changed;  
      118.   
      119.     /** 
      120.      * Sample rate of the audio data. 
      121.      */  
      122.     int sample_rate;  
      123.   
      124.     /** 
      125.      * Channel layout of the audio data. 
      126.      */  
      127.     uint64_t channel_layout;  
      128.   
      129.     /** 
      130.      * 指向这个帧要用到的AVBuffer中的数据缓冲区. 
      131.      * 
      132.      * 一般每个图像位面(就时data[0],data[1] data[2])只有一个指向AVBuffer的缓冲区, so for video this array 
      133.      * always contains all the references. For planar audio with more than 
      134.      * AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in 
      135.      * this array. Then the extra AVBufferRef pointers are stored in the 
      136.      * extended_buf array. 
      137.      */  
      138.     AVBufferRef *buf[AV_NUM_DATA_POINTERS];  
      139.   
      140.     /** 
      141.      * For planar audio which requires more than AV_NUM_DATA_POINTERS 
      142.      * AVBufferRef pointers, this array will hold all the references which 
      143.      * cannot fit into AVFrame.buf. 
      144.      */  
      145.     AVBufferRef **extended_buf;  
      146.     /** 
      147.      * Number of elements in extended_buf. 
      148.      */  
      149.     int        nb_extended_buf;  
      150.   
      151.     AVFrameSideData **side_data;  
      152.     int            nb_side_data;  
      153.   
      154. /** 
      155.  * 可能因为解码错误,数据帧Frame会成为无效的帧,下面的结构就是当数据帧无效时使用的 
      156.  */  
      157. #define AV_FRAME_FLAG_CORRUPT       (1 << 0)  
      158.   
      159.     /** 
      160.      * Frame flags, a combination of AV_FRAME_FLAG_* 
      161.      */  
      162.     int flags;  
      163.   
      164.       
      165.     int64_t best_effort_timestamp;  
      166.   
      167.      
      168.     int64_t pkt_pos;  
      169.   
      170.       
      171.     int64_t pkt_duration;  
      172.   
      173.      
      174.     AVDictionary *metadata;  
      175.   
      176.       
      177.     int decode_error_flags;  
      178. #define FF_DECODE_ERROR_INVALID_BITSTREAM   1  
      179. #define FF_DECODE_ERROR_MISSING_REFERENCE   2  
      180.   
      181.      
      182.     int channels;  
      183.   
      184.       
      185.     int pkt_size;  
      186.   
      187.       
      188.     enum AVColorSpace colorspace;  
      189.   
      190.      
      191.     enum AVColorRange color_range;  
      192.   
      193.   
      194.     /** 
      195.      * Not to be accessed directly from outside libavutil 
      196.      */  
      197.     AVBufferRef *qp_table_buf;  
      198. } AVFrame; 
  • 相关阅读:
    ycsb
    Tikv docker-compose go client
    Raft 协议
    kubectl 命令
    JAVA判断是否是微信内置浏览器,是否是在微信内打开
    IDEA设置默认maven配置
    JAVA中JDK1.8的LocalDateTime日期类的操作方法
    JAVA在JDK1.8中Stream流的使用
    Linux(Centos)部署Jenkins
    Linux(Centos)安装maven
  • 原文地址:https://www.cnblogs.com/sunminmin/p/4976271.html
Copyright © 2011-2022 走看看