📄 configfile.c
字号:
while( uiTmp != 0 )
{
uiTmp >>= 1;
uiRet++;
}
return uiRet;
}
/*!
************************************************************************
* \brief
* read the slice group configuration file. Returns without action
* if type is not 0, 2 or 6
************************************************************************
*/
void read_slice_group_info()
{
FILE * sgfile=NULL;
int i;
int ret;
if ((params->slice_group_map_type != 0) && (params->slice_group_map_type != 2) && (params->slice_group_map_type != 6))
{
// nothing to do
return;
}
// do we have a file name (not only NULL character)
if (strlen (params->SliceGroupConfigFileName) <= 1)
error ("No slice group config file name specified", 500);
// open file
sgfile = fopen(params->SliceGroupConfigFileName,"r");
if ( NULL==sgfile )
{
snprintf(errortext, ET_SIZE, "Error opening slice group file %s", params->SliceGroupConfigFileName);
error (errortext, 500);
}
switch (params->slice_group_map_type)
{
case 0:
params->run_length_minus1=(int *)malloc(sizeof(int)*(params->num_slice_groups_minus1+1));
if ( NULL==params->run_length_minus1 )
{
fclose(sgfile);
no_mem_exit("PatchInp: params->run_length_minus1");
}
// each line contains one 'run_length_minus1' value
for(i=0;i<=params->num_slice_groups_minus1;i++)
{
ret = fscanf(sgfile,"%d",(params->run_length_minus1+i));
fscanf(sgfile,"%*[^\n]");
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", i+1);
error (errortext, 500);
}
}
break;
case 2:
params->top_left=(int *)malloc(sizeof(int)*params->num_slice_groups_minus1);
params->bottom_right=(int *)malloc(sizeof(int)*params->num_slice_groups_minus1);
if (NULL==params->top_left)
{
fclose(sgfile);
no_mem_exit("PatchInp: params->top_left");
}
if (NULL==params->bottom_right)
{
fclose(sgfile);
no_mem_exit("PatchInp: params->bottom_right");
}
// every two lines contain 'top_left' and 'bottom_right' value
for(i=0;i<params->num_slice_groups_minus1;i++)
{
ret = fscanf(sgfile,"%d",(params->top_left+i));
fscanf(sgfile,"%*[^\n]");
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", 2*i +1);
error (errortext, 500);
}
ret = fscanf(sgfile,"%d",(params->bottom_right+i));
fscanf(sgfile,"%*[^\n]");
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", 2*i + 2);
error (errortext, 500);
}
}
break;
case 6:
{
int tmp;
int frame_mb_only;
int mb_width, mb_height, mapunit_height;
frame_mb_only = !(params->PicInterlace || params->MbInterlace);
mb_width = (params->output.width + img->auto_crop_right)>>4;
mb_height = (params->output.height + img->auto_crop_bottom)>>4;
mapunit_height = mb_height / (2-frame_mb_only);
params->slice_group_id=(byte * ) malloc(sizeof(byte)*mapunit_height*mb_width);
if (NULL==params->slice_group_id)
{
fclose(sgfile);
no_mem_exit("PatchInp: params->slice_group_id");
}
// each line contains slice_group_id for one Macroblock
for (i=0;i<mapunit_height*mb_width;i++)
{
ret = fscanf(sgfile,"%d", &tmp);
params->slice_group_id[i]= (byte) tmp;
if ( 1!=ret )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file (line %d)", i + 1);
error (errortext, 500);
}
if ( *(params->slice_group_id+i) > params->num_slice_groups_minus1 )
{
fclose(sgfile);
snprintf(errortext, ET_SIZE, "Error while reading slice group config file: slice_group_id not allowed (line %d)", i + 1);
error (errortext, 500);
}
fscanf(sgfile,"%*[^\n]");
}
}
break;
default:
// we should not get here
error ("Wrong slice group type while reading config file", 500);
break;
}
// close file again
fclose(sgfile);
}
/*!
***********************************************************************
* \brief
* Checks the input parameters for consistency.
***********************************************************************
*/
static void PatchInp (void)
{
int i,j;
int storedBplus1;
int bitdepth_qp_scale[3];
if (params->src_BitDepthRescale)
{
bitdepth_qp_scale [0] = 6*(params->output.bit_depth[0] - 8);
bitdepth_qp_scale [1] = 6*(params->output.bit_depth[1] - 8);
bitdepth_qp_scale [2] = 6*(params->output.bit_depth[2] - 8);
}
else
{
bitdepth_qp_scale [0] = 6*(params->source.bit_depth[0] - 8);
bitdepth_qp_scale [1] = 6*(params->source.bit_depth[1] - 8);
bitdepth_qp_scale [2] = 6*(params->source.bit_depth[2] - 8);
}
TestEncoderParams(bitdepth_qp_scale);
if (params->FrameRate == 0.0)
params->FrameRate = INIT_FRAME_RATE;
// Set block sizes
// Skip/Direct16x16
params->part_size[0][0] = 4;
params->part_size[0][1] = 4;
// 16x16
params->part_size[1][0] = 4;
params->part_size[1][1] = 4;
// 16x8
params->part_size[2][0] = 4;
params->part_size[2][1] = 2;
// 8x16
params->part_size[3][0] = 2;
params->part_size[3][1] = 4;
// 8x8
params->part_size[4][0] = 2;
params->part_size[4][1] = 2;
// 8x4
params->part_size[5][0] = 2;
params->part_size[5][1] = 1;
// 4x8
params->part_size[6][0] = 1;
params->part_size[6][1] = 2;
// 4x4
params->part_size[7][0] = 1;
params->part_size[7][1] = 1;
for (j = 0; j<8;j++)
{
for (i = 0; i<2; i++)
{
params->blc_size[j][i] = params->part_size[j][i] * BLOCK_SIZE;
}
}
if (params->idr_period && params->intra_delay && params->idr_period <= params->intra_delay)
{
snprintf(errortext, ET_SIZE, " IntraDelay cannot be larger than or equal to IDRPeriod.");
error (errortext, 500);
}
if (params->idr_period && params->intra_delay && params->EnableIDRGOP == 0)
{
snprintf(errortext, ET_SIZE, " IntraDelay can only be used with only 1 IDR or with EnableIDRGOP=1.");
error (errortext, 500);
}
if (params->idr_period && params->intra_delay && params->adaptive_idr_period)
{
snprintf(errortext, ET_SIZE, " IntraDelay can not be used with AdaptiveIDRPeriod.");
error (errortext, 500);
}
storedBplus1 = (params->BRefPictures ) ? params->successive_Bframe + 1: 1;
if (params->Log2MaxFNumMinus4 == -1)
{
log2_max_frame_num_minus4 = iClip3(0,12, (int) (CeilLog2(params->no_frames * storedBplus1) - 4));
}
else
log2_max_frame_num_minus4 = params->Log2MaxFNumMinus4;
max_frame_num = 1 << (log2_max_frame_num_minus4 + 4);
if (log2_max_frame_num_minus4 == 0 && params->num_ref_frames == 16)
{
snprintf(errortext, ET_SIZE, " NumberReferenceFrames=%d and Log2MaxFNumMinus4=%d may lead to an invalid value of frame_num.", params->num_ref_frames, params-> Log2MaxFNumMinus4);
error (errortext, 500);
}
// set proper log2_max_pic_order_cnt_lsb_minus4.
if (params->Log2MaxPOCLsbMinus4 == - 1)
log2_max_pic_order_cnt_lsb_minus4 = iClip3(0,12, (int) (CeilLog2( 2*params->no_frames * (params->jumpd + 1)) - 4));
else
log2_max_pic_order_cnt_lsb_minus4 = params->Log2MaxPOCLsbMinus4;
max_pic_order_cnt_lsb = 1 << (log2_max_pic_order_cnt_lsb_minus4 + 4);
if (((1<<(log2_max_pic_order_cnt_lsb_minus4 + 3)) < params->jumpd * 4) && params->Log2MaxPOCLsbMinus4 != -1)
error("log2_max_pic_order_cnt_lsb_minus4 might not be sufficient for encoding. Increase value.",400);
// B picture consistency check
if(params->successive_Bframe > params->jumpd)
{
snprintf(errortext, ET_SIZE, "Number of B-frames %d can not exceed the number of frames skipped", params->successive_Bframe);
error (errortext, 400);
}
// Direct Mode consistency check
if(params->successive_Bframe && params->direct_spatial_mv_pred_flag != DIR_SPATIAL && params->direct_spatial_mv_pred_flag != DIR_TEMPORAL)
{
snprintf(errortext, ET_SIZE, "Unsupported direct mode=%d, use TEMPORAL=0 or SPATIAL=1", params->direct_spatial_mv_pred_flag);
error (errortext, 400);
}
if (params->PicInterlace>0 || params->MbInterlace>0)
{
if (params->directInferenceFlag==0)
printf("\nWarning: DirectInferenceFlag set to 1 due to interlace coding.");
params->directInferenceFlag = 1;
}
// Open Files
if ((p_in=open(params->infile, OPENFLAGS_READ))==-1)
{
snprintf(errortext, ET_SIZE, "Input file %s does not exist",params->infile);
error (errortext, 500);
}
updateOutFormat(params);
if (params->no_frames == -1)
{
getNumberOfFrames();
}
if (params->no_frames < 1)
{
snprintf(errortext, ET_SIZE, "Not enough frames to encode (%d)", params->no_frames);
error (errortext, 500);
}
if (strlen (params->ReconFile) > 0 && (p_dec=open(params->ReconFile, OPENFLAGS_WRITE, OPEN_PERMISSIONS))==-1)
{
snprintf(errortext, ET_SIZE, "Error open file %s", params->ReconFile);
error (errortext, 500);
}
#if TRACE
if (strlen (params->TraceFile) > 0 && (p_trace=fopen(params->TraceFile,"w"))==NULL)
{
snprintf(errortext, ET_SIZE, "Error open file %s", params->TraceFile);
error (errortext, 500);
}
#endif
if (params->output.width % 16 != 0)
{
img->auto_crop_right = 16 - (params->output.width % 16);
}
else
{
img->auto_crop_right=0;
}
if (params->PicInterlace || params->MbInterlace)
{
if ((params->output.height & 0x01) != 0)
{
error ("even number of lines required for interlaced coding", 500);
}
if (params->output.height % 32 != 0)
{
img->auto_crop_bottom = 32-(params->output.height % 32);
}
else
{
img->auto_crop_bottom=0;
}
}
else
{
if (params->output.height % 16 != 0)
{
img->auto_crop_bottom = 16-(params->output.height % 16);
}
else
{
img->auto_crop_bottom=0;
}
}
if (img->auto_crop_bottom || img->auto_crop_right)
{
fprintf (stderr, "Warning: Automatic cropping activated: Coded frame Size: %dx%d\n",
params->output.width + img->auto_crop_right, params->output.height + img->auto_crop_bottom);
}
if ((params->slice_mode==1)&&(params->MbInterlace!=0))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -