X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=vp8_multi_resolution_encoder.c;h=81e71375dff8ac95100c098bfdd5402f16c8c0b6;hb=caf0f14f84b7d66a614bc6f83ca7b311dcda437b;hp=633c039ec59454cbcc12221672fd2cac60a179a1;hpb=2e0d55314c28c546d98595e4b3799ca451a5a777;p=profile%2Fivi%2Flibvpx.git diff --git a/vp8_multi_resolution_encoder.c b/vp8_multi_resolution_encoder.c index 633c039..81e7137 100644 --- a/vp8_multi_resolution_encoder.c +++ b/vp8_multi_resolution_encoder.c @@ -224,9 +224,6 @@ int main(int argc, char **argv) dsf[1] controls down sampling from level 1 to level 2; dsf[2] is not used. */ vpx_rational_t dsf[NUM_ENCODERS] = {{2, 1}, {2, 1}, {1, 1}}; - /* Encode starting from which resolution level. Normally it is 0 that - * means the original(highest) resolution. */ - int s_lvl = 0; if(argc!= (5+NUM_ENCODERS)) die("Usage: %s \n", @@ -240,21 +237,6 @@ int main(int argc, char **argv) if(width < 16 || width%2 || height <16 || height%2) die("Invalid resolution: %ldx%ld", width, height); - /* Check to see if we need to encode all resolution levels */ - for (i=0; i= NUM_ENCODERS) - { - printf("No encoding: total number of encoders is 0!"); - return 0; - } - /* Open input video file for encoding */ if(!(infile = fopen(argv[3], "rb"))) die("Failed to open %s for reading", argv[3]); @@ -262,6 +244,12 @@ int main(int argc, char **argv) /* Open output file for each encoder to output bitstreams */ for (i=0; i< NUM_ENCODERS; i++) { + if(!target_bitrate[i]) + { + outfile[i] = NULL; + continue; + } + if(!(outfile[i] = fopen(argv[i+4], "wb"))) die("Failed to open %s for writing", argv[i+4]); } @@ -300,8 +288,13 @@ int main(int argc, char **argv) cfg[0].g_lag_in_frames = 0; /* Disable automatic keyframe placement */ + /* Note: These 3 settings are copied to all levels. But, except the lowest + * resolution level, all other levels are set to VPX_KF_DISABLED internally. + */ //cfg[0].kf_mode = VPX_KF_DISABLED; - cfg[0].kf_min_dist = cfg[0].kf_max_dist = 1000; + cfg[0].kf_mode = VPX_KF_AUTO; + cfg[0].kf_min_dist = 0; + cfg[0].kf_max_dist = 150; cfg[0].rc_target_bitrate = target_bitrate[0]; /* Set target bitrate */ cfg[0].g_timebase.num = 1; /* Set fps */ @@ -342,15 +335,18 @@ int main(int argc, char **argv) else read_frame_p = read_frame_by_row; + for (i=0; i< NUM_ENCODERS; i++) + if(outfile[i]) + write_ivf_file_header(outfile[i], &cfg[i], 0); + /* Initialize multi-encoder */ - if(vpx_codec_enc_init_multi(&codec[s_lvl], interface, &cfg[s_lvl], s_lvl, - NUM_ENCODERS, - (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[s_lvl])) - die_codec(&codec[s_lvl], "Failed to initialize encoder"); + if(vpx_codec_enc_init_multi(&codec[0], interface, &cfg[0], NUM_ENCODERS, + (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[0])) + die_codec(&codec[0], "Failed to initialize encoder"); /* The extra encoding configuration parameters can be set as follows. */ /* Set encoding speed */ - for ( i=s_lvl; i=s_lvl ; i--) + for (i=NUM_ENCODERS-1; i>=0 ; i--) { got_data = 0; @@ -452,10 +443,9 @@ int main(int argc, char **argv) fclose(infile); - for (i=s_lvl; i< NUM_ENCODERS; i++) + printf("Processed %ld frames.\n",(long int)frame_cnt-1); + for (i=0; i< NUM_ENCODERS; i++) { - printf("Processed %ld frames.\n",(long int)frame_cnt-1); - /* Calculate PSNR and print it out */ if ( (show_psnr) && (psnr_count[i]>0) ) { @@ -475,16 +465,17 @@ int main(int argc, char **argv) if(vpx_codec_destroy(&codec[i])) die_codec(&codec[i], "Failed to destroy codec"); + vpx_img_free(&raw[i]); + + if(!outfile[i]) + continue; + /* Try to rewrite the file header with the actual frame count */ if(!fseek(outfile[i], 0, SEEK_SET)) write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1); - } - - for (i=0; i< NUM_ENCODERS; i++) - { fclose(outfile[i]); - vpx_img_free(&raw[i]); } + printf("\n"); return EXIT_SUCCESS; }