📄 umc_mpeg2_enc_params.cpp
字号:
}
Status MPEG2EncoderParams::RelationChecks()
{
Status ret = UMC_OK;
if( mpeg1 ) {
if(info.interlace_type != PROGRESSIVE)
{
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting progressive_sequence = 1\n"));
info.interlace_type = PROGRESSIVE;
}
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("MPEG1 is not implemented. Setting to MPEG2\n"));
mpeg1 = 0;
}
frame_pred_frame_dct[0] = (frame_pred_frame_dct[0] != 0) ? 1 : 0;
frame_pred_frame_dct[1] = (frame_pred_frame_dct[1] != 0) ? 1 : 0;
frame_pred_frame_dct[2] = (frame_pred_frame_dct[2] != 0) ? 1 : 0;
if( info.interlace_type == PROGRESSIVE )
{
if( FieldPicture )
{
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting FieldPicture = 0\n"));
FieldPicture = 0;
}
if( !frame_pred_frame_dct[0] )
{
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting frame_pred_frame_dct[I_PICTURE] = 1\n"));
frame_pred_frame_dct[0] = 1;
}
if( !frame_pred_frame_dct[1] )
{
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting frame_pred_frame_dct[P_PICTURE] = 1\n"));
frame_pred_frame_dct[1] = 1;
}
if( !frame_pred_frame_dct[2] )
{
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting frame_pred_frame_dct[B_PICTURE] = 1\n"));
frame_pred_frame_dct[2] = 1;
}
}
if(info.color_format < YUV420 || info.color_format > YUV444) {
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("color_format fixed to YUV420\n"));
info.color_format = YUV420;
}
return ret;
}
Status MPEG2EncoderParams::ReadOldParamFile(const vm_char *ParFileName)
{
Ipp32s i, j;
vm_file *InputFile;
vm_char line[PAR_STRLEN];
vm_char IntraQMatrixFName[PAR_STRLEN];
vm_char NonIntraQMatrixFName[PAR_STRLEN];
vm_char TemplateLogFile[PAR_STRLEN];
Ipp32s LogMask;
Status ret, ret2;
Ipp32s frame_rate_code, aspect_code;
Ipp32s prog_seq;
info.color_format = YUV420;
profile = MP;
level = ML;
if( 0 == (InputFile = vm_file_open(ParFileName,VM_STRING("rt"))) )
{
vm_debug_trace1(VM_DEBUG_ERROR, VM_STRING("Couldn't open parameter file %s\n"), ParFileName);
return UMC_ERR_OPEN_FAILED;
}
vm_file_fgets( idStr, PAR_STRLEN, InputFile );
vm_file_fgets( line, PAR_STRLEN, InputFile ); //vm_string_sscanf(line, VM_STRING("%s"), SrcFileName );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%s"), IntraQMatrixFName );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%s"), NonIntraQMatrixFName );
vm_file_fgets( line, PAR_STRLEN, InputFile ); //vm_string_sscanf(line, VM_STRING("%d"), &numFramesToEncode );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &gopSize );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &IPDistance);
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &info.clip_info.width );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &info.clip_info.height );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &aspect_code );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &frame_rate_code );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &info.bitrate );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d %d %d"), &quant_vbr[0],
&quant_vbr[1],
&quant_vbr[2] );
vm_file_fgets( line, PAR_STRLEN, InputFile ); //vm_string_sscanf(line, VM_STRING("%d"), &dst_width );
vm_file_fgets( line, PAR_STRLEN, InputFile ); //vm_string_sscanf(line, VM_STRING("%d"), &dst_height );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d %d %d"), &frame_pred_frame_dct[0],
&frame_pred_frame_dct[1],
&frame_pred_frame_dct[2] );
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d"), &prog_seq );
info.interlace_type = prog_seq ? PROGRESSIVE : INTERLEAVED_TOP_FIELD_FIRST;
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d %d %d"), &intraVLCFormat[0],
&intraVLCFormat[1],
&intraVLCFormat[2] );
line[0]=0;
vm_file_fgets( line, PAR_STRLEN, InputFile ); vm_string_sscanf(line, VM_STRING("%d %s"), &LogMask,TemplateLogFile);
if( gopSize < 1 )
error("N must be positive\n");
if( IPDistance < 1 )
error("M must be positive\n");
if( gopSize%IPDistance != 0 )
error("N must be an integer multiple of M\n");
for (i = 0; i < IPDistance; i++) {
Ipp32s f0, f1;
for (j=0; j<2; j++) { // fwd/bwd
if (i==0) {
if (j!=0) continue;
vm_file_fgets( line, PAR_STRLEN, InputFile );
vm_string_sscanf(line, VM_STRING("%d %d %d %d"), &f0, &f1,
&rangeP[0], &rangeP[1] );
} else {
vm_file_fgets( line, PAR_STRLEN, InputFile );
if (i < 3)
vm_string_sscanf(line, VM_STRING("%d %d %d %d"), &f0, &f1,
&rangeB[j][0], &rangeB[j][1] );
}
}
}
vm_file_fclose( InputFile );
if(frame_rate_code < 1 || frame_rate_code > 8) {
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting frame rate to 30 fps\n"));
frame_rate_code = 5;
}
info.framerate = ratetab[frame_rate_code - 1];
if(aspect_code < 1 || aspect_code > 4) {
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting aspect ratio to 4:3\n"));
aspect_code = 2;
}
if(aspect_code == 1) {
info.aspect_ratio_width = info.clip_info.width;
info.aspect_ratio_height = info.clip_info.height;
} else {
info.aspect_ratio_width = aspecttab[aspect_code-2][0];
info.aspect_ratio_height = aspecttab[aspect_code-2][1];
}
// check parameters correctness
ret = Profile_and_Level_Checks();
if (ret < 0) return ret;
ret2 = RelationChecks();
if (ret2 < 0) return ret2;
if (ret2 != UMC_OK) ret = ret2;
ret2 = ReadQMatrices(IntraQMatrixFName, NonIntraQMatrixFName);
if (ret2 < 0) return ret2;
if (ret2 != UMC_OK) ret = ret2;
return ret;
}
Status MPEG2EncoderParams::ReadParamFile(const vm_char *ParFileName)
{
Ipp32s i, j;
Ipp32s h, m, s, f;
vm_file *InputFile;
vm_char line[PAR_STRLEN];
vm_char IntraQMatrixFName[PAR_STRLEN];
vm_char NonIntraQMatrixFName[PAR_STRLEN];
vm_char TemplateLogFile[PAR_STRLEN];
Ipp64f tmp;
Status ret, ret2;
Ipp32s frame_rate_code, chroma_format_code, aspect_code;
Ipp32s prog_seq, top_field_first;
if (0 == (InputFile = vm_file_open(ParFileName, VM_STRING("rt"))))
{
vm_debug_trace1(VM_DEBUG_ERROR, VM_STRING("Can't open parameter file %s\n"), ParFileName);
return UMC_ERR_OPEN_FAILED;
}
vm_file_fgets(idStr, PAR_STRLEN,InputFile);
if( vm_string_strstr(idStr, VM_STRING("Intel IPP")) != NULL ||
vm_string_strstr(idStr, VM_STRING("UMC")) != NULL ) {
vm_file_fclose(InputFile);
return ReadOldParamFile(ParFileName);
}
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%s"),SrcFileName);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%s"),tplref);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%s"),IntraQMatrixFName);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%s"),NonIntraQMatrixFName);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%s"),TemplateLogFile);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&inputtype);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&numFramesToEncode);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&numStartFrame);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d:%d:%d:%d"),&h,&m,&s,&f);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&gopSize);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&IPDistance);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&mpeg1);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&FieldPicture);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&info.clip_info.width);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&info.clip_info.height);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&aspect_code);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&frame_rate_code);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%lf"),&tmp); info.bitrate = (Ipp32s)tmp;
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&VBV_BufferSize);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&low_delay);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&constrparms);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&profile);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&level);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&prog_seq);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&chroma_format_code);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&video_format);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&color_primaries);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&transfer_characteristics);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&matrix_coefficients);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&dst_width);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&dst_height);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&intra_dc_precision);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d"),&top_field_first);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d %d %d"),
frame_pred_frame_dct,frame_pred_frame_dct+1,frame_pred_frame_dct+2);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d %d %d"),
conceal_tab,conceal_tab+1,conceal_tab+2);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d %d %d"),
//nonLinearQScale,nonLinearQScale+1,nonLinearQScale+2);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d %d %d"),
intraVLCFormat,intraVLCFormat+1,intraVLCFormat+2);
vm_file_fgets(line,PAR_STRLEN,InputFile); vm_string_sscanf(line, VM_STRING("%d %d %d"),
altscan_tab,altscan_tab+1,altscan_tab+2);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&repeat_first_field);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&progressive_frame);
/* intra slice interval refresh period */
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&P);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&r);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%lf"),&avg_act);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&Xi);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&Xp);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&Xb);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&d0i);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&d0p);
vm_file_fgets(line,PAR_STRLEN,InputFile); //vm_string_sscanf(line, VM_STRING("%d"),&d0b);
if( gopSize < 1 )
error("N must be positive\n");
if( IPDistance < 1 )
error("M must be positive\n");
if( gopSize%IPDistance != 0 )
error("N must be an integer multiple of M\n");
switch(chroma_format_code) {
case CHROMA420: info.color_format = YUV420; break;
case CHROMA422: info.color_format = YUV422; break;
case CHROMA444: info.color_format = YUV444; break;
default:
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("chroma_format fixed to CHROMA420\n"));
chroma_format_code = CHROMA420;
info.color_format = YUV420;
}
for (i = 0; i < IPDistance; i++) {
Ipp32s f0, f1;
for (j=0; j<2; j++) { // fwd/bwd
if (i==0) {
if (j!=0) continue;
vm_file_fgets( line, PAR_STRLEN, InputFile );
vm_string_sscanf(line, VM_STRING("%d %d %d %d"), &f0, &f1,
&rangeP[0], &rangeP[1] );
} else {
vm_file_fgets( line, PAR_STRLEN, InputFile );
if (i < 3)
vm_string_sscanf(line, VM_STRING("%d %d %d %d"), &f0, &f1,
&rangeB[j][0], &rangeB[j][1] );
}
}
}
vm_file_fclose( InputFile );
for (i=0; i<3; i++)
{
frame_pred_frame_dct[i] = !!frame_pred_frame_dct[i];
conceal_tab[i] = !!conceal_tab[i];
intraVLCFormat[i] = !!intraVLCFormat[i];
altscan_tab[i] = !!altscan_tab[i];
}
if(aspect_code < 1 || aspect_code > 4) {
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting aspect ratio to 4:3\n"));
aspect_code = 2;
}
if(aspect_code == 1) {
info.aspect_ratio_width = info.clip_info.width;
info.aspect_ratio_height = info.clip_info.height;
} else {
info.aspect_ratio_width = aspecttab[aspect_code-2][0];
info.aspect_ratio_height = aspecttab[aspect_code-2][1];
}
if(frame_rate_code < 1 || frame_rate_code > 8) {
vm_debug_trace(VM_DEBUG_WARNING, VM_STRING("setting frame rate to 30 fps\n"));
frame_rate_code = 5;
}
info.framerate = ratetab[frame_rate_code - 1];
info.interlace_type =
prog_seq ? PROGRESSIVE :
top_field_first ? INTERLEAVED_TOP_FIELD_FIRST : INTERLEAVED_BOTTOM_FIELD_FIRST;
// check parameters correctness
ret = Profile_and_Level_Checks();
if (ret < 0) return ret;
ret2 = RelationChecks();
if (ret2 < 0) return ret2;
if (ret2 != UMC_OK) ret = ret2;
ret2 = ReadQMatrices(IntraQMatrixFName, NonIntraQMatrixFName);
if (ret2 < 0) return ret2;
if (ret2 != UMC_OK) ret = ret2;
return ret;
}
#endif // UMC_ENABLE_MPEG2_VIDEO_ENCODER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -