H.264 视频编码实验

 之前装好了mcsdk_video,在Codecs文件夹下有很多音视频编解码的demo,这篇博文主要介绍其中的高性能H.264 视频编码实验,H.264是现今普遍使用的编码方式,这个demo位于Codecs\C66x_h264hpvenc_01_00_03_00_ELF 文件夹。

第一步:连接好卡板,no boot 模式,打开CCS,导入已存在项目,找到这个文件夹,导入这个项目。



第二步:编译这个项目,成功的话会显示如下图:成功生成out文件。


失败的话多半是组件位置路径不对,请右击项目选择properties,检查下图中各项中组件名称和位置是否正确:


第三步:将编译好的out文件加载到0核或者多核中(具体视参数配置文件而定),在加载前请注意进行如下图的系统初始化和全局初始化。


第四步:点击运行,控制台输出如下(只进行了两帧编码)

[C66xx_0] 
---------------------------------------------------------
Test Case Number : 1
---------------------------------------------------------
Config File   : ..\..\..\Test\TestVecs\Config\encoder.cfg
Input YUV     : ..\..\..\Test\TestVecs\Input\airshow_p352x288.yuv
Output Stream : ..\..\..\Test\TestVecs\Output\airshow_p352x288.264

ShmemTab initialized on Core 0 

Algorithm Instance  Creation for the Module DEV.H264HP.E.C6678.01.00.03.00 Done...

Started Reading Frame : 0.......
 
#NA   : IVIDEO_NA_FRAME       : Bits  : 0         

Started Reading Frame : 0.......
 
#NA   : IVIDEO_NA_FRAME       : Bits  : 0         

Started Reading Frame : 0.......
 
#0    : IVIDEO_IDR_FRAME      : Bits  : 107144    

 core 0 ,nalSizes 24
 core 0 ,nalSizes 8
 core 0 ,nalSizes 13361

Started Reading Frame : 1.......
 
#1    : IVIDEO_P_FRAME        : Bits  : 9216      

 core 0 ,nalSizes 1152
 
#2    : IVIDEO_B_FRAME        : Bits  : 2048      

 core 0 ,nalSizes 256
 
#3    : IVIDEO_B_FRAME        : Bits  : 1960      

 core 0 ,nalSizes 245

 Given number of frames are encoded

 ******** Request to END H264 Encoder ******** 


总结:程序开始运行后,首先去Codecs\C66x_h264hpvenc_01_00_03_00_ELF\packages\ti\sdo\codecs\h264hpvenc\App\Client\Test\TestVecs\Config 下读取了两个配置文件 testcases.txt 和 encoder.cfg 。testcases.txt 只是用来指出 encoder.cfg 的位置和名称,而 encoder.cfg 则给出了所有的编码参数和输入输出文件,以及需要用到的核数。encoder.cfg的内容如下(重要的参数用绿色标出):

***************************************************************************************************************************************************************************************

#  New Input File Format is as follows
#  <ParameterName> = <ParameterValue> # Comment
#


#############################################################################################
# Files      
#############################################################################################
InputFile       = ..\..\..\Test\TestVecs\Input\airshow_p352x288.yuv
EncodedFile     = ..\..\..\Test\TestVecs\Output\airshow_p352x288.264

#Default reference file in package is generated with 8 core configuration
ReferenceFile   = ..\..\..\Test\TestVecs\Reference\airshow_p352x288_ref.264


##########################################################################################
# Multicore Parameters
##########################################################################################
 
ncores                  = 1
CoreTeamMap             = 0

#CoreTeamMap             = 0,1,2,3,4,5,6,7
# ##########################################################################################
#  Encoder Control
# ##########################################################################################
EncodingPreset         = 3 # encoding preset 0: DEFAULT, 1: HIGH_QUALITY, 2: HIGH_SPEED, 3:USER_DEFINED
RateControlPreset     = 5 # 5: IVIDEO_USER_DEFINED, 4: IVIDEO_NONE, 2: IVIDEO_STORAGE, 1: IVIDEO_LOW_DELAY
framesToEncode        = 4 # Total number of frames to encode 
MaxWidth              = 640 # Max Frame width
MaxHeight             = 480 # Max Frame height

MaxInterFrameInterval = 3 # I to P frame distance. 1 indicates no B frames. Value >1 indicates presence of B frames. 
InputChromaFormat     = 1 # 1 => XDM_YUV_420P, Only 1 is supported.
InputContentType       = 0 # Input buffer content type, 0 -> Progressive Type, 1-> Interlaced.
Profile               = 100 # Encoding profile 100 => HP, 77 => MP, 66 => BP.  
Level                 = 40 # Level IDC   (e.g. 20 = level 2.0) 
inputWidth              = 352 # width of image 
inputHeight             = 288 # Height of image 

