📄 umc_mpeg2_enc_put.cpp
字号:
2 , /* 5-bit codes */
0x0000000e, 0x00000000, 0x00000003, 0x0000000f, 0x00000000, 0xfffffffd,
11, /* 6-bit codes */
0x00000001, IPPVC_ESCAPE, IPPVC_ESCAPE,
0x0000000a, 0x00000002, 0x00000001, 0x0000000b, 0x00000002, 0xffffffff, 0x0000000e, 0x00000003, 0x00000001,
0x0000000f, 0x00000003, 0xffffffff, 0x0000000c, 0x00000001, 0x00000002, 0x0000000d, 0x00000001, 0xfffffffe,
0x00000038, 0x00000000, 0x00000004, 0x00000039, 0x00000000, 0xfffffffc, 0x0000003a, 0x00000000, 0x00000005,
0x0000003b, 0x00000000, 0xfffffffb,
8 , /* 7-bit codes */
0x0000000c, 0x00000004, 0x00000001, 0x0000000d, 0x00000004, 0xffffffff, 0x0000000e, 0x00000005, 0x00000001,
0x0000000f, 0x00000005, 0xffffffff, 0x0000000a, 0x00000000, 0x00000006, 0x0000000b, 0x00000000, 0xfffffffa,
0x00000008, 0x00000000, 0x00000007, 0x00000009, 0x00000000, 0xfffffff9,
18, /* 8-bit codes */
0x0000000c, 0x00000006, 0x00000001, 0x0000000d, 0x00000006, 0xffffffff, 0x00000008, 0x00000007, 0x00000001,
0x00000009, 0x00000007, 0xffffffff, 0x0000000e, 0x00000002, 0x00000002, 0x0000000f, 0x00000002, 0xfffffffe,
0x0000000a, 0x00000008, 0x00000001, 0x0000000b, 0x00000008, 0xffffffff, 0x000000f0, 0x00000009, 0x00000001,
0x000000f1, 0x00000009, 0xffffffff, 0x000000f2, 0x00000001, 0x00000003, 0x000000f3, 0x00000001, 0xfffffffd,
0x000000f4, 0x0000000a, 0x00000001, 0x000000f5, 0x0000000a, 0xffffffff, 0x000000f6, 0x00000000, 0x00000008,
0x000000f7, 0x00000000, 0xfffffff8, 0x000000f8, 0x00000000, 0x00000009, 0x000000f9, 0x00000000, 0xfffffff7,
28, /* 9-bit codes */
0x0000004c, 0x00000003, 0x00000002, 0x0000004d, 0x00000003, 0xfffffffe, 0x00000042, 0x0000000b, 0x00000001,
0x00000043, 0x0000000b, 0xffffffff, 0x0000004a, 0x0000000c, 0x00000001, 0x0000004b, 0x0000000c, 0xffffffff,
0x00000048, 0x0000000d, 0x00000001, 0x00000049, 0x0000000d, 0xffffffff, 0x0000004e, 0x00000001, 0x00000004,
0x0000004f, 0x00000001, 0xfffffffc, 0x000001f8, 0x00000002, 0x00000003, 0x000001f9, 0x00000002, 0xfffffffd,
0x000001fa, 0x00000004, 0x00000002, 0x000001fb, 0x00000004, 0xfffffffe, 0x00000046, 0x00000000, 0x0000000a,
0x00000047, 0x00000000, 0xfffffff6, 0x00000044, 0x00000000, 0x0000000b, 0x00000045, 0x00000000, 0xfffffff5,
0x00000040, 0x00000001, 0x00000005, 0x00000041, 0x00000001, 0xfffffffb, 0x000001f4, 0x00000000, 0x0000000c,
0x000001f5, 0x00000000, 0xfffffff4, 0x000001f6, 0x00000000, 0x0000000d, 0x000001f7, 0x00000000, 0xfffffff3,
0x000001fc, 0x00000000, 0x0000000e, 0x000001fd, 0x00000000, 0xfffffff2, 0x000001fe, 0x00000000, 0x0000000f,
0x000001ff, 0x00000000, 0xfffffff1,
6 , /* 10-bit codes */
0x00000008, 0x00000005, 0x00000002, 0x00000009, 0x00000005, 0xfffffffe, 0x0000000a, 0x0000000e, 0x00000001,
0x0000000b, 0x0000000e, 0xffffffff, 0x0000000e, 0x0000000f, 0x00000001, 0x0000000f, 0x0000000f, 0xffffffff,
4 , /* 11-bit codes */
0x0000001a, 0x00000010, 0x00000001, 0x0000001b, 0x00000010, 0xffffffff, 0x00000018, 0x00000002, 0x00000004,
0x00000019, 0x00000002, 0xfffffffc,
0, /* 12-bit codes */
20, /* 13-bit codes */
0x00000038, 0x00000003, 0x00000003, 0x00000039, 0x00000003, 0xfffffffd, 0x00000024, 0x00000004, 0x00000003,
0x00000025, 0x00000004, 0xfffffffd, 0x0000003c, 0x00000006, 0x00000002, 0x0000003d, 0x00000006, 0xfffffffe,
0x0000002a, 0x00000007, 0x00000002, 0x0000002b, 0x00000007, 0xfffffffe, 0x00000022, 0x00000008, 0x00000002,
0x00000023, 0x00000008, 0xfffffffe, 0x0000003e, 0x00000011, 0x00000001, 0x0000003f, 0x00000011, 0xffffffff,
0x00000034, 0x00000012, 0x00000001, 0x00000035, 0x00000012, 0xffffffff, 0x00000032, 0x00000013, 0x00000001,
0x00000033, 0x00000013, 0xffffffff, 0x0000002e, 0x00000014, 0x00000001, 0x0000002f, 0x00000014, 0xffffffff,
0x0000002c, 0x00000015, 0x00000001, 0x0000002d, 0x00000015, 0xffffffff,
24, /* 14-bit codes */
0x0000002c, 0x00000001, 0x00000006, 0x0000002d, 0x00000001, 0xfffffffa, 0x0000002a, 0x00000001, 0x00000007,
0x0000002b, 0x00000001, 0xfffffff9, 0x00000028, 0x00000002, 0x00000005, 0x00000029, 0x00000002, 0xfffffffb,
0x00000026, 0x00000003, 0x00000004, 0x00000027, 0x00000003, 0xfffffffc, 0x00000024, 0x00000005, 0x00000003,
0x00000025, 0x00000005, 0xfffffffd, 0x00000022, 0x00000009, 0x00000002, 0x00000023, 0x00000009, 0xfffffffe,
0x00000020, 0x0000000a, 0x00000002, 0x00000021, 0x0000000a, 0xfffffffe, 0x0000003e, 0x00000016, 0x00000001,
0x0000003f, 0x00000016, 0xffffffff, 0x0000003c, 0x00000017, 0x00000001, 0x0000003d, 0x00000017, 0xffffffff,
0x0000003a, 0x00000018, 0x00000001, 0x0000003b, 0x00000018, 0xffffffff, 0x00000038, 0x00000019, 0x00000001,
0x00000039, 0x00000019, 0xffffffff, 0x00000036, 0x0000001a, 0x00000001, 0x00000037, 0x0000001a, 0xffffffff,
32, /* 15-bit codes */
0x0000003e, 0x00000000, 0x00000010, 0x0000003f, 0x00000000, 0xfffffff0, 0x0000003c, 0x00000000, 0x00000011,
0x0000003d, 0x00000000, 0xffffffef, 0x0000003a, 0x00000000, 0x00000012, 0x0000003b, 0x00000000, 0xffffffee,
0x00000038, 0x00000000, 0x00000013, 0x00000039, 0x00000000, 0xffffffed, 0x00000036, 0x00000000, 0x00000014,
0x00000037, 0x00000000, 0xffffffec, 0x00000034, 0x00000000, 0x00000015, 0x00000035, 0x00000000, 0xffffffeb,
0x00000032, 0x00000000, 0x00000016, 0x00000033, 0x00000000, 0xffffffea, 0x00000030, 0x00000000, 0x00000017,
0x00000031, 0x00000000, 0xffffffe9, 0x0000002e, 0x00000000, 0x00000018, 0x0000002f, 0x00000000, 0xffffffe8,
0x0000002c, 0x00000000, 0x00000019, 0x0000002d, 0x00000000, 0xffffffe7, 0x0000002a, 0x00000000, 0x0000001a,
0x0000002b, 0x00000000, 0xffffffe6, 0x00000028, 0x00000000, 0x0000001b, 0x00000029, 0x00000000, 0xffffffe5,
0x00000026, 0x00000000, 0x0000001c, 0x00000027, 0x00000000, 0xffffffe4, 0x00000024, 0x00000000, 0x0000001d,
0x00000025, 0x00000000, 0xffffffe3, 0x00000022, 0x00000000, 0x0000001e, 0x00000023, 0x00000000, 0xffffffe2,
0x00000020, 0x00000000, 0x0000001f, 0x00000021, 0x00000000, 0xffffffe1,
32, /* 16-bit codes */
0x00000030, 0x00000000, 0x00000020, 0x00000031, 0x00000000, 0xffffffe0, 0x0000002e, 0x00000000, 0x00000021,
0x0000002f, 0x00000000, 0xffffffdf, 0x0000002c, 0x00000000, 0x00000022, 0x0000002d, 0x00000000, 0xffffffde,
0x0000002a, 0x00000000, 0x00000023, 0x0000002b, 0x00000000, 0xffffffdd, 0x00000028, 0x00000000, 0x00000024,
0x00000029, 0x00000000, 0xffffffdc, 0x00000026, 0x00000000, 0x00000025, 0x00000027, 0x00000000, 0xffffffdb,
0x00000024, 0x00000000, 0x00000026, 0x00000025, 0x00000000, 0xffffffda, 0x00000022, 0x00000000, 0x00000027,
0x00000023, 0x00000000, 0xffffffd9, 0x00000020, 0x00000000, 0x00000028, 0x00000021, 0x00000000, 0xffffffd8,
0x0000003e, 0x00000001, 0x00000008, 0x0000003f, 0x00000001, 0xfffffff8, 0x0000003c, 0x00000001, 0x00000009,
0x0000003d, 0x00000001, 0xfffffff7, 0x0000003a, 0x00000001, 0x0000000a, 0x0000003b, 0x00000001, 0xfffffff6,
0x00000038, 0x00000001, 0x0000000b, 0x00000039, 0x00000001, 0xfffffff5, 0x00000036, 0x00000001, 0x0000000c,
0x00000037, 0x00000001, 0xfffffff4, 0x00000034, 0x00000001, 0x0000000d, 0x00000035, 0x00000001, 0xfffffff3,
0x00000032, 0x00000001, 0x0000000e, 0x00000033, 0x00000001, 0xfffffff2,
32, /* 17-bit codes */
0x00000026, 0x00000001, 0x0000000f, 0x00000027, 0x00000001, 0xfffffff1, 0x00000024, 0x00000001, 0x00000010,
0x00000025, 0x00000001, 0xfffffff0, 0x00000022, 0x00000001, 0x00000011, 0x00000023, 0x00000001, 0xffffffef,
0x00000020, 0x00000001, 0x00000012, 0x00000021, 0x00000001, 0xffffffee, 0x00000028, 0x00000006, 0x00000003,
0x00000029, 0x00000006, 0xfffffffd, 0x00000034, 0x0000000b, 0x00000002, 0x00000035, 0x0000000b, 0xfffffffe,
0x00000032, 0x0000000c, 0x00000002, 0x00000033, 0x0000000c, 0xfffffffe, 0x00000030, 0x0000000d, 0x00000002,
0x00000031, 0x0000000d, 0xfffffffe, 0x0000002e, 0x0000000e, 0x00000002, 0x0000002f, 0x0000000e, 0xfffffffe,
0x0000002c, 0x0000000f, 0x00000002, 0x0000002d, 0x0000000f, 0xfffffffe, 0x0000002a, 0x00000010, 0x00000002,
0x0000002b, 0x00000010, 0xfffffffe, 0x0000003e, 0x0000001b, 0x00000001, 0x0000003f, 0x0000001b, 0xffffffff,
0x0000003c, 0x0000001c, 0x00000001, 0x0000003d, 0x0000001c, 0xffffffff, 0x0000003a, 0x0000001d, 0x00000001,
0x0000003b, 0x0000001d, 0xffffffff, 0x00000038, 0x0000001e, 0x00000001, 0x00000039, 0x0000001e, 0xffffffff,
0x00000036, 0x0000001f, 0x00000001, 0x00000037, 0x0000001f, 0xffffffff,
-1 /* end of table */
};
const IppiPoint MPEG2VideoEncoderBase::MV_ZERO = {0, 0};
// generate sequence header (6.2.2.1, 6.3.3)
void MPEG2VideoEncoderBase::PutSequenceHeader()
{
Ipp32s i;
PUT_START_CODE(SEQ_START_CODE); // sequence_header_code
PUT_BITS((encodeInfo.info.clip_info.width & 0xfff), 12); // horizontal_size_value
PUT_BITS((encodeInfo.info.clip_info.height & 0xfff), 12); // vertical_size_value
PUT_BITS(aspectRatio_code, 4); // aspect_ratio_information
PUT_BITS(frame_rate_code, 4); // frame_rate_code
PUT_BITS(((Ipp32s)ceil(encodeInfo.info.bitrate / 400.0) & 0x3ffff), 18); // bit_rate_value
PUT_BITS(1, 1); // marker_bit
PUT_BITS((encodeInfo.VBV_BufferSize & 0x3ff), 10); // vbv_buffer_size_value
PUT_BITS(0, 1); // constrained_parameters_flag
PUT_BITS(encodeInfo.CustomIntraQMatrix, 1); // load_intra_quantizer_matrix
if( encodeInfo.CustomIntraQMatrix )
for(i=0; i < 64; i++) // matrices are always downloaded in zig-zag order
PUT_BITS(IntraQMatrix[ZigZagScan[i]], 8); // intra_quantizer_matrix
PUT_BITS(encodeInfo.CustomNonIntraQMatrix, 1); // load_non_intra_quantizer_matrix
if( encodeInfo.CustomNonIntraQMatrix )
for(i=0; i < 64; i++)
PUT_BITS(NonIntraQMatrix[ZigZagScan[i]], 8); // non_intra_quantizer_matrix
}
// generate sequence extension (6.2.2.3, 6.3.5) header (MPEG-2 only)
void MPEG2VideoEncoderBase::PutSequenceExt()
{
Ipp32s chroma_format_code;
Ipp32s prog_seq = (encodeInfo.info.interlace_type == PROGRESSIVE) ? 1 : 0;
switch(encodeInfo.info.color_format) {
case YUV420: chroma_format_code = 1; break;
case YUV422: chroma_format_code = 2; break;
case YUV444: chroma_format_code = 3; break;
default: chroma_format_code = 1;
}
PUT_START_CODE(EXT_START_CODE); // extension_start_code
PUT_BITS(SEQ_ID, 4); // extension_start_code_identifier
PUT_BITS(( encodeInfo.profile << 4 ) | encodeInfo.level, 8); // profile_and_level_indication
PUT_BITS(prog_seq, 1); // progressive sequence
PUT_BITS(chroma_format_code, 2); // chroma_format
PUT_BITS(encodeInfo.info.clip_info.width >> 12, 2); // horizontal_size_extension
PUT_BITS(encodeInfo.info.clip_info.height >> 12, 2); // vertical_size_extension
PUT_BITS(((Ipp32s)ceil(encodeInfo.info.bitrate / 400.0)) >> 18, 12); // bit_rate_extension
PUT_BITS(1, 1); // marker_bit
PUT_BITS(encodeInfo.VBV_BufferSize >> 10, 8); // vbv_buffer_size_extension
PUT_BITS(0, 1); // low_delay (not implemented)
PUT_BITS(frame_rate_extension_n, 2);
PUT_BITS(frame_rate_extension_d, 5);
}
// generate sequence display extension (6.2.2.4, 6.3.6)
void MPEG2VideoEncoderBase::PutSequenceDisplayExt()
{
PUT_START_CODE(EXT_START_CODE); // extension_start_code
PUT_BITS(DISP_ID, 4); // extension_start_code_identifier
PUT_BITS(1, 3); // video_format
PUT_BITS(1, 1); // colour_description
PUT_BITS(5, 8); // colour_primaries
PUT_BITS(5, 8); // transfer_characteristics
PUT_BITS(5, 8); // matrix_coefficients
PUT_BITS(encodeInfo.info.clip_info.width, 14); // display_horizontal_size
PUT_BITS(1, 1); // marker_bit
PUT_BITS(encodeInfo.info.clip_info.height, 14); // display_vertical_size
}
// put a zero terminated string as user data (6.2.2.2.2, 6.3.4.1)
void MPEG2VideoEncoderBase::PutUserData(Ipp32s part)
{
vm_char* ptr=0;
Ipp32s len=0, i;
// select data by part, no standard rules
if(part==0 && encodeInfo.idStr[0]) {
ptr = encodeInfo.idStr;
len = (Ipp32s)vm_string_strlen(ptr);
}
else if(part==2 && encodeInfo.UserData != 0 && encodeInfo.UserDataLen > 0) {
ptr = encodeInfo.UserData;
len = encodeInfo.UserDataLen;
}
if(len==0) return;
for(i=0; i<len-2; i++) { // stop len if start code happens
if(!ptr[i] && !ptr[i+1] && ptr[i+2]==1) {
// start code! - stop right before
break;
}
}
if(i>=len-2)
i = len;
if(i==0) return;
PUT_START_CODE(USER_START_CODE); // user_data_start_code
len = i;
for( i=0; i<len; i++ ) {
PUT_BITS((Ipp8u)(ptr[i]), 8);
}
}
// generate group of pictures header (6.2.2.6, 6.3.9)
void MPEG2VideoEncoderBase::PutGOPHeader(Ipp32s Count )
{
Ipp32s tc;
PUT_START_CODE(GOP_START_CODE);
tc = FrameToTimecode(Count);
PUT_BITS(tc, 25); // time_code
//closed_gop = (Count && encodeInfo.IPDistance>1)?0:1;
PUT_BITS(closed_gop, 1); // closed_gop (all except first GOP are open)
PUT_BITS(0, 1); // broken_link
}
Ipp32s MPEG2VideoEncoderBase::FrameToTimecode(Ipp32s frame)
{
Ipp32s fps, pict, sec, minute, hour, tc;
fps = (Ipp32s)(encodeInfo.info.framerate + 0.5);
pict = frame % fps;
frame = (frame - pict) / fps;
sec = frame % 60;
frame = (frame - sec) / 60;
minute = frame % 60;
frame = (frame - minute) / 60;
hour = frame % 24;
tc = (hour<<19) | (minute<<13) | (1<<12) | (sec<<6) | pict;
return tc;
}
// generate picture header (6.2.3, 6.3.9)
void MPEG2VideoEncoderBase::PutPictureHeader()
{
PUT_START_CODE(PICTURE_START_CODE); // picture_start_code
PUT_BITS((temporal_reference & 0x3ff), 10); // temporal_reference
PUT_BITS(picture_coding_type, 3); // picture_coding_type
PUT_BITS(vbv_delay, 16); // vbv_delay
if( picture_coding_type == P_PICTURE || picture_coding_type == B_PICTURE )
{
PUT_BITS(0, 1); // full_pel_forward_vector
PUT_BITS(7, 3); // forward_f_code
}
if( picture_coding_type == B_PICTURE )
{
PUT_BITS(0, 1); // full_pel_backward_vector
PUT_BITS(7, 3); // backward_f_code
}
PUT_BITS(0, 1); // extra_bit_picture
}
// generate picture coding extension (6.2.3.1, 6.3.11)
void MPEG2VideoEncoderBase::PutPictureCodingExt()
{
Ipp32s chroma_420_type;
PUT_START_CODE(EXT_START_CODE); // extension_start_code
PUT_BITS(CODING_ID, 4); // extension_start_code_identifier
if(mp_f_code == 0) {
PUT_BITS(0xffff, 16); // forward_horizontal_f_code
} else {
PUT_BITS(mp_f_code[0][0], 4); // forward_horizontal_f_code
PUT_BITS(mp_f_code[0][1], 4); // forward_vertical_f_code
PUT_BITS(mp_f_code[1][0], 4); // backward_horizontal_f_code
PUT_BITS(mp_f_code[1][1], 4); // backward_vertical_f_code
}
PUT_BITS(intra_dc_precision, 2); // encodeInfo.intra_dc_precision
PUT_BITS(picture_structure, 2); // picture_structure
PUT_BITS((picture_structure == FRAME_PICTURE) ? top_field_first : 0, 1);// top_field_first
PUT_BITS(curr_frame_pred, 1) // frame_pred_frame_dct
PUT_BITS(0, 1); // concealment_motion_vectors (not implemented yet)
PUT_BITS(q_scale_type, 1); // q_scale_type
PUT_BITS(curr_intra_vlc_format, 1); // intra_vlc_format
PUT_BITS(curr_scan, 1); // alternate_scan
PUT_BITS(repeat_first_field, 1); // repeat_first_field
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -