x264框架概览

avcodec_open2(st->codec, codec, options ? &options[i] : NULL);
  |--  avctx->codec->init(avctx);
       -->int X264_init(AVCodecContext *avctx)
                 |-- check_default_settings(avctx); // 使用默认设置"Default settings detected, using medium profile"
                 |    ...
                 |   if(x4->x264opts){ 对x264进行指定的参数设置;}
                 |    ...
                 |-- x264_encoder_open(&x4->params);
                               |-- x264_sps_init( h->sps, h->param.i_sps_id, &h->param );
                               |   x264_pps_init( h->pps, h->param.i_sps_id, &h->param, h->sps );
                               |   初始化帧内预测,MC, DCT, 扫描, 量化, deblock, 熵编码的函数指针;
                               |   ...
                 |-- x264_encoder_headers(x4->enc, &nal, &nnal); //编码NAL头, SPS和PPS
                 |-- encode_nals(avctx, avctx->extradata, s, nal, nnal, 1);


transcode
  |
  V
output_packet
  |
  V
do_video_out
  |
  V
avcodec_encode_video
  |
  V
int X264_frame(AVCodecContext *ctx,           // 编码参数 
               uint8_t *buf,int orig_bufsize, // 输出的编码后的比特流
               void *data)                    // 要编码YUV帧
{
  x264_picture_init( &x4->pic ); // 初始化
  x264_encoder_encode(...);
      |-- x264_frame_expand_border_lowres( frame ); //扩边
          x264_slice_init( h, i_nal_type, i_global_qp ); // Create slice header


  x264_slices_write( h );
      |-- x264_slice_write()
              |-- x264_slice_header_write( &h->out.bs, &h->sh, h->i_nal_ref_idc );
              |-- x264_macroblock_analyse( x264_t *h )
                      |--  if( h->sh.i_type == SLICE_TYPE_I )
                      |      进行I4x4, I8x8, I16x16的SAD计算,得到最佳宏块模式;
                      |    else if( h->sh.i_type == SLICE_TYPE_P )
                      |      进行Intra, inter P的SAD计算, 得到最佳宏块模式;
                      |    else if( h->sh.i_type == SLICE_TYPE_B )
                      |      进行Intra, inter B的SAD计算, 得到最佳宏块模式;
              |-- x264_macroblock_encode_internal( h, 1, 1 )
                      |--  if( h->mb.i_type == I_16x16 )
                      |       x264_mb_encode_i16x16( h, p, i_qp );// I_16x16编码: 预测,计算残差,DCT,量化,扫描,反量化,idct
                      |    else if( h->mb.i_type == I_8x8 )
                      |       x264_mb_encode_i8x8( h, p, i, i_qp, i_mode, NULL, 1 );
                      |    else if( h->mb.i_type == I_4x4 )  
                      |       264_mb_encode_i4x4( h, p, i, i_qp, i_mode, 1 ); // 预测,计算残差值
                      |    else    /* Inter MB */
                      |       预测,计算残差值, dct, 量化,扫描, 反量化, idct ;
                      |    ...
                      |    if( chroma ) 
                      |      x264_mb_encode_chroma( h, !IS_INTRA( h->mb.i_type ), h->mb.i_chroma_qp ); 
              |-- 熵编码  
                       
                      
                                 
 
          
  
}
 
                               
                
                             
                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北雨南萍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值