comparison libmpcodecs/ve_x264.c @ 14468:05518b274cdf

sync to x264 r93: Change the mechanics of option "keyint": Now controls the GOP size directly and allows variable numbers of non-IDR I-frames within a GOP. Remove option "idrint" and replace it with "keyint_min". Add option "8x8mv" for the sake of completeness.
author lorenm
date Wed, 12 Jan 2005 09:54:56 +0000
parents fba04febec4e
children a76f1a68ed75
comparison
equal deleted inserted replaced
14467:d03e8e7f9b26 14468:05518b274cdf
47 #include "mp_image.h" 47 #include "mp_image.h"
48 #include "vf.h" 48 #include "vf.h"
49 49
50 #include <x264.h> 50 #include <x264.h>
51 51
52 #if X264_BUILD < 0x000d 52 #if X264_BUILD < 0x000e
53 #error We do not support old versions of x264. Get the latest from SVN. 53 #error We do not support old versions of x264. Get the latest from SVN.
54 #endif 54 #endif
55 55
56 typedef struct _h264_module_t { 56 typedef struct _h264_module_t {
57 muxer_stream_t *mux; 57 muxer_stream_t *mux;
63 extern char* passtmpfile; 63 extern char* passtmpfile;
64 64
65 static int bitrate = -1; 65 static int bitrate = -1;
66 static int qp_constant = 26; 66 static int qp_constant = 26;
67 static int frame_ref = 1; 67 static int frame_ref = 1;
68 static int iframe = 250; 68 static int keyint_max = 250;
69 static int idrframe = 2; 69 static int keyint_min = -1;
70 static int scenecut_threshold = 40; 70 static int scenecut_threshold = 40;
71 static int bframe = 0; 71 static int bframe = 0;
72 static int deblock = 1; 72 static int deblock = 1;
73 static int deblockalpha = 0; 73 static int deblockalpha = 0;
74 static int deblockbeta = 0; 74 static int deblockbeta = 0;
75 static int cabac = 1; 75 static int cabac = 1;
76 static int cabacidc = -1; 76 static int cabacidc = -1;
77 static int p4x4mv = 0; 77 static int p4x4mv = 0;
78 static int p8x8mv = 1;
78 static int b8x8mv = 1; 79 static int b8x8mv = 1;
79 static int direct_pred = X264_DIRECT_PRED_TEMPORAL; 80 static int direct_pred = X264_DIRECT_PRED_TEMPORAL;
80 static float ip_factor = 1.4; 81 static float ip_factor = 1.4;
81 static float pb_factor = 1.3; 82 static float pb_factor = 1.3;
82 static int rc_buffer_size = -1; 83 static int rc_buffer_size = -1;
96 97
97 m_option_t x264encopts_conf[] = { 98 m_option_t x264encopts_conf[] = {
98 {"bitrate", &bitrate, CONF_TYPE_INT, CONF_RANGE, 0, 24000000, NULL}, 99 {"bitrate", &bitrate, CONF_TYPE_INT, CONF_RANGE, 0, 24000000, NULL},
99 {"qp_constant", &qp_constant, CONF_TYPE_INT, CONF_RANGE, 1, 51, NULL}, 100 {"qp_constant", &qp_constant, CONF_TYPE_INT, CONF_RANGE, 1, 51, NULL},
100 {"frameref", &frame_ref, CONF_TYPE_INT, CONF_RANGE, 1, 15, NULL}, 101 {"frameref", &frame_ref, CONF_TYPE_INT, CONF_RANGE, 1, 15, NULL},
101 {"keyint", &iframe, CONF_TYPE_INT, CONF_RANGE, 1, 24000000, NULL}, 102 {"keyint", &keyint_max, CONF_TYPE_INT, CONF_RANGE, 1, 24000000, NULL},
102 {"idrint", &idrframe, CONF_TYPE_INT, CONF_RANGE, 1, 24000000, NULL}, 103 {"keyint_min", &keyint_min, CONF_TYPE_INT, CONF_RANGE, 1, 24000000, NULL},
103 {"scenecut", &scenecut_threshold, CONF_TYPE_INT, CONF_RANGE, -1, 100, NULL}, 104 {"scenecut", &scenecut_threshold, CONF_TYPE_INT, CONF_RANGE, -1, 100, NULL},
104 {"bframes", &bframe, CONF_TYPE_INT, CONF_RANGE, 0, 16, NULL}, 105 {"bframes", &bframe, CONF_TYPE_INT, CONF_RANGE, 0, 16, NULL},
105 {"deblock", &deblock, CONF_TYPE_FLAG, 0, 0, 1, NULL}, 106 {"deblock", &deblock, CONF_TYPE_FLAG, 0, 0, 1, NULL},
106 {"nodeblock", &deblock, CONF_TYPE_FLAG, 0, 1, 0, NULL}, 107 {"nodeblock", &deblock, CONF_TYPE_FLAG, 0, 1, 0, NULL},
107 {"deblockalpha", &deblockalpha, CONF_TYPE_INT, CONF_RANGE, -6, 6, NULL}, 108 {"deblockalpha", &deblockalpha, CONF_TYPE_INT, CONF_RANGE, -6, 6, NULL},
109 {"cabac", &cabac, CONF_TYPE_FLAG, 0, 0, 1, NULL}, 110 {"cabac", &cabac, CONF_TYPE_FLAG, 0, 0, 1, NULL},
110 {"nocabac", &cabac, CONF_TYPE_FLAG, 0, 1, 0, NULL}, 111 {"nocabac", &cabac, CONF_TYPE_FLAG, 0, 1, 0, NULL},
111 {"cabacidc", &cabacidc, CONF_TYPE_INT, CONF_RANGE, -1, 2, NULL}, 112 {"cabacidc", &cabacidc, CONF_TYPE_INT, CONF_RANGE, -1, 2, NULL},
112 {"4x4mv", &p4x4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL}, 113 {"4x4mv", &p4x4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL},
113 {"no4x4mv", &p4x4mv, CONF_TYPE_FLAG, 0, 1, 0, NULL}, 114 {"no4x4mv", &p4x4mv, CONF_TYPE_FLAG, 0, 1, 0, NULL},
115 {"8x8mv", &p8x8mv, CONF_TYPE_FLAG, 0, 0, 1, NULL},
116 {"no8x8mv", &p8x8mv, CONF_TYPE_FLAG, 0, 1, 0, NULL},
114 {"b8x8mv", &b8x8mv, CONF_TYPE_FLAG, 0, 0, 1, NULL}, 117 {"b8x8mv", &b8x8mv, CONF_TYPE_FLAG, 0, 0, 1, NULL},
115 {"nob8x8mv", &b8x8mv, CONF_TYPE_FLAG, 0, 1, 0, NULL}, 118 {"nob8x8mv", &b8x8mv, CONF_TYPE_FLAG, 0, 1, 0, NULL},
116 {"direct_pred", &direct_pred, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, 119 {"direct_pred", &direct_pred, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
117 {"ip_factor", &ip_factor, CONF_TYPE_FLOAT, CONF_RANGE, -10.0, 10.0, NULL}, 120 {"ip_factor", &ip_factor, CONF_TYPE_FLOAT, CONF_RANGE, -10.0, 10.0, NULL},
118 {"pb_factor", &pb_factor, CONF_TYPE_FLOAT, CONF_RANGE, -10.0, 10.0, NULL}, 121 {"pb_factor", &pb_factor, CONF_TYPE_FLOAT, CONF_RANGE, -10.0, 10.0, NULL},
141 mod->mux->bih->biHeight = height; 144 mod->mux->bih->biHeight = height;
142 mod->mux->aspect = (float)d_width/d_height; 145 mod->mux->aspect = (float)d_width/d_height;
143 146
144 x264_param_default(&mod->param); 147 x264_param_default(&mod->param);
145 mod->param.i_frame_reference = frame_ref; 148 mod->param.i_frame_reference = frame_ref;
146 mod->param.i_idrframe = idrframe; 149 mod->param.i_keyint_max = keyint_max;
147 mod->param.i_iframe = iframe; 150 mod->param.i_keyint_min = keyint_min > 0 ? keyint_min : keyint_max * 2 / 5;
148 mod->param.i_scenecut_threshold = scenecut_threshold; 151 mod->param.i_scenecut_threshold = scenecut_threshold;
149 mod->param.i_bframe = bframe; 152 mod->param.i_bframe = bframe;
150 mod->param.b_deblocking_filter = deblock; 153 mod->param.b_deblocking_filter = deblock;
151 mod->param.i_deblocking_filter_alphac0 = deblockalpha; 154 mod->param.i_deblocking_filter_alphac0 = deblockalpha;
152 mod->param.i_deblocking_filter_beta = deblockbeta; 155 mod->param.i_deblocking_filter_beta = deblockbeta;
204 mod->param.rc.i_rc_init_buffer = rc_buffer_size * rc_init_buffer; 207 mod->param.rc.i_rc_init_buffer = rc_buffer_size * rc_init_buffer;
205 mod->param.rc.i_rc_sens = rc_sens; 208 mod->param.rc.i_rc_sens = rc_sens;
206 } 209 }
207 mod->param.rc.f_ip_factor = ip_factor; 210 mod->param.rc.f_ip_factor = ip_factor;
208 mod->param.rc.f_pb_factor = pb_factor; 211 mod->param.rc.f_pb_factor = pb_factor;
209 mod->param.analyse.inter = X264_ANALYSE_I4x4 | X264_ANALYSE_PSUB16x16; 212 mod->param.analyse.inter = X264_ANALYSE_I4x4;
210 if(p4x4mv) 213 if(p4x4mv)
211 mod->param.analyse.inter |= X264_ANALYSE_PSUB8x8; 214 mod->param.analyse.inter |= X264_ANALYSE_PSUB8x8;
215 if(p8x8mv)
216 mod->param.analyse.inter |= X264_ANALYSE_PSUB16x16;
212 if(b8x8mv) 217 if(b8x8mv)
213 mod->param.analyse.inter |= X264_ANALYSE_BSUB16x16; 218 mod->param.analyse.inter |= X264_ANALYSE_BSUB16x16;
214 mod->param.analyse.i_direct_mv_pred = direct_pred; 219 mod->param.analyse.i_direct_mv_pred = direct_pred;
215 220
216 mod->param.i_width = width; 221 mod->param.i_width = width;
322 int i_data = mod->mux->buffer_size - i_size; 327 int i_data = mod->mux->buffer_size - i_size;
323 i_size += x264_nal_encode(mod->mux->buffer + i_size, &i_data, 1, &nal[i]); 328 i_size += x264_nal_encode(mod->mux->buffer + i_size, &i_data, 1, &nal[i]);
324 } 329 }
325 if(i_size>0) { 330 if(i_size>0) {
326 int keyframe = (mod->pic.i_type == X264_TYPE_IDR) || 331 int keyframe = (mod->pic.i_type == X264_TYPE_IDR) ||
327 (mod->pic.i_type == X264_TYPE_I && frame_ref == 1); 332 (mod->pic.i_type == X264_TYPE_I
333 && frame_ref == 1 && !bframe);
328 muxer_write_chunk(mod->mux, i_size, keyframe?0x10:0); 334 muxer_write_chunk(mod->mux, i_size, keyframe?0x10:0);
329 } 335 }
330 return 1; 336 return 1;
331 } 337 }
332 338