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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 (info.frame_width % 2) != 0 || | 186 (info.frame_width % 2) != 0 || |
187 (info.frame_height % 2) != 0) { | 187 (info.frame_height % 2) != 0) { |
188 die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); | 188 die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); |
189 } | 189 } |
190 | 190 |
191 if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, | 191 if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, |
192 info.frame_height, 1)) { | 192 info.frame_height, 1)) { |
193 die("Failed to allocate image."); | 193 die("Failed to allocate image."); |
194 } | 194 } |
195 | 195 |
196 printf("Using %s\n", vpx_codec_iface_name(encoder->interface())); | 196 printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); |
197 | 197 |
198 res = vpx_codec_enc_config_default(encoder->interface(), &cfg, 0); | 198 res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); |
199 if (res) | 199 if (res) |
200 die_codec(&codec, "Failed to get default codec config."); | 200 die_codec(&codec, "Failed to get default codec config."); |
201 | 201 |
202 cfg.g_w = info.frame_width; | 202 cfg.g_w = info.frame_width; |
203 cfg.g_h = info.frame_height; | 203 cfg.g_h = info.frame_height; |
204 cfg.g_timebase.num = info.time_base.numerator; | 204 cfg.g_timebase.num = info.time_base.numerator; |
205 cfg.g_timebase.den = info.time_base.denominator; | 205 cfg.g_timebase.den = info.time_base.denominator; |
206 cfg.rc_target_bitrate = (unsigned int)(bits_per_pixel_per_frame * cfg.g_w * | 206 cfg.rc_target_bitrate = (unsigned int)(bits_per_pixel_per_frame * cfg.g_w * |
207 cfg.g_h * fps / 1000); | 207 cfg.g_h * fps / 1000); |
208 cfg.g_lag_in_frames = 0; | 208 cfg.g_lag_in_frames = 0; |
209 | 209 |
210 writer = vpx_video_writer_open(argv[5], kContainerIVF, &info); | 210 writer = vpx_video_writer_open(argv[5], kContainerIVF, &info); |
211 if (!writer) | 211 if (!writer) |
212 die("Failed to open %s for writing.", argv[5]); | 212 die("Failed to open %s for writing.", argv[5]); |
213 | 213 |
214 if (!(infile = fopen(argv[4], "rb"))) | 214 if (!(infile = fopen(argv[4], "rb"))) |
215 die("Failed to open %s for reading.", argv[4]); | 215 die("Failed to open %s for reading.", argv[4]); |
216 | 216 |
217 if (vpx_codec_enc_init(&codec, encoder->interface(), &cfg, 0)) | 217 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0)) |
218 die_codec(&codec, "Failed to initialize encoder"); | 218 die_codec(&codec, "Failed to initialize encoder"); |
219 | 219 |
220 while (vpx_img_read(&raw, infile)) { | 220 while (vpx_img_read(&raw, infile)) { |
221 ++frame_count; | 221 ++frame_count; |
222 | 222 |
223 if (frame_count == 22 && encoder->fourcc == VP8_FOURCC) { | 223 if (frame_count == 22 && encoder->fourcc == VP8_FOURCC) { |
224 set_roi_map(&cfg, &codec); | 224 set_roi_map(&cfg, &codec); |
225 } else if (frame_count == 33) { | 225 } else if (frame_count == 33) { |
226 set_active_map(&cfg, &codec); | 226 set_active_map(&cfg, &codec); |
227 } else if (frame_count == 44) { | 227 } else if (frame_count == 44) { |
228 unset_active_map(&cfg, &codec); | 228 unset_active_map(&cfg, &codec); |
229 } | 229 } |
230 | 230 |
231 encode_frame(&codec, &raw, frame_count, writer); | 231 encode_frame(&codec, &raw, frame_count, writer); |
232 } | 232 } |
233 encode_frame(&codec, NULL, -1, writer); | 233 encode_frame(&codec, NULL, -1, writer); |
234 printf("\n"); | 234 printf("\n"); |
235 fclose(infile); | 235 fclose(infile); |
236 printf("Processed %d frames.\n", frame_count); | 236 printf("Processed %d frames.\n", frame_count); |
237 | 237 |
238 vpx_img_free(&raw); | 238 vpx_img_free(&raw); |
239 if (vpx_codec_destroy(&codec)) | 239 if (vpx_codec_destroy(&codec)) |
240 die_codec(&codec, "Failed to destroy codec."); | 240 die_codec(&codec, "Failed to destroy codec."); |
241 | 241 |
242 vpx_video_writer_close(writer); | 242 vpx_video_writer_close(writer); |
243 | 243 |
244 return EXIT_SUCCESS; | 244 return EXIT_SUCCESS; |
245 } | 245 } |
OLD | NEW |