| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 /* | 11 /* |
| 12 * This is an example demonstrating multi-resolution encoding in VP8. | 12 * This is an example demonstrating multi-resolution encoding in VP8. |
| 13 * High-resolution input video is down-sampled to lower-resolutions. The | 13 * High-resolution input video is down-sampled to lower-resolutions. The |
| 14 * encoder then encodes the video and outputs multiple bitstreams with | 14 * encoder then encodes the video and outputs multiple bitstreams with |
| 15 * different resolutions. | 15 * different resolutions. |
| 16 */ | 16 */ |
| 17 #include <stdio.h> | 17 #include <stdio.h> |
| 18 #include <stdlib.h> | 18 #include <stdlib.h> |
| 19 #include <stdarg.h> | 19 #include <stdarg.h> |
| 20 #include <string.h> | 20 #include <string.h> |
| 21 #include "math.h" | 21 #include <math.h> |
| 22 #define VPX_CODEC_DISABLE_COMPAT 1 | 22 #define VPX_CODEC_DISABLE_COMPAT 1 |
| 23 #include "vpx/vpx_encoder.h" | 23 #include "vpx/vpx_encoder.h" |
| 24 #include "vpx/vp8cx.h" | 24 #include "vpx/vp8cx.h" |
| 25 #include "vpx_ports/mem_ops.h" | 25 #include "vpx_ports/mem_ops.h" |
| 26 #include "./tools_common.h" |
| 26 #define interface (vpx_codec_vp8_cx()) | 27 #define interface (vpx_codec_vp8_cx()) |
| 27 #define fourcc 0x30385056 | 28 #define fourcc 0x30385056 |
| 28 | 29 |
| 29 #define IVF_FILE_HDR_SZ (32) | 30 #define IVF_FILE_HDR_SZ (32) |
| 30 #define IVF_FRAME_HDR_SZ (12) | 31 #define IVF_FRAME_HDR_SZ (12) |
| 31 | 32 |
| 32 /* | 33 /* |
| 33 * The input video frame is downsampled several times to generate a multi-level | 34 * The input video frame is downsampled several times to generate a multi-level |
| 34 * hierarchical structure. NUM_ENCODERS is defined as the number of encoding | 35 * hierarchical structure. NUM_ENCODERS is defined as the number of encoding |
| 35 * levels required. For example, if the size of input video is 1280x720, | 36 * levels required. For example, if the size of input video is 1280x720, |
| 36 * NUM_ENCODERS is 3, and down-sampling factor is 2, the encoder outputs 3 | 37 * NUM_ENCODERS is 3, and down-sampling factor is 2, the encoder outputs 3 |
| 37 * bitstreams with resolution of 1280x720(level 0), 640x360(level 1), and | 38 * bitstreams with resolution of 1280x720(level 0), 640x360(level 1), and |
| 38 * 320x180(level 2) respectively. | 39 * 320x180(level 2) respectively. |
| 39 */ | 40 */ |
| 40 #define NUM_ENCODERS 3 | 41 #define NUM_ENCODERS 3 |
| 41 | 42 |
| 42 /* This example uses the scaler function in libyuv. */ | 43 /* This example uses the scaler function in libyuv. */ |
| 43 #include "third_party/libyuv/include/libyuv/basic_types.h" | 44 #include "third_party/libyuv/include/libyuv/basic_types.h" |
| 44 #include "third_party/libyuv/include/libyuv/scale.h" | 45 #include "third_party/libyuv/include/libyuv/scale.h" |
| 45 #include "third_party/libyuv/include/libyuv/cpu_id.h" | 46 #include "third_party/libyuv/include/libyuv/cpu_id.h" |
| 46 | 47 |
| 47 static double vp8_mse2psnr(double Samples, double Peak, double Mse) | |
| 48 { | |
| 49 double psnr; | |
| 50 | |
| 51 if ((double)Mse > 0.0) | |
| 52 psnr = 10.0 * log10(Peak * Peak * Samples / Mse); | |
| 53 else | |
| 54 psnr = 60; // Limit to prevent / 0 | |
| 55 | |
| 56 if (psnr > 60) | |
| 57 psnr = 60; | |
| 58 | |
| 59 return psnr; | |
| 60 } | |
| 61 | |
| 62 static void die(const char *fmt, ...) { | 48 static void die(const char *fmt, ...) { |
| 63 va_list ap; | 49 va_list ap; |
| 64 | 50 |
| 65 va_start(ap, fmt); | 51 va_start(ap, fmt); |
| 66 vprintf(fmt, ap); | 52 vprintf(fmt, ap); |
| 67 if(fmt[strlen(fmt)-1] != '\n') | 53 if(fmt[strlen(fmt)-1] != '\n') |
| 68 printf("\n"); | 54 printf("\n"); |
| 69 exit(EXIT_FAILURE); | 55 exit(EXIT_FAILURE); |
| 70 } | 56 } |
| 71 | 57 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 433 |
| 448 fclose(infile); | 434 fclose(infile); |
| 449 | 435 |
| 450 printf("Processed %ld frames.\n",(long int)frame_cnt-1); | 436 printf("Processed %ld frames.\n",(long int)frame_cnt-1); |
| 451 for (i=0; i< NUM_ENCODERS; i++) | 437 for (i=0; i< NUM_ENCODERS; i++) |
| 452 { | 438 { |
| 453 /* Calculate PSNR and print it out */ | 439 /* Calculate PSNR and print it out */ |
| 454 if ( (show_psnr) && (psnr_count[i]>0) ) | 440 if ( (show_psnr) && (psnr_count[i]>0) ) |
| 455 { | 441 { |
| 456 int j; | 442 int j; |
| 457 double ovpsnr = vp8_mse2psnr(psnr_samples_total[i], 255.0, | 443 double ovpsnr = sse_to_psnr(psnr_samples_total[i], 255.0, |
| 458 psnr_sse_total[i]); | 444 psnr_sse_total[i]); |
| 459 | 445 |
| 460 fprintf(stderr, "\n ENC%d PSNR (Overall/Avg/Y/U/V)", i); | 446 fprintf(stderr, "\n ENC%d PSNR (Overall/Avg/Y/U/V)", i); |
| 461 | 447 |
| 462 fprintf(stderr, " %.3lf", ovpsnr); | 448 fprintf(stderr, " %.3lf", ovpsnr); |
| 463 for (j = 0; j < 4; j++) | 449 for (j = 0; j < 4; j++) |
| 464 { | 450 { |
| 465 fprintf(stderr, " %.3lf", psnr_totals[i][j]/psnr_count[i]); | 451 fprintf(stderr, " %.3lf", psnr_totals[i][j]/psnr_count[i]); |
| 466 } | 452 } |
| 467 } | 453 } |
| 468 | 454 |
| 469 if(vpx_codec_destroy(&codec[i])) | 455 if(vpx_codec_destroy(&codec[i])) |
| 470 die_codec(&codec[i], "Failed to destroy codec"); | 456 die_codec(&codec[i], "Failed to destroy codec"); |
| 471 | 457 |
| 472 vpx_img_free(&raw[i]); | 458 vpx_img_free(&raw[i]); |
| 473 | 459 |
| 474 if(!outfile[i]) | 460 if(!outfile[i]) |
| 475 continue; | 461 continue; |
| 476 | 462 |
| 477 /* Try to rewrite the file header with the actual frame count */ | 463 /* Try to rewrite the file header with the actual frame count */ |
| 478 if(!fseek(outfile[i], 0, SEEK_SET)) | 464 if(!fseek(outfile[i], 0, SEEK_SET)) |
| 479 write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1); | 465 write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1); |
| 480 fclose(outfile[i]); | 466 fclose(outfile[i]); |
| 481 } | 467 } |
| 482 printf("\n"); | 468 printf("\n"); |
| 483 | 469 |
| 484 return EXIT_SUCCESS; | 470 return EXIT_SUCCESS; |
| 485 } | 471 } |
| OLD | NEW |