FFmpeg软硬解和多线程解码

一. AVCodecContext解码上下文

  1.avcodec_register_all() : 注册所有的解码器

  2.AVCodec *avcodec_find_decoder(enum AVCodecID id)  :  查找解码器(法一 :  通过ID去查找)

   AVCodecID ------> AVStream->codecpar->codec_id : 就是解封装后的ID ----------->这个是软解码的查找解码器的方式

  3.AVCode *avcodec_find_decoder_by_name(const char *name) : 查找解码器(法二 :  通过名字去查找)--------->avcodec_find_decoder_by_name("h264_mediacodec")---------------->这个是硬解码查找的编码器方式

       2和3做一个对比 : 通过ID去查找编码器为软解码

           通过名字去查找编码器为硬解码  

  4.AVCodecContext  *avcodec_alloc_context3(const  AVCodec *codec)  :  创建AVCodec空间

  5. void avcodec_free_context(AVCodecContext  **avctx)  :  释放AVCodec的空间

  6.int avcodec_open2(AVCodecContext *avctx , const AVCodec *codec , AVDictionary  **options) :  打开avcodec编码器

  AVDictionary  **options  -------------> /libavcodec/options_table.h(这里面是存key--value键值对)

  7. int thread_count : 使用CPU的数量

  8. time_base : 时间的基数

  9. avcodec_parameters_to_context : 把AVStream复制到avcodec里面

二. AVFrame : 存放解码后的数据

  1.AVFrame *frame  =  av_frame_alloc() : 分配一个空间并且初始化

  2.void av_frame_free(AVFrame **frame) :  释放创建的空间

  3.int av_frame_ref(AVFrame *dst , const AVFrame *src) : 引用计数+1

  4.AVFrame *av_frame_clone(const AVFrame *src) : 分配一个空间并且引用计数=1

  5.void av_frame_unref(AVFrame *frame) : 引用计数-1

  6.uint8_t  *data[AV_NUM_DATA_POINTERS]  :  用来数据的存放Y[0]U[1]V[2]

  7.int linesize[AV_NUM_DATA_POINTERS] :  视频:一行数据的大小 音频:一个通道数据的大小(这两个地方是一个坑,以后仔细看看这一块的东西)

       data[0]:存放着Y,linesixe[0]代表存放着data[0]里面的所有数据量 

  8.int width

  9.int height

  10.int nb_samples : 音频 : 单通道的样本数据量

  11.int64_t   pts : 显示时间

  12.int64_t  pkt_dts :

  13.format : 视频: 像素格式(YUV420)   音频:采样率的格式(8bit or 16bit)

三. 

  avcodec_send_packet(AVCodecContext *avctx , AVPacket * avpkt) : 把Packet数据放入解码队列中

  avcodec_receive_frame(AVCodecContext *avctx , AVFrame *frame) : 从解码空间取出数据

  JNI_Onload ------>硬解码初始化,进入java程序之前会调用这个函数入口,然后把java上层应用的环境传给FFmpeg进行调用.

  

  

原文地址:https://www.cnblogs.com/liunx1109/p/9270520.html