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 #include "./tools_common.h" |
27 #define interface (vpx_codec_vp8_cx()) | 27 #define interface (vpx_codec_vp8_cx()) |
28 #define fourcc 0x30385056 | 28 #define fourcc 0x30385056 |
29 | 29 |
30 #define IVF_FILE_HDR_SZ (32) | 30 void usage_exit() { |
31 #define IVF_FRAME_HDR_SZ (12) | 31 exit(EXIT_FAILURE); |
| 32 } |
32 | 33 |
33 /* | 34 /* |
34 * The input video frame is downsampled several times to generate a multi-level | 35 * The input video frame is downsampled several times to generate a multi-level |
35 * hierarchical structure. NUM_ENCODERS is defined as the number of encoding | 36 * hierarchical structure. NUM_ENCODERS is defined as the number of encoding |
36 * levels required. For example, if the size of input video is 1280x720, | 37 * levels required. For example, if the size of input video is 1280x720, |
37 * NUM_ENCODERS is 3, and down-sampling factor is 2, the encoder outputs 3 | 38 * NUM_ENCODERS is 3, and down-sampling factor is 2, the encoder outputs 3 |
38 * bitstreams with resolution of 1280x720(level 0), 640x360(level 1), and | 39 * bitstreams with resolution of 1280x720(level 0), 640x360(level 1), and |
39 * 320x180(level 2) respectively. | 40 * 320x180(level 2) respectively. |
40 */ | 41 */ |
41 #define NUM_ENCODERS 3 | 42 #define NUM_ENCODERS 3 |
42 | 43 |
43 /* This example uses the scaler function in libyuv. */ | 44 /* This example uses the scaler function in libyuv. */ |
44 #include "third_party/libyuv/include/libyuv/basic_types.h" | 45 #include "third_party/libyuv/include/libyuv/basic_types.h" |
45 #include "third_party/libyuv/include/libyuv/scale.h" | 46 #include "third_party/libyuv/include/libyuv/scale.h" |
46 #include "third_party/libyuv/include/libyuv/cpu_id.h" | 47 #include "third_party/libyuv/include/libyuv/cpu_id.h" |
47 | 48 |
48 static void die(const char *fmt, ...) { | |
49 va_list ap; | |
50 | |
51 va_start(ap, fmt); | |
52 vprintf(fmt, ap); | |
53 if(fmt[strlen(fmt)-1] != '\n') | |
54 printf("\n"); | |
55 exit(EXIT_FAILURE); | |
56 } | |
57 | |
58 static void die_codec(vpx_codec_ctx_t *ctx, const char *s) { | |
59 const char *detail = vpx_codec_error_detail(ctx); | |
60 | |
61 printf("%s: %s\n", s, vpx_codec_error(ctx)); | |
62 if(detail) | |
63 printf(" %s\n",detail); | |
64 exit(EXIT_FAILURE); | |
65 } | |
66 | |
67 int (*read_frame_p)(FILE *f, vpx_image_t *img); | 49 int (*read_frame_p)(FILE *f, vpx_image_t *img); |
68 | 50 |
69 static int read_frame(FILE *f, vpx_image_t *img) { | 51 static int read_frame(FILE *f, vpx_image_t *img) { |
70 size_t nbytes, to_read; | 52 size_t nbytes, to_read; |
71 int res = 1; | 53 int res = 1; |
72 | 54 |
73 to_read = img->w*img->h*3/2; | 55 to_read = img->w*img->h*3/2; |
74 nbytes = fread(img->planes[0], 1, to_read, f); | 56 nbytes = fread(img->planes[0], 1, to_read, f); |
75 if(nbytes != to_read) { | 57 if(nbytes != to_read) { |
76 res = 0; | 58 res = 0; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 444 |
463 /* Try to rewrite the file header with the actual frame count */ | 445 /* Try to rewrite the file header with the actual frame count */ |
464 if(!fseek(outfile[i], 0, SEEK_SET)) | 446 if(!fseek(outfile[i], 0, SEEK_SET)) |
465 write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1); | 447 write_ivf_file_header(outfile[i], &cfg[i], frame_cnt-1); |
466 fclose(outfile[i]); | 448 fclose(outfile[i]); |
467 } | 449 } |
468 printf("\n"); | 450 printf("\n"); |
469 | 451 |
470 return EXIT_SUCCESS; | 452 return EXIT_SUCCESS; |
471 } | 453 } |
OLD | NEW |