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 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 void usage_exit() { | 58 void usage_exit() { |
59 fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n", | 59 fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n", |
60 exec_name); | 60 exec_name); |
61 exit(EXIT_FAILURE); | 61 exit(EXIT_FAILURE); |
62 } | 62 } |
63 | 63 |
64 static void set_roi_map(const vpx_codec_enc_cfg_t *cfg, | 64 static void set_roi_map(const vpx_codec_enc_cfg_t *cfg, |
65 vpx_codec_ctx_t *codec) { | 65 vpx_codec_ctx_t *codec) { |
66 unsigned int i; | 66 unsigned int i; |
67 vpx_roi_map_t roi = {0}; | 67 vpx_roi_map_t roi; |
| 68 memset(&roi, 0, sizeof(roi)); |
68 | 69 |
69 roi.rows = (cfg->g_h + 15) / 16; | 70 roi.rows = (cfg->g_h + 15) / 16; |
70 roi.cols = (cfg->g_w + 15) / 16; | 71 roi.cols = (cfg->g_w + 15) / 16; |
71 | 72 |
72 roi.delta_q[0] = 0; | 73 roi.delta_q[0] = 0; |
73 roi.delta_q[1] = -2; | 74 roi.delta_q[1] = -2; |
74 roi.delta_q[2] = -4; | 75 roi.delta_q[2] = -4; |
75 roi.delta_q[3] = -6; | 76 roi.delta_q[3] = -6; |
76 | 77 |
77 roi.delta_lf[0] = 0; | 78 roi.delta_lf[0] = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
90 | 91 |
91 if (vpx_codec_control(codec, VP8E_SET_ROI_MAP, &roi)) | 92 if (vpx_codec_control(codec, VP8E_SET_ROI_MAP, &roi)) |
92 die_codec(codec, "Failed to set ROI map"); | 93 die_codec(codec, "Failed to set ROI map"); |
93 | 94 |
94 free(roi.roi_map); | 95 free(roi.roi_map); |
95 } | 96 } |
96 | 97 |
97 static void set_active_map(const vpx_codec_enc_cfg_t *cfg, | 98 static void set_active_map(const vpx_codec_enc_cfg_t *cfg, |
98 vpx_codec_ctx_t *codec) { | 99 vpx_codec_ctx_t *codec) { |
99 unsigned int i; | 100 unsigned int i; |
100 vpx_active_map_t map = {0}; | 101 vpx_active_map_t map = {0, 0, 0}; |
101 | 102 |
102 map.rows = (cfg->g_h + 15) / 16; | 103 map.rows = (cfg->g_h + 15) / 16; |
103 map.cols = (cfg->g_w + 15) / 16; | 104 map.cols = (cfg->g_w + 15) / 16; |
104 | 105 |
105 map.active_map = (uint8_t *)malloc(map.rows * map.cols); | 106 map.active_map = (uint8_t *)malloc(map.rows * map.cols); |
106 for (i = 0; i < map.rows * map.cols; ++i) | 107 for (i = 0; i < map.rows * map.cols; ++i) |
107 map.active_map[i] = i % 2; | 108 map.active_map[i] = i % 2; |
108 | 109 |
109 if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map)) | 110 if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map)) |
110 die_codec(codec, "Failed to set active map"); | 111 die_codec(codec, "Failed to set active map"); |
111 | 112 |
112 free(map.active_map); | 113 free(map.active_map); |
113 } | 114 } |
114 | 115 |
115 static void unset_active_map(const vpx_codec_enc_cfg_t *cfg, | 116 static void unset_active_map(const vpx_codec_enc_cfg_t *cfg, |
116 vpx_codec_ctx_t *codec) { | 117 vpx_codec_ctx_t *codec) { |
117 vpx_active_map_t map = {0}; | 118 vpx_active_map_t map = {0, 0, 0}; |
118 | 119 |
119 map.rows = (cfg->g_h + 15) / 16; | 120 map.rows = (cfg->g_h + 15) / 16; |
120 map.cols = (cfg->g_w + 15) / 16; | 121 map.cols = (cfg->g_w + 15) / 16; |
121 map.active_map = NULL; | 122 map.active_map = NULL; |
122 | 123 |
123 if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map)) | 124 if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map)) |
124 die_codec(codec, "Failed to set active map"); | 125 die_codec(codec, "Failed to set active map"); |
125 } | 126 } |
126 | 127 |
127 static void encode_frame(vpx_codec_ctx_t *codec, | 128 static void encode_frame(vpx_codec_ctx_t *codec, |
(...skipping 18 matching lines...) Expand all Loading... |
146 } | 147 } |
147 | 148 |
148 printf(keyframe ? "K" : "."); | 149 printf(keyframe ? "K" : "."); |
149 fflush(stdout); | 150 fflush(stdout); |
150 } | 151 } |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 int main(int argc, char **argv) { | 155 int main(int argc, char **argv) { |
155 FILE *infile = NULL; | 156 FILE *infile = NULL; |
156 vpx_codec_ctx_t codec = {0}; | 157 vpx_codec_ctx_t codec; |
157 vpx_codec_enc_cfg_t cfg = {0}; | 158 vpx_codec_enc_cfg_t cfg; |
158 int frame_count = 0; | 159 int frame_count = 0; |
159 vpx_image_t raw = {0}; | 160 vpx_image_t raw; |
160 vpx_codec_err_t res; | 161 vpx_codec_err_t res; |
161 VpxVideoInfo info = {0}; | 162 VpxVideoInfo info; |
162 VpxVideoWriter *writer = NULL; | 163 VpxVideoWriter *writer = NULL; |
163 const VpxInterface *encoder = NULL; | 164 const VpxInterface *encoder = NULL; |
164 const int fps = 2; // TODO(dkovalev) add command line argument | 165 const int fps = 2; // TODO(dkovalev) add command line argument |
165 const double bits_per_pixel_per_frame = 0.067; | 166 const double bits_per_pixel_per_frame = 0.067; |
166 | 167 |
167 exec_name = argv[0]; | 168 exec_name = argv[0]; |
168 | |
169 if (argc != 6) | 169 if (argc != 6) |
170 die("Invalid number of arguments"); | 170 die("Invalid number of arguments"); |
171 | 171 |
| 172 memset(&info, 0, sizeof(info)); |
| 173 |
172 encoder = get_vpx_encoder_by_name(argv[1]); | 174 encoder = get_vpx_encoder_by_name(argv[1]); |
173 if (!encoder) | 175 if (!encoder) |
174 die("Unsupported codec."); | 176 die("Unsupported codec."); |
175 | 177 |
176 info.codec_fourcc = encoder->fourcc; | 178 info.codec_fourcc = encoder->fourcc; |
177 info.frame_width = strtol(argv[2], NULL, 0); | 179 info.frame_width = strtol(argv[2], NULL, 0); |
178 info.frame_height = strtol(argv[3], NULL, 0); | 180 info.frame_height = strtol(argv[3], NULL, 0); |
179 info.time_base.numerator = 1; | 181 info.time_base.numerator = 1; |
180 info.time_base.denominator = fps; | 182 info.time_base.denominator = fps; |
181 | 183 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 printf("Processed %d frames.\n", frame_count); | 236 printf("Processed %d frames.\n", frame_count); |
235 | 237 |
236 vpx_img_free(&raw); | 238 vpx_img_free(&raw); |
237 if (vpx_codec_destroy(&codec)) | 239 if (vpx_codec_destroy(&codec)) |
238 die_codec(&codec, "Failed to destroy codec."); | 240 die_codec(&codec, "Failed to destroy codec."); |
239 | 241 |
240 vpx_video_writer_close(writer); | 242 vpx_video_writer_close(writer); |
241 | 243 |
242 return EXIT_SUCCESS; | 244 return EXIT_SUCCESS; |
243 } | 245 } |
OLD | NEW |