| @@ -224,9 +224,6 @@ int main(int argc, char **argv) · 223 unmodified lines |
| 224 | dsf[1] controls down sampling from level 1 to level 2; | 224 | dsf[1] controls down sampling from level 1 to level 2; |
| 225 | dsf[2] is not used. */ | 225 | dsf[2] is not used. */ |
| 226 | vpx_rational_t dsf[NUM_ENCODERS] = {{2, 1}, {2, 1}, {1, 1}}; | 226 | vpx_rational_t dsf[NUM_ENCODERS] = {{2, 1}, {2, 1}, {1, 1}}; |
| 227 | /* Encode starting from which resolution level. Normally it is 0 that | | |
| 228 | * means the original(highest) resolution. */ | | |
| 229 | int s_lvl = 0; | | |
| 230 | | 227 | |
| 231 | if(argc!= (5+NUM_ENCODERS)) | 228 | if(argc!= (5+NUM_ENCODERS)) |
| 232 | die("Usage: %s <width> <height> <infile> <outfile(s)> <output psnr?>\n", | 229 | die("Usage: %s <width> <height> <infile> <outfile(s)> <output psnr?>\n", |
| @@ -240,21 +237,6 @@ int main(int argc, char **argv) · 7 unmodified lines |
| 240 | if(width < 16 || width%2 || height <16 || height%2) | 237 | if(width < 16 || width%2 || height <16 || height%2) |
| 241 | die("Invalid resolution: %ldx%ld", width, height); | 238 | die("Invalid resolution: %ldx%ld", width, height); |
| 242 | | 239 | |
| 243 | /* Check to see if we need to encode all resolution levels */ | | |
| 244 | for (i=0; i<NUM_ENCODERS; i++) | | |
| 245 | { | | |
| 246 | if (target_bitrate[i]) | | |
| 247 | break; | | |
| 248 | else | | |
| 249 | s_lvl += 1; | | |
| 250 | } | | |
| 251 | | | |
| 252 | if (s_lvl >= NUM_ENCODERS) | | |
| 253 | { | | |
| 254 | printf("No encoding: total number of encoders is 0!"); | | |
| 255 | return 0; | | |
| 256 | } | | |
| 257 | | | |
| 258 | /* Open input video file for encoding */ | 240 | /* Open input video file for encoding */ |
| 259 | if(!(infile = fopen(argv[3], "rb"))) | 241 | if(!(infile = fopen(argv[3], "rb"))) |
| 260 | die("Failed to open %s for reading", argv[3]); | 242 | die("Failed to open %s for reading", argv[3]); |
| @@ -262,6 +244,12 @@ int main(int argc, char **argv) · 1 unmodified line |
| 262 | /* Open output file for each encoder to output bitstreams */ | 244 | /* Open output file for each encoder to output bitstreams */ |
| 263 | for (i=0; i< NUM_ENCODERS; i++) | 245 | for (i=0; i< NUM_ENCODERS; i++) |
| 264 | { | 246 | { |
| | 247 | if(!target_bitrate[i]) |
| | 248 | { |
| | 249 | outfile[i] = NULL; |
| | 250 | continue; |
| | 251 | } |
| | 252 | |
| 265 | if(!(outfile[i] = fopen(argv[i+4], "wb"))) | 253 | if(!(outfile[i] = fopen(argv[i+4], "wb"))) |
| 266 | die("Failed to open %s for writing", argv[i+4]); | 254 | die("Failed to open %s for writing", argv[i+4]); |
| 267 | } | 255 | } |
| @@ -342,15 +330,18 @@ int main(int argc, char **argv) · 74 unmodified lines |
| 342 | else | 330 | else |
| 343 | read_frame_p = read_frame_by_row; | 331 | read_frame_p = read_frame_by_row; |
| 344 | | 332 | |
| | 333 | for (i=0; i< NUM_ENCODERS; i++) |
| | 334 | if(outfile[i]) |
| | 335 | write_ivf_file_header(outfile[i], &cfg[i], 0); |
| | 336 | |
| 345 | /* Initialize multi-encoder */ | 337 | /* Initialize multi-encoder */ |
| 346 | if(vpx_codec_enc_init_multi(&codec[s_lvl], interface, &cfg[s_lvl], s_lvl, | 338 | if(vpx_codec_enc_init_multi(&codec[0], interface, &cfg[0], NUM_ENCODERS, |
| 347 | NUM_ENCODERS, | 339 | (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[0])) |
| 348 | (show_psnr ? VPX_CODEC_USE_PSNR : 0), &dsf[s_lvl])) | 340 | die_codec(&codec[0], "Failed to initialize encoder"); |
| 349 | die_codec(&codec[s_lvl], "Failed to initialize encoder"); | | |
| 350 | | 341 | |
| 351 | /* The extra encoding configuration parameters can be set as follows. */ | 342 | /* The extra encoding configuration parameters can be set as follows. */ |
| 352 | /* Set encoding speed */ | 343 | /* Set encoding speed */ |
| 353 | for ( i=s_lvl; i<NUM_ENCODERS; i++) | 344 | for ( i=0; i<NUM_ENCODERS; i++) |
| 354 | { | 345 | { |
| 355 | int speed = -6; | 346 | int speed = -6; |
| 356 | if(vpx_codec_control(&codec[i], VP8E_SET_CPUUSED, speed)) | 347 | if(vpx_codec_control(&codec[i], VP8E_SET_CPUUSED, speed)) |
| @@ -360,25 +351,20 @@ int main(int argc, char **argv) · 3 unmodified lines |
| 360 | * better performance. */ | 351 | * better performance. */ |
| 361 | { | 352 | { |
| 362 | unsigned int static_thresh = 1000; | 353 | unsigned int static_thresh = 1000; |
| 363 | if(vpx_codec_control(&codec[s_lvl], VP8E_SET_STATIC_THRESHOLD, | 354 | if(vpx_codec_control(&codec[0], VP8E_SET_STATIC_THRESHOLD, static_thresh)) |
| 364 | static_thresh)) | 355 | die_codec(&codec[0], "Failed to set static threshold"); |
| 365 | die_codec(&codec[s_lvl], "Failed to set static threshold"); | | |
| 366 | } | 356 | } |
| 367 | /* Set static thresh = 0 for other encoders for better quality */ | 357 | /* Set static thresh = 0 for other encoders for better quality */ |
| 368 | for ( i=s_lvl+1; i<NUM_ENCODERS; i++) | 358 | for ( i=1; i<NUM_ENCODERS; i++) |
| 369 | { | 359 | { |
| 370 | unsigned int static_thresh = 0; | 360 | unsigned int static_thresh = 0; |
| 371 | if(vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD, | 361 | if(vpx_codec_control(&codec[i], VP8E_SET_STATIC_THRESHOLD, static_thresh)) |
| 372 | static_thresh)) | | |
| 373 | die_codec(&codec[i], "Failed to set static threshold"); | 362 | die_codec(&codec[i], "Failed to set static threshold"); |
| 374 | } | 363 | } |
| 375 | | 364 | |
| 376 | frame_avail = 1; | 365 | frame_avail = 1; |
| 377 | got_data = 0; | 366 | got_data = 0; |
| 378 | | 367 | |
| 379 | for (i=s_lvl ; i< NUM_ENCODERS; i++) | | |
| 380 | write_ivf_file_header(outfile[i], &cfg[i], 0); | | |
| 381 | | | |
| 382 | while(frame_avail || got_data) | 368 | while(frame_avail || got_data) |
| 383 | { | 369 | { |
| 384 | vpx_codec_iter_t iter[NUM_ENCODERS]={NULL}; | 370 | vpx_codec_iter_t iter[NUM_ENCODERS]={NULL}; |
| @@ -405,11 +391,11 @@ int main(int argc, char **argv) · 20 unmodified lines |
| 405 | } | 391 | } |
| 406 | | 392 | |
| 407 | /* Encode each frame at multi-levels */ | 393 | /* Encode each frame at multi-levels */ |
| 408 | if(vpx_codec_encode(&codec[s_lvl], frame_avail? &raw[s_lvl] : NULL, | 394 | if(vpx_codec_encode(&codec[0], frame_avail? &raw[0] : NULL, |
| 409 | frame_cnt, 1, flags, arg_deadline)) | 395 | frame_cnt, 1, flags, arg_deadline)) |
| 410 | die_codec(&codec[s_lvl], "Failed to encode frame"); | 396 | die_codec(&codec[0], "Failed to encode frame"); |
| 411 | | 397 | |
| 412 | for (i=NUM_ENCODERS-1; i>=s_lvl ; i--) | 398 | for (i=NUM_ENCODERS-1; i>=0 ; i--) |
| 413 | { | 399 | { |
| 414 | got_data = 0; | 400 | got_data = 0; |
| 415 | | 401 | |
| @@ -452,10 +438,9 @@ int main(int argc, char **argv) · 36 unmodified lines |
| 452 | | 438 | |
| 453 | fclose(infile); | 439 | fclose(infile); |
| 454 | | 440 | |
| 455 | for (i=s_lvl; i< NUM_ENCODERS; i++) | 441 | printf("Processed %ld frames.\n",(long int)frame_cnt-1); |
| | 442 | for (i=0; i< NUM_ENCODERS; i++) |
| 456 | { | 443 | { |
| 457 | printf("Processed %ld frames.\n",(long int)frame_cnt-1); | | |
| 458 | | | |
| 459 | /* Calculate PSNR and print it out */ | 444 | /* Calculate PSNR and print it out */ |
| 460 | if ( (show_psnr) && (psnr_count[i]>0) ) | 445 | if ( (show_psnr) && (psnr_count[i]>0) ) |
| 461 | { | 446 | { |
| @@ -475,16 +460,17 @@ int main(int argc, char **argv) · 13 unmodified lines |
| 475 | if(vpx_codec_destroy(&codec[i])) | 460 | if(vpx_codec_destroy(&codec[i])) |
| 476 | die_codec(&codec[i], "Failed to destroy codec"); | 461 | die_codec(&codec[i], "Failed to destroy codec"); |
| 477 | | 462 | |
| | 463 | vpx_img_free(&raw[i]); |
| | 464 | |
| | 465 | if(!outfile[i]) |
| | 466 | continue; |
| | 467 | |
| 478 | /* Try to rewrite the file header with the actual frame count */ | 468 | /* Try to rewrite the file header with the actual frame count */ |
| 479 | if(!fseek(outfile[i], 0, SEEK_SET)) | 469 | if(!fseek(outfile[i], 0, SEEK_SET)) |
| 480 | write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1); | 470 | write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1); |
| 481 | } | | |
| 482 | | | |
| 483 | for (i=0; i< NUM_ENCODERS; i++) | | |
| 484 | { | | |
| 485 | fclose(outfile[i]); | 471 | fclose(outfile[i]); |
| 486 | vpx_img_free(&raw[i]); | | |
| 487 | } | 472 | } |
| | 473 | printf("\n"); |
| 488 | | 474 | |
| 489 | return EXIT_SUCCESS; | 475 | return EXIT_SUCCESS; |
| 490 | } | 476 | } |