📄 video_enc_con.cpp
字号:
i++;
refEncodedFile = argv[i];
break;
case 'l':
i++;
inpLogFile = argv[i];
break;
case 'v':
i++;
outLogFile = argv[i];
break;
case 'g':
i++;
resLogFile = argv[i];
break;
/////////////////
//case 'h':
case '?':
default:
return PrintHelp(argv[0], VM_STRING("Unknown options"));
}
}
}
if (!DstFileName) {
return PrintHelp(argv[0], VM_STRING("Destination file name not found"));
}
if (!ParFileName && (!mWidth || !mHeight)) {
return PrintHelp(argv[0], VM_STRING("at least ParFile or options -w,-h should be specified"));
}
if (ParFileName) { // read first line of ParFile
if (read_line(ParFileName, 1, line, MAX_FILELEN)) {
return 3;
}
}
if (mVideoStreamType == UNDEF_VIDEO) {
if (!ParFileName) {
mVideoStreamType = MPEG2_VIDEO;
} else {
if (vm_string_strstr(line, VM_STRING("MPEG-2"))) mVideoStreamType = MPEG2_VIDEO; else
if (vm_string_strstr(line, VM_STRING("MPEG-4"))) mVideoStreamType = MPEG4_VIDEO; else
if (vm_string_strstr(line, VM_STRING("H.261"))) mVideoStreamType = H261_VIDEO; else
if (vm_string_strstr(line, VM_STRING("H.263"))) mVideoStreamType = H263_VIDEO; else
if (vm_string_strstr(line, VM_STRING("H.264"))) mVideoStreamType = H264_VIDEO; else {
return PrintHelp(argv[0], VM_STRING("Unknown codec"));
}
}
}
if (ParFileName && vm_string_strstr(line, VM_STRING("UseDefaultParameters"))) {
ParFileName = NULL; // use default parameters
}
switch (mVideoStreamType) {
#ifdef UMC_ENABLE_MPEG2_VIDEO_ENCODER
case MPEG2_VIDEO:
CREATE_ENCODER(MPEG2)
break;
#endif
#ifdef UMC_ENABLE_MPEG4_VIDEO_ENCODER
case MPEG4_VIDEO:
CREATE_ENCODER(MPEG4)
break;
#endif
#ifdef UMC_ENABLE_H261_VIDEO_ENCODER
case H261_VIDEO:
CREATE_ENCODER(H261)
break;
#endif
#ifdef UMC_ENABLE_H263_VIDEO_ENCODER
case H263_VIDEO:
CREATE_ENCODER(H263)
break;
#endif
#ifdef UMC_ENABLE_H264_VIDEO_ENCODER
case H264_VIDEO:
CREATE_ENCODER(H264)
break;
#endif
#ifdef UMC_ENABLE_DV_VIDEO_ENCODER
case DIGITAL_VIDEO_SD:
CREATE_ENCODER(DV)
break;
#endif
#ifdef UMC_ENABLE_DV50_VIDEO_ENCODER
case DIGITAL_VIDEO_50:
CREATE_ENCODER(DV50)
mColorFormat = YUV422;
break;
#endif
#ifdef UMC_ENABLE_DVHD_VIDEO_ENCODER
case DIGITAL_VIDEO_HD:
CREATE_ENCODER(DV100)
mColorFormat = YUV422;
break;
#endif
#ifdef UMC_ENABLE_VC1_VIDEO_ENCODER
case VC1_VIDEO:
CREATE_ENCODER(VC1)
break;
#endif
default:
vm_file_fprintf(vm_stderr, VM_STRING("Codec (%d) not supported\n"), (int)mVideoStreamType);
return PrintHelp(argv[0], VM_STRING("Codec not supported"));
}
if (ParFileName) {
Status res;
res = pEncoderParams->ReadParamFile(ParFileName);
if (res < UMC_OK) { // < means error
if (res == UMC_ERR_OPEN_FAILED) {
vm_file_fprintf(vm_stderr, VM_STRING("Error: Can't open par file %s\n"), ParFileName);
} else {
vm_file_fprintf(vm_stderr, VM_STRING("Error: Can't parse par file %s\n"), ParFileName);
}
return 3;
}
#ifdef UMC_ENABLE_MPEG2_VIDEO_ENCODER
if (mVideoStreamType == MPEG2_VIDEO) {
//chroma_format = ((MPEG2EncoderParams*)pEncoderParams)->chroma_format;
mColorFormat = pEncoderParams->info.color_format;
}
#endif
#ifdef UMC_ENABLE_VC1_VIDEO_ENCODER
if (mVideoStreamType == VC1_VIDEO) {
if(!maxNumFrames)
{
if (((VC1EncoderParams*)pEncoderParams)->m_uiNumFrames)
maxNumFrames = ((VC1EncoderParams*)pEncoderParams)->m_uiNumFrames;
}
}
#endif
#ifdef UMC_ENABLE_H264_VIDEO_ENCODER
if (mVideoStreamType == H264_VIDEO) {
H264EncoderParams *params = (H264EncoderParams*)pEncoderParams;
chroma_format = params->chroma_format_idc;
mBitDepth = (IPP_MAX(params->bit_depth_luma, params->bit_depth_chroma) > 8)? 16 : 8;
mBitDepthAlpha = (params->bit_depth_aux > 8)? 16: 8;
numFramesToEncode = params->numFramesToEncode;
#if 0
if (ReconFileName) {
((H264EncoderParams*)pEncoderParams)->m_SaveReconFlag = 1;
vm_string_strncpy(((H264EncoderParams*)pEncoderParams)->m_ReconFileName, ReconFileName, MAXIMUM_PATH);
printf("ReconFileName = \"%s\"\n", ((H264EncoderParams*)pEncoderParams)->m_ReconFileName);
}
#endif
mColorFormat = (chroma_format == 0)? GRAY
: (chroma_format == 2)? YUV422
: (chroma_format == 3)? YUV444
: YUV420; // Accept monochromes with UV components filled with dummy values.
}
#endif
}
if ((!SrcFileName[0] || SrcFileName[vm_string_strlen(SrcFileName) - 1] == '\\') && ParFileName) {
// read stream filename from second line of ParFile
vm_char SrcName[MAX_FILELEN];
if (read_line(ParFileName, 2, line, MAX_FILELEN)) {
return 3;
}
vm_string_sscanf(line, VM_STRING("%s"), SrcName);
vm_string_strcat(SrcFileName, SrcName); // concatenate
}
#ifdef UMC_ENABLE_VC1_VIDEO_ENCODER
if (ParFileName) {
if (mVideoStreamType == VC1_VIDEO) {
((VC1EncoderParams*)pEncoderParams)->m_pStreamName = SrcFileName;
}
}
#endif
if (!ParFileName) {
pEncoderParams = new VideoEncoderParams;
if (!maxNumFrames) {
maxNumFrames = 0x7fffffff;
}
if (!FrameRate) {
FrameRate = 30;
}
if (BitRate < 0) {
BitRate = 5000000;
}
}
// override param's if non-zero
if (mWidth && mHeight) {
pEncoderParams->info.clip_info.width = mWidth;
pEncoderParams->info.clip_info.height = mHeight;
} else {
mWidth = pEncoderParams->info.clip_info.width;
mHeight = pEncoderParams->info.clip_info.height;
}
if (maxNumFrames) {
numFramesToEncode = maxNumFrames;
} else {
maxNumFrames = numFramesToEncode;
}
if (FrameRate) {
pEncoderParams->info.framerate = FrameRate;
} else {
FrameRate = pEncoderParams->info.framerate;
}
if (BitRate >= 0) {
pEncoderParams->info.bitrate = BitRate;
} else {
BitRate = pEncoderParams->info.bitrate;
}
pEncoderParams->numThreads = numThreads;
srcFile = vm_file_open(SrcFileName, VM_STRING("rb"));
if (NULL == srcFile) {
vm_file_fprintf(vm_stderr, VM_STRING("Error opening file %s"), SrcFileName);
return 8;
}
dstFile = vm_file_open(DstFileName, VM_STRING("wb"));
if (NULL == dstFile) {
vm_file_fprintf(vm_stderr, VM_STRING("Error: Can't open output file '%s'\n"), DstFileName);
return 9;
}
if (AlphaFileName) {
srcAlphaFile = vm_file_open(AlphaFileName, VM_STRING("rb"));
if (NULL == srcAlphaFile) {
vm_file_fprintf(vm_stderr, VM_STRING("Error opening file %s"), AlphaFileName);
return 8;
}
if (mColorFormat == YUV420) mColorFormat = YUV420A; else
if (mColorFormat == YUV422) mColorFormat = YUV422A; else
if (mColorFormat == YUV444) mColorFormat = YUV444A;
}
if (pCodec->Init(pEncoderParams) != UMC_OK) {
vm_file_fprintf(vm_stderr, VM_STRING("Error: Video encoder initialization failed\n"));
return 6;
}
if (pCodec->GetInfo(pEncoderParams) != UMC_OK) {
vm_file_fprintf(vm_stderr, VM_STRING("Error: Video encoder GetInfo failed\n"));
return 7;
}
vm_string_printf(VM_STRING("\n"));
vm_string_printf(VM_STRING("Starting %s encoding %s to file %s\n"), codecName, SrcFileName, DstFileName);
vm_string_printf(VM_STRING("Source video width = %d, height = %d, frameRate = %.2lf\n"),
mWidth, mHeight, FrameRate);
vm_string_printf(VM_STRING("Max frames to encode = %d\n"), maxNumFrames);
if (pEncoderParams->info.bitrate > 0)
vm_string_printf(VM_STRING("Encoding bit rate = %d bits per second\n"), pEncoderParams->info.bitrate);
else
vm_string_printf(VM_STRING("Encoding without rate control\n"));
m_csysinfo.GetCpuUsage();
DumpPerf0();
Run();
fullTime = GetTick() - t_start;
m_csysinfo.GetCpuUsage();
DumpPerf1();
vm_string_printf(VM_STRING("\nSummary:\n"));
vm_string_printf(VM_STRING(" Num frames encoded = %d\n"), mFramesEncoded);
vm_string_printf(VM_STRING(" Encoding Time = %.2f sec, %.2f fps\n"), encodingTime, mFramesEncoded/encodingTime);
vm_string_printf(VM_STRING(" Overall Time = %.2f sec, %.2f fps\n"), fullTime, mFramesEncoded/fullTime);
vm_string_printf(VM_STRING(" Average CPU usage = %.2lf%%\n"), m_csysinfo.GetAvgCpuUsage());
vm_string_printf(VM_STRING(" Encoded Size = %d bytes\n"), encodedSize);
vm_string_printf(VM_STRING(" Compression Ratio = %.2f\n"), ((Ipp64f)mFramesEncoded*mFrameSize)/encodedSize);
if (pEncoderParams->info.framerate > 0 && pEncoderParams->info.bitrate > 0) {
size_ratio = encodedSize/(((Ipp64f)mFramesEncoded/pEncoderParams->info.framerate)*(pEncoderParams->info.bitrate/8));
vm_string_printf(VM_STRING(" EncodedSize/ExpectedSize = %.2f\n"), size_ratio);
}
if (perf_file != NULL) {
vm_string_fprintf(perf_file, VM_STRING("Performance = %.2f fps"), mFramesEncoded/encodingTime);
vm_string_fprintf(perf_file, VM_STRING(", EncodedSize/ExpectedSize = %.2f\n"), size_ratio);
vm_string_fprintf(perf_file, VM_STRING("num = %d"), mFramesEncoded);
vm_string_fprintf(perf_file, VM_STRING("performance = %.5f"), mFramesEncoded/encodingTime);
vm_string_fprintf(perf_file, VM_STRING("perf_overall = %.5f"), fullTime);
vm_string_fprintf(perf_file, VM_STRING("size_ratio = %.5f"), ((Ipp64f)mFramesEncoded*mFrameSize)/encodedSize);
vm_file_fclose(perf_file);
}
if (dstFile) {
vm_file_fclose(dstFile);
dstFile = NULL;
}
if (srcFile) {
vm_file_fclose(srcFile);
srcFile = NULL;
}
return 0;
}
void VideoEncodingTest::DumpPerf0()
{
sSystemInfo* m_ssysteminfo = (sSystemInfo *)m_csysinfo.GetSysInfo();
vm_char* stream_name = NULL;
vm_file *perf_file_csv = NULL;
vm_char tmpbuf[128]={0,};
if(PerfFileName)
perf_file_csv = vm_file_open(PerfFileName, VM_STRING("a"));
if(perf_file_csv){
IppLibraryVersion *ipplibversion;
stream_name = vm_string_strrchr(SrcFileName, (Ipp32s)('\\'));
if(!stream_name)stream_name = SrcFileName;
else stream_name++;
vm_file_fseek( perf_file_csv, 0, VM_FILE_SEEK_END);
if(!vm_file_ftell( perf_file_csv))
vm_string_fprintf(perf_file_csv, VM_STRING("Date,Time,Comp.name,OS,CPU,Num.CPU,CPU freq.,MEM,VGA,App,App description,Ver.,Ipp Type,Ipp ver.,Ipp Desc.,Streams(S) name,Output S. name,Status,Output S. size,S.Type,S.Res.,S.FR,S.BR,Video(V)Type,V.Format,V.Num,R.S.BR,V.E/D(FpS),V.E/D(MHz),Compr.(%%),CPU Usage (%%),Max Cpu Usage (%%),Work.Time,1e,2e,3e,4e,5e,\n"));
vm_sys_info_get_date(tmpbuf,MMDDYY);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), tmpbuf);
vm_sys_info_get_time(tmpbuf,HHMMSS);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), tmpbuf);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), m_ssysteminfo->computer_name);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), m_ssysteminfo->os_name);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), m_ssysteminfo->proc_name);
vm_string_fprintf(perf_file_csv,VM_STRING("%d,"), m_ssysteminfo->num_proc);
vm_string_fprintf(perf_file_csv,VM_STRING("%.2f,"), (Ipp64f)m_ssysteminfo->cpu_freq);
vm_string_fprintf(perf_file_csv,VM_STRING("%d,"), m_ssysteminfo->phys_mem);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), m_ssysteminfo->video_card);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"),m_ssysteminfo->program_name);
vm_string_fprintf(perf_file_csv,VM_STRING("UMC Video Encoder Con.,"));//,m_ssysteminfo->description);
vm_string_fprintf(perf_file_csv,VM_STRING(",")); // ver. of aplications
ipplibversion = (IppLibraryVersion*)ippvcGetLibVersion();
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), ipplibversion->targetCpu);
vm_string_fprintf(perf_file_csv,VM_STRING("%d.%d.%d.%d,"), ipplibversion->major,ipplibversion->minor,ipplibversion->majorBuild,ipplibversion->build);
vm_string_fprintf(perf_file_csv,VM_STRING("%s (%s),"), ipplibversion->Version,ipplibversion->BuildDate);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), stream_name);
stream_name = vm_string_strrchr(DstFileName, (Ipp32s)('\\'));
if(!stream_name)stream_name = DstFileName;
else stream_name++;
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), stream_name);
vm_string_fprintf(perf_file_csv,VM_STRING("FAIL,\n"));
vm_file_fclose(perf_file_csv);
}
}
void VideoEncodingTest::DumpPerf1()
{
sSystemInfo* m_ssysteminfo = (sSystemInfo *)m_csysinfo.GetSysInfo();
vm_file *perf_file_csv = NULL;
if(PerfFileName)
perf_file_csv = vm_file_open(PerfFileName, VM_STRING("r+"));
if(perf_file_csv) {
vm_file_fseek( perf_file_csv, -6, VM_FILE_SEEK_END);
vm_string_fprintf(perf_file_csv,VM_STRING("PASSED,"));
vm_string_fprintf(perf_file_csv,VM_STRING("%d,"), encodedSize);
vm_string_fprintf(perf_file_csv,VM_STRING("PV,"));
vm_string_fprintf(perf_file_csv,VM_STRING("%dx%d,"),pEncoderParams->info.clip_info.width,pEncoderParams->info.clip_info.height);
vm_string_fprintf(perf_file_csv,VM_STRING("%.2lf,"),pEncoderParams->info.framerate);
vm_string_fprintf(perf_file_csv,VM_STRING("%d,"),pEncoderParams->info.bitrate/1000);
vm_string_fprintf(perf_file_csv,VM_STRING("%s,"), codecName);
vm_string_fprintf(perf_file_csv,VM_STRING(","));
vm_string_fprintf(perf_file_csv,VM_STRING("%d,"), mFramesEncoded);
vm_string_fprintf(perf_file_csv,VM_STRING("%d,"), (Ipp32s)(encodedSize/mFramesEncoded*pEncoderParams->info.framerate*8/1000));
vm_string_fprintf(perf_file_csv,VM_STRING("%.2lf,"), mFramesEncoded/encodingTime);
vm_string_fprintf(perf_file_csv,VM_STRING("%.2lf,"), (Ipp64f)(pEncoderParams->info.framerate/(mFramesEncoded/encodingTime)*(m_ssysteminfo->cpu_freq)));
vm_string_fprintf(perf_file_csv,VM_STRING("%.2lf,"), ((Ipp64f)encodedSize*100.0/(mFramesEncoded*mFrameSize)));
vm_string_fprintf(perf_file_csv,VM_STRING("%.2lf,"), m_csysinfo.GetAvgCpuUsage());
vm_string_fprintf(perf_file_csv,VM_STRING("%.2lf,"), m_csysinfo.GetMaxCpuUsage());
vm_string_fprintf(perf_file_csv,VM_STRING("%02d:%02d:%02d.%02d,"),(Ipp32s)fullTime/3600,(Ipp32s)(fullTime)%3600/60,(Ipp32s)fullTime%3600%60,(Ipp32s)((fullTime-(Ipp32s)fullTime)*100));
vm_string_fprintf(perf_file_csv,VM_STRING("\n" ));
#if 0
if (FrameSize) {
vm_string_fprintf(perf_file_csv,VM_STRING("Frame Info\nNum, Size\n"));
for (i = 0; i < mFramesEncoded; i ++)
vm_string_fprintf(perf_file_csv,VM_STRING("%d, %d\n"), i, FrameSize[i]);
}
#endif
vm_file_fclose(perf_file_csv);
}
}
#ifndef NO_MAIN
int main(Ipp32s argc, vm_char *argv[])
{
VideoEncodingTest Encode;
return Encode.Main(argc, argv);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -