Guest User

Untitled

a guest
Apr 19th, 2010
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.56 KB | None | 0 0
  1. Index: common/common.c
  2. ===================================================================
  3. --- common/common_orig.c
  4. +++ common/common.c
  5. @@ -693,6 +693,8 @@
  6. p->i_slice_max_mbs = atoi(value);
  7. OPT("slices")
  8. p->i_slice_count = atoi(value);
  9. + OPT("open-gop")
  10. + p->b_open_gop = atobool(value);
  11. OPT("cabac")
  12. p->b_cabac = atobool(value);
  13. OPT("cabac-idc")
  14. @@ -1225,9 +1227,9 @@
  15. s += sprintf( s, " bframes=%d", p->i_bframe );
  16. if( p->i_bframe )
  17. {
  18. - s += sprintf( s, " b_pyramid=%d b_adapt=%d b_bias=%d direct=%d wpredb=%d",
  19. + s += sprintf( s, " b_pyramid=%d b_adapt=%d b_bias=%d direct=%d wpredb=%d open_gop=%d",
  20. p->i_bframe_pyramid, p->i_bframe_adaptive, p->i_bframe_bias,
  21. - p->analyse.i_direct_mv_pred, p->analyse.b_weighted_bipred );
  22. + p->analyse.i_direct_mv_pred, p->analyse.b_weighted_bipred, p->b_open_gop );
  23. }
  24. s += sprintf( s, " wpredp=%d", p->analyse.i_weighted_pred > 0 ? p->analyse.i_weighted_pred : 0 );
  25.  
  26. Index: common/common.h
  27. ===================================================================
  28. --- common/common_orig.h
  29. +++ common/common.h
  30. @@ -297,6 +297,7 @@
  31. volatile uint8_t b_exit_thread;
  32. uint8_t b_thread_active;
  33. uint8_t b_analyse_keyframe;
  34. + int i_last_idr;
  35. int i_last_keyframe;
  36. int i_slicetype_length;
  37. x264_frame_t *last_nonb;
  38. @@ -441,6 +442,8 @@
  39. x264_frame_t *reference[16+2];
  40.  
  41. int i_last_keyframe; /* Frame number of the last keyframe */
  42. + int i_last_idr; /* Frame number of the last IDR (not RP)*/
  43. + int i_poc_last_open_gop; /* Stores poc of last i frame before pruning else -1*/
  44.  
  45. int i_input; /* Number of input frames already accepted */
  46.  
  47. Index: encoder/encoder.c
  48. ===================================================================
  49. --- encoder/encoder_orig.c
  50. +++ encoder/encoder.c
  51. @@ -566,6 +566,7 @@
  52. h->param.i_bframe_adaptive = X264_B_ADAPT_NONE;
  53. h->param.analyse.i_direct_mv_pred = 0;
  54. h->param.analyse.b_weighted_bipred = 0;
  55. + h->param.b_open_gop = 0;
  56. }
  57. if( h->param.b_intra_refresh && h->param.i_bframe_pyramid == X264_B_PYRAMID_NORMAL )
  58. {
  59. @@ -577,6 +578,11 @@
  60. x264_log( h, X264_LOG_WARNING, "ref > 1 + intra-refresh is not supported\n" );
  61. h->param.i_frame_reference = 1;
  62. }
  63. + if( h->param.b_intra_refresh && h->param.b_open_gop )
  64. + {
  65. + x264_log( h, X264_LOG_WARNING, "intra-refresh nullifies open gop\n" );
  66. + h->param.b_open_gop = 0;
  67. + }
  68. if( h->param.i_keyint_min == X264_KEYINT_MIN_AUTO )
  69. h->param.i_keyint_min = h->param.i_keyint_max / 10;
  70. h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 );
  71. @@ -944,9 +950,11 @@
  72. h->frames.b_have_lowres |= h->param.rc.b_stat_read && h->param.rc.i_vbv_buffer_size > 0;
  73. h->frames.b_have_sub8x8_esa = !!(h->param.analyse.inter & X264_ANALYSE_PSUB8x8);
  74.  
  75. - h->frames.i_last_keyframe = - h->param.i_keyint_max;
  76. + h->frames.i_last_idr =
  77. + h->frames.i_last_keyframe = - h->param.i_keyint_max;
  78. h->frames.i_input = 0;
  79. h->frames.i_largest_pts = h->frames.i_second_largest_pts = -1;
  80. + h->frames.i_poc_last_open_gop = -1;
  81.  
  82. CHECKED_MALLOCZERO( h->frames.unused[0], (h->frames.i_delay + 3) * sizeof(x264_frame_t *) );
  83. /* Allocate room for max refs plus a few extra just in case. */
  84. @@ -1658,9 +1666,11 @@
  85. static inline void x264_reference_hierarchy_reset( x264_t *h )
  86. {
  87. int ref;
  88. - int b_hasdelayframe = 0;
  89. - if( !h->param.i_bframe_pyramid )
  90. - return;
  91. + uint8_t b_hasdelayframe = 0;
  92. +
  93. + /* This function must handle b-pyramid and clear frames for open-gop */
  94. + if( h->param.i_bframe_pyramid != X264_B_PYRAMID_STRICT && !b_hasdelayframe && h->frames.i_poc_last_open_gop == -1 )
  95. + return;
  96.  
  97. /* look for delay frames -- chain must only contain frames that are disposable */
  98. for( int i = 0; h->frames.current[i] && IS_DISPOSABLE( h->frames.current[i]->i_type ); i++ )
  99. @@ -1674,20 +1684,24 @@
  100. * dpb during a BREF decode when pyramid == STRICT */
  101. for( ref = 0; h->frames.reference[ref]; ref++ )
  102. {
  103. - if( h->param.i_bframe_pyramid == X264_B_PYRAMID_STRICT
  104. + if( ( h->param.i_bframe_pyramid == X264_B_PYRAMID_STRICT
  105. && h->frames.reference[ref]->i_type == X264_TYPE_BREF )
  106. + || ( h->frames.i_poc_last_open_gop >= 0
  107. + && h->frames.i_poc_last_open_gop != h->frames.reference[ref]->i_poc
  108. + && h->sh.i_type != SLICE_TYPE_B ) )
  109. {
  110. int diff = h->i_frame_num - h->frames.reference[ref]->i_frame_num;
  111. h->sh.mmco[h->sh.i_mmco_command_count].i_difference_of_pic_nums = diff;
  112. h->sh.mmco[h->sh.i_mmco_command_count++].i_poc = h->frames.reference[ref]->i_poc;
  113. - x264_frame_push_unused( h, x264_frame_pop( h->frames.reference ) );
  114. + x264_frame_push_unused( h, x264_frame_shift( &h->frames.reference[ref] ) );
  115. h->b_ref_reorder[0] = 1;
  116. - break;
  117. + ref--;
  118. }
  119. }
  120.  
  121. - /* Prepare to room in the dpb for the delayed display time of the later b-frame's */
  122. - h->sh.i_mmco_remove_from_end = X264_MAX( ref + 2 - h->frames.i_max_dpb, 0 );
  123. + /* Prepare room in the dpb for the delayed display time of the later b-frame's */
  124. + if( h->param.i_bframe_pyramid )
  125. + h->sh.i_mmco_remove_from_end = X264_MAX( ref + 2 - h->frames.i_max_dpb, 0 );
  126. }
  127.  
  128. static inline void x264_slice_init( x264_t *h, int i_nal_type, int i_global_qp )
  129. @@ -2268,17 +2282,22 @@
  130. if( h->fenc->b_keyframe )
  131. {
  132. h->frames.i_last_keyframe = h->fenc->i_frame;
  133. - if( h->fenc->i_type == X264_TYPE_IDR )
  134. + if( IS_X264_TYPE_IDR( h->fenc->i_type, h->param.b_open_gop ) )
  135. + {
  136. h->i_frame_num = 0;
  137. + h->frames.i_last_idr = h->fenc->i_frame;
  138. + }
  139. }
  140. h->sh.i_mmco_command_count =
  141. h->sh.i_mmco_remove_from_end = 0;
  142. h->b_ref_reorder[0] =
  143. h->b_ref_reorder[1] = 0;
  144. + h->fdec->i_poc =
  145. + h->fenc->i_poc = 2 * ( h->fenc->i_frame - X264_MAX( h->frames.i_last_idr, 0 ) );
  146.  
  147. /* ------------------- Setup frame context ----------------------------- */
  148. /* 5: Init data dependent of frame type */
  149. - if( h->fenc->i_type == X264_TYPE_IDR )
  150. + if( IS_X264_TYPE_IDR( h->fenc->i_type, h->param.b_open_gop ) )
  151. {
  152. /* reset ref pictures */
  153. i_nal_type = NAL_SLICE_IDR;
  154. @@ -2286,12 +2305,14 @@
  155. h->sh.i_type = SLICE_TYPE_I;
  156. x264_reference_reset( h );
  157. }
  158. - else if( h->fenc->i_type == X264_TYPE_I )
  159. + else if( IS_X264_TYPE_RP( h->fenc->i_type, h->param.b_open_gop ) )
  160. {
  161. i_nal_type = NAL_SLICE;
  162. i_nal_ref_idc = NAL_PRIORITY_HIGH; /* Not completely true but for now it is (as all I/P are kept as ref)*/
  163. h->sh.i_type = SLICE_TYPE_I;
  164. x264_reference_hierarchy_reset( h );
  165. + if( h->param.b_open_gop )
  166. + h->frames.i_poc_last_open_gop = h->fenc->b_keyframe ? h->fenc->i_poc : -1;
  167. }
  168. else if( h->fenc->i_type == X264_TYPE_P )
  169. {
  170. @@ -2299,6 +2320,7 @@
  171. i_nal_ref_idc = NAL_PRIORITY_HIGH; /* Not completely true but for now it is (as all I/P are kept as ref)*/
  172. h->sh.i_type = SLICE_TYPE_P;
  173. x264_reference_hierarchy_reset( h );
  174. + h->frames.i_poc_last_open_gop = -1;
  175. }
  176. else if( h->fenc->i_type == X264_TYPE_BREF )
  177. {
  178. @@ -2314,8 +2336,6 @@
  179. h->sh.i_type = SLICE_TYPE_B;
  180. }
  181.  
  182. - h->fdec->i_poc =
  183. - h->fenc->i_poc = 2 * (h->fenc->i_frame - h->frames.i_last_keyframe);
  184. h->fdec->i_type = h->fenc->i_type;
  185. h->fdec->i_frame = h->fenc->i_frame;
  186. h->fenc->b_kept_as_ref =
  187. Index: encoder/ratecontrol.c
  188. ===================================================================
  189. --- encoder/ratecontrol_orig.c
  190. +++ encoder/ratecontrol.c
  191. @@ -674,6 +674,7 @@
  192. CMP_OPT_FIRST_PASS( "b_pyramid", h->param.i_bframe_pyramid );
  193. CMP_OPT_FIRST_PASS( "intra_refresh", h->param.b_intra_refresh );
  194. CMP_OPT_FIRST_PASS( "keyint", h->param.i_keyint_max );
  195. + CMP_OPT_FIRST_PASS( "open_gop", h->param.b_open_gop );
  196.  
  197. if( strstr( opts, "qp=0" ) && h->param.rc.i_rc_method == X264_RC_ABR )
  198. x264_log( h, X264_LOG_WARNING, "1st pass was lossless, bitrate prediction will be inaccurate\n" );
  199. Index: encoder/slicetype.c
  200. ===================================================================
  201. --- encoder/slicetype_orig.c
  202. +++ encoder/slicetype.c
  203. @@ -1085,7 +1085,6 @@
  204. orig_num_frames = num_frames = h->param.b_intra_refresh ? framecnt : X264_MIN( framecnt, keyint_limit );
  205.  
  206. x264_lowres_context_init( h, &a );
  207. - idr_frame_type = frames[1]->i_frame - h->lookahead->i_last_keyframe >= h->param.i_keyint_min ? X264_TYPE_IDR : X264_TYPE_I;
  208.  
  209. /* This is important psy-wise: if we have a non-scenecut keyframe,
  210. * there will be significant visual artifacts if the frames just before
  211. @@ -1097,12 +1096,12 @@
  212. {
  213. frames[1]->i_type = X264_TYPE_P;
  214. if( h->param.i_scenecut_threshold && scenecut( h, &a, frames, 0, 1, 1, orig_num_frames ) )
  215. - frames[1]->i_type = idr_frame_type;
  216. + frames[1]->i_type = X264_TYPE_I;
  217. return;
  218. }
  219. else if( num_frames == 0 )
  220. {
  221. - frames[1]->i_type = idr_frame_type;
  222. + frames[1]->i_type = X264_TYPE_I;
  223. return;
  224. }
  225.  
  226. @@ -1111,7 +1110,7 @@
  227. int reset_start;
  228. if( h->param.i_scenecut_threshold && scenecut( h, &a, frames, 0, 1, 1, orig_num_frames ) )
  229. {
  230. - frames[1]->i_type = idr_frame_type;
  231. + frames[1]->i_type = X264_TYPE_I;
  232. return;
  233. }
  234.  
  235. @@ -1219,9 +1218,7 @@
  236. {
  237. if( ((j-keyint_limit) % h->param.i_keyint_max) == 0 )
  238. {
  239. - if( j && h->param.i_keyint_max > 1 )
  240. - frames[j]->i_type = X264_TYPE_P;
  241. - frames[j+1]->i_type = X264_TYPE_IDR;
  242. + frames[j+1]->i_type = X264_TYPE_I;
  243. reset_start = X264_MIN( reset_start, j+2 );
  244. }
  245. }
  246. @@ -1311,12 +1308,23 @@
  247. /* Limit GOP size */
  248. if( (!h->param.b_intra_refresh || frm->i_frame == 0) && frm->i_frame - h->lookahead->i_last_keyframe >= h->param.i_keyint_max )
  249. {
  250. - if( frm->i_type == X264_TYPE_AUTO )
  251. - frm->i_type = X264_TYPE_IDR;
  252. - if( frm->i_type != X264_TYPE_IDR )
  253. + if( frm->i_type == X264_TYPE_AUTO || frm->i_type == X264_TYPE_I )
  254. + frm->i_type = h->param.b_open_gop && h->lookahead->i_last_keyframe >= 0 ? X264_TYPE_I : X264_TYPE_IDR;
  255. + if( frm->i_type != X264_TYPE_IDR && frm->i_type != X264_TYPE_I && frm->i_type != X264_TYPE_KEYFRAME )
  256. x264_log( h, X264_LOG_WARNING, "specified frame type (%d) is not compatible with keyframe interval\n", frm->i_type );
  257. }
  258. - if( frm->i_type == X264_TYPE_IDR )
  259. + if( frm->i_type == X264_TYPE_I && frm->i_frame - h->lookahead->i_last_keyframe >= h->param.i_keyint_min )
  260. + {
  261. + if( h->param.b_open_gop )
  262. + {
  263. + h->lookahead->i_last_keyframe = frm->i_frame;
  264. + frm->b_keyframe = 1;
  265. + }
  266. + else
  267. + frm->i_type = X264_TYPE_IDR;
  268. + }
  269. + // 'close' gop if type is IDR or RP for seeking
  270. + if( frm->i_type == X264_TYPE_IDR || frm->i_type == X264_TYPE_KEYFRAME )
  271. {
  272. /* Close GOP */
  273. h->lookahead->i_last_keyframe = frm->i_frame;
  274. Index: x264.c
  275. ===================================================================
  276. --- x264_orig.c
  277. +++ x264.c
  278. @@ -380,6 +380,8 @@
  279. " - strict: Strictly hierarchical pyramid\n"
  280. " - normal: Non-strict (not Blu-ray compatible)\n",
  281. strtable_lookup( x264_b_pyramid_names, defaults->i_bframe_pyramid ) );
  282. + H1( " --open-gop Use non IDR i-frames w/ recovery point SEI to\n"
  283. + " close GOPs; Only available with b-frames\n" );
  284. H1( " --no-cabac Disable CABAC\n" );
  285. H1( " -r, --ref <integer> Number of reference frames [%d]\n", defaults->i_frame_reference );
  286. H1( " --no-deblock Disable loop filter\n" );
  287. @@ -622,6 +624,7 @@
  288. { "no-b-adapt", no_argument, NULL, 0 },
  289. { "b-bias", required_argument, NULL, 0 },
  290. { "b-pyramid", required_argument, NULL, 0 },
  291. + { "open-gop", no_argument, NULL, 0 },
  292. { "min-keyint", required_argument, NULL, 'i' },
  293. { "keyint", required_argument, NULL, 'I' },
  294. { "intra-refresh", no_argument, NULL, 0 },
  295. @@ -1287,6 +1290,7 @@
  296. pic->i_qpplus1 = qp+1;
  297. if ( type == 'I' ) pic->i_type = X264_TYPE_IDR;
  298. else if( type == 'i' ) pic->i_type = X264_TYPE_I;
  299. + else if( type == 'K' ) pic->i_type = X264_TYPE_KEYFRAME;
  300. else if( type == 'P' ) pic->i_type = X264_TYPE_P;
  301. else if( type == 'B' ) pic->i_type = X264_TYPE_BREF;
  302. else if( type == 'b' ) pic->i_type = X264_TYPE_B;
  303. Index: x264.h
  304. ===================================================================
  305. --- x264_orig.h
  306. +++ x264.h
  307. @@ -136,7 +136,10 @@
  308. #define X264_TYPE_P 0x0003
  309. #define X264_TYPE_BREF 0x0004 /* Non-disposable B-frame */
  310. #define X264_TYPE_B 0x0005
  311. -#define IS_X264_TYPE_I(x) ((x)==X264_TYPE_I || (x)==X264_TYPE_IDR)
  312. +#define X264_TYPE_KEYFRAME 0x0006 /* IDR or I depending on b_open_gop option */
  313. +#define IS_X264_TYPE_I(x) ((x)==X264_TYPE_I || (x)==X264_TYPE_IDR || (x)==X264_TYPE_KEYFRAME)
  314. +#define IS_X264_TYPE_IDR(x,isopengop) ((x)==X264_TYPE_IDR || (x)==X264_TYPE_KEYFRAME && !(isopengop))
  315. +#define IS_X264_TYPE_RP(x,isopengop) ((x)==X264_TYPE_I || (x)==X264_TYPE_KEYFRAME && (isopengop))
  316. #define IS_X264_TYPE_B(x) ((x)==X264_TYPE_B || (x)==X264_TYPE_BREF)
  317.  
  318. /* Log level */
  319. @@ -222,6 +225,7 @@
  320. int i_bframe_adaptive;
  321. int i_bframe_bias;
  322. int i_bframe_pyramid; /* Keep some B-frames as references: 0=off, 1=strict hierarchical, 2=normal */
  323. + int b_open_gop;
  324.  
  325. int b_deblocking_filter;
  326. int i_deblocking_filter_alphac0; /* [-6, 6] -6 light filter, 6 strong */
Advertisement
Add Comment
Please, Sign In to add comment