targetFrameRate         = 30000 # Target frame rate in fps * 1000
targetBitRate           = 1000000 # Target Bit Rate in Bits per second. 

intraFrameInterval     = 15  # Interval between two consecutive intra frames, 0 => Only first frame to be intra coded, 1 => All intra frames, N => One intra frame and N-1 inter frames, where N > 1
interFrameInterval     = 3 # M: Number of (M-1) B frames between two reference frames. 1 indicates no B frame. 
mvAccuracy            = 2 # Pixel accuracy of the motion vector, 0 => integer pel 2=> quarter pel
generateHeader         = 0 # 1: Encode only header, 0: Encode entire access unit, including the headers 
forceFrame             = -1 # -1: IVIDEO_NA_FRAME, 3: IVIDEO_IDR_FRAME
dataLayout             = 0 # input data buffer layout 0=> interleaved, 1=> seprated. Only 0 is supported and applicable only for interlace content.
sampleAspectRatioHeight = 1 # Aspect Ratio Height
sampleAspectRatioWidth  = 1 # Aspect Ratio Width


# ##########################################################################################
#  Rate Control Params
# ##########################################################################################
rateControlParamsPreset = 1 # Preset value for selecting rate control params, 0: default (other parameters in this category will be decided by Codec internally), 1: user defined
rcAlgo                  = 0 # Rate control algorithm used, 0: Variable Bitrate, 1 : Constant bitrate (low dealy), 2: Constrained CBR (No Frame Skips), 3:Constrained CBR (No Frame Skips with no scene change detection)
qpI                     = 25 # Initial QP for I/IDR frames, -1 indicates codec chosen 
qpP                     = 25 # Initial QP for P frames
qpOffsetB               = 4 # Offset of B frames QP from P frames 
qpMaxI                  = 51 # Maximum QP for I/IDR frames 
qpMinI                  = 1 # Minimum QP for I/IDR frames 
qpMaxP                  = 51 # Maximum QP for P frames 
qpMinP                  = 1 # Minimum QP for P frames 
qpMaxB                  = 51 # Maximum QP for B frames 
qpMinB                  = 1 # Minimum QP for B frames 
CbQPIndexOffset         = 0 # Specifies offset to be added to luma QP for addressing QPC values table for Cb components
CrQPIndexOffset         = 0 # Specifies offset to be added to luma QP for addressing QPC values table for Cr components
initialBufferLevel      = 2000000 # Initial Buffer level for HRD compliance, keep same as HRDBufferSize for best quality
HRDBufferSize           = 2000000 # Hypothetical Reference Decoder Buffer Size in bits - 2*bitrate for VBR

enablePRC               = 1 #  Control Flag to enable MB level Perceptual Rate Control, 0 => Disable, 1 => Enable
frameSkipAfterSceneChange = 1 # 0=> no forced skip after scenechange, 1 => force skip frame after coding scene change frame.
scalingMatrixPreset      = 0 # Scaling Matrix selection of encoder, 0: no scaling matrices, 1: normal, 2: noisy, 3 : standard default, 4 : user defined
suppressHighFreqCoeffs  = 0 #0=> No High Freq Suppression #1=>Adaptively enabled only for noise streams when Qp reaches it max & suppression for more than half of the coeffs 2 => Enabled for all streams when Qp reaches it max & suppression for half of the coeffs 3 => Enabled for all streams when Qp reaches it max & suppression for more than half of the coeffs
##########################################################################################
#  InterCoding Control
##########################################################################################


interCodingPreset    = 1 # Inter coding mode preset, 0 => deafult values, 1 => user defined 
MvRangeVerP          = 32  # Vertical Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496 
MvRangeHorP          = 144 # Horizontal Motion Vector Range for P frames in integer pixels, Range supported is 16 to 496
MvRangeVerB          = 32  # Vertical Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496 
MvRangeHorB          = 144 # Horizontal Motion Vector Range for B frames in integer pixels, Range supported is 16 to 496
maxMVperMB           = 4 # Maximum MV per MB (Values of 1 & 4 are valid)


# ##########################################################################################
#  IntraCoding Control
# ##########################################################################################
intraCodingPreset             = 1 # Intra coding mode preset, 0 => deafult values, 1 => user defined  
enableIntraPartition          = 4 # 0 => INTRA_PARTITION_NONE , 1 => INTRA_PARTITION_ISLICES, 2 => INTRA_PARTITION_IPSLICES, 3 => INTRA_PARTITION_IBSLICES, 4 => INTRA_PARTITION_IPBSLICES.
intraRefreshMethod            = 0 # IH264_INTRAREFRESH_NONE  = 0, IH264_INTRAREFRESH_CYCLIC_MBS = 1
intraRefreshRate              = 0 # Rate at which intra MB Refresh is done. e.g. 10 indicates every 10th MB will coded as Intra in inter pictures.
constrainedIntraPredEnable    = 0 # Controls the intra macroblock coding in inter slices


# ##########################################################################################
# Entropy Coding Mode
# ##########################################################################################
entropyCodingMode               = 1 # Enropy coding type, (0 => CAVLC, 1 => CABAC)


# ##########################################################################################
#  Slice Mode Configuration
# ##########################################################################################
sliceCodingPreset            = 0 # Preset value for slice coding mode, 0 => deafult values, 1 => user defined
streamFormat                 = 0 # Type of bitstream to be encoded, 0 => Byte stream format, 1=> NALU format(without start code)
sliceMode                    = 0 # Type of slice coding, 0 => slice coding mode is frame based, 1 => Slices are controlled based upon number of Macroblocks
sliceUnitSize                = 1200 # Number of macroblocks per slice


# ##########################################################################################
#  Loop Filter Control
# ##########################################################################################


loopfilterPreset           = 1 # Preset value for loop filter operation parameters, 0 => default values, 1 => user defined
loopfilterDisableIDC               = 2 # Disable H.264 loop filter, (0=Filter, 1= NoFilter, 2 = No loop filter across slices)
filterOffsetA                      = 0 # Alpha offset for loop filter
filterOffsetB                      = 0 # Beta offset for loop filter
# ##########################################################################################
#  VUI Control Params
# ##########################################################################################


vuiCodingPreset                = 1 # Preset value for VUI Control Params, 0 => deafult values, 1 => user defined
aspectRatioInfoPresentFlag     = 1 # Controls the insertion of aspect ratio information in VUI part of bit-stream 
aspectRatioIdc                 = 1 # Aspect ratio ID 
videoSignalTypePresentFlag     = 0 # controls the insertion of video signal type in VUI part of bit-stream
videoFormat                    = 2 # Video signal type
videoFullRangeFlag             = 0 # Flag to specigy Range of the pixels 
colourDescriptionPresentFlag   = 1 # Specifies whether colour_primaries, transfer_characteristics and matrix_coefficients are present or not.
colourPrimaries         = 5 # chromaticity coordinates of the source primaries(Table E-3 in standard)
transferCharacteristics = 5 # opto-electronic transfer characteristic of the source picture(Table E-4 in standard)
matrixCoefficients       = 5 # matrix coefficients used in deriving Y,Cb,Cr signals from the G,B,R primaries(Table E-5 in standard)
timingInfoPresentFlag          = 1 # Controls the insertion of timing info related parameters in VUI part of bit-stream
##########################################################################################
#  MISC
##########################################################################################


gopStructure               = 0 # GOP structure, 0 => Open or Non uniform(IBBPBBP), 1 => Closed or Uniform (BBIBBPBB) 
log2MaxFNumMinus4          = 0 # sliceParams::frame_num syntax element will be reset after every (1<< (log2MaxFNumMinus4 + 4)) frames
picOrderCountType          = 0  # Picture order count type
IDRFrameInterval           = 0 # Interval b/w two IDR frames  0=>IDR BBP I BBP I,  1=>IDR BBP IDR BBP IDR,  2=>IDR BBP I BBP IDR, 3=>IDR BBP I BBP I BBP IDR
transformBlockSize         = 1  # Tranform type, 0:4x4 only, 1: 8x8 only
topFieldFirstFlag          = 1  # Flag to indicate field order in interlaced content
interlaceCodingType        = 4 # Interlced field coding type selection, 2 => MRF 3=> ARF 4=> SPF
DebugTraceLevel            = 0 # Debug trace Enable 0 - Disable, 1- Level1, 2 - Level2, 3 - Level3,
lastNFramesToLog           = 5 # Last N frames to log into debug trace buffer

****************************************************************************************************************************************************************************************

 程序读取到相应参数后,会去读取输入yuv文件(位于 ..\..\..\Test\TestVecs\Input,不会一次读完,应该是分帧),然后编码,并将结果返回到PC,输出的码流文件位于 ..\..\..\Test\TestVecs\Output,所有交互都是通过仿真器的串口完成,所以速度很慢,建议大家实验时编码4帧就够了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值