From 8601262cd08c781a6dd47aa199d7717027227b2a Mon Sep 17 00:00:00 2001 From: Zhou Chang Date: Wed, 27 Jul 2011 14:44:32 +0800 Subject: [PATCH] test/encode/avcenc: Fixed bug about B frame display order wrong. Signed-off-by: Zhou Chang --- test/encode/avcenc.c | 77 +++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/test/encode/avcenc.c b/test/encode/avcenc.c index 0627bfd..197b284 100644 --- a/test/encode/avcenc.c +++ b/test/encode/avcenc.c @@ -1069,23 +1069,7 @@ encode_picture(FILE *yuv_fp, FILE *avc_fp, end_picture(slice_type, next_is_bpic); } -static void encode_i_picture(FILE *yuv_fp, FILE *avc_fp, int f, int is_idr) -{ - encode_picture(yuv_fp, avc_fp, - enc_frame_number, f, - is_idr, - SLICE_TYPE_I, 0, f + 1); -} - -static void encode_p_picture(FILE *yuv_fp, FILE *avc_fp, int f) -{ - encode_picture(yuv_fp, avc_fp, - enc_frame_number, f, - 0, - SLICE_TYPE_P, 0, f + 1); -} - -static void encode_pb_pictures(FILE *yuv_fp, FILE *avc_fp, int f, int nbframes) +static void encode_pb_pictures(FILE *yuv_fp, FILE *avc_fp, int f, int nbframes, int next_f) { int i; encode_picture(yuv_fp, avc_fp, @@ -1103,7 +1087,7 @@ static void encode_pb_pictures(FILE *yuv_fp, FILE *avc_fp, int f, int nbframes) encode_picture(yuv_fp, avc_fp, enc_frame_number + 1, f + nbframes - 1, 0, - SLICE_TYPE_B, 0, f + nbframes + 1); + SLICE_TYPE_B, 0, next_f); } static void show_help() @@ -1315,28 +1299,47 @@ int main(int argc, char *argv[]) enc_frame_number = 0; for ( f = 0; f < frame_number; ) { //picture level loop - int is_intra = i_frame_only?1:(enc_frame_number % intra_period == 0); - int is_idr = (f == 0); - int is_bslice = 0; - - if ( ! is_intra && pb_period > 0) { - is_bslice = i_p_frame_only?0:(f % pb_period == 1) && (f < frame_number - 1); - } - - if ( is_intra ) { - encode_i_picture(yuv_fp, avc_fp, f, is_idr); - f++; - enc_frame_number++; - } else if ( is_bslice) { - encode_pb_pictures(yuv_fp, avc_fp, f, 2); //last parameter is continue B frames number - f += (1 + 2); - enc_frame_number++; - } else { - encode_p_picture(yuv_fp, avc_fp, f); + static int const frame_type_pattern[][2] = { {SLICE_TYPE_I,1}, + {SLICE_TYPE_P,3}, {SLICE_TYPE_P,3},{SLICE_TYPE_P,3}, + {SLICE_TYPE_P,3}, {SLICE_TYPE_P,3},{SLICE_TYPE_P,3}, + {SLICE_TYPE_P,3}, {SLICE_TYPE_P,3},{SLICE_TYPE_P,3}, + {SLICE_TYPE_P,2} }; + + if ( i_frame_only ) { + encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_I, 0, f+1); f++; enc_frame_number++; + } else if ( i_p_frame_only ) { + if ( (f % intra_period) == 0 ) { + encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_I, 0, f+1); + f++; + enc_frame_number++; + } else { + encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_P, 0, f+1); + f++; + enc_frame_number++; + } + } else { // follow the i,p,b pattern + static int fcurrent = 0; + int fnext; + + fcurrent = fcurrent % sizeof(frame_type_pattern)/sizeof(int[2]); + fnext = (fcurrent+1) % sizeof(frame_type_pattern)/sizeof(int[2]); + + if ( frame_type_pattern[fcurrent][0] == SLICE_TYPE_I ) { + encode_picture(yuv_fp, avc_fp,enc_frame_number, f, f==0, SLICE_TYPE_I, 0, + f+frame_type_pattern[fnext][1]); + f++; + enc_frame_number++; + } else { + encode_pb_pictures(yuv_fp, avc_fp, f, frame_type_pattern[fcurrent][1]-1, + f + frame_type_pattern[fcurrent][1] + frame_type_pattern[fnext][1] -1 ); + f += frame_type_pattern[fcurrent][1]; + enc_frame_number++; + } + + fcurrent++; } - printf("\r %d/%d ...", f+1, frame_number); fflush(stdout); } -- 2.7.4