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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 (info.frame_width % 2) != 0 || | 131 (info.frame_width % 2) != 0 || |
132 (info.frame_height % 2) != 0) { | 132 (info.frame_height % 2) != 0) { |
133 die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); | 133 die("Invalid frame size: %dx%d", info.frame_width, info.frame_height); |
134 } | 134 } |
135 | 135 |
136 if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, | 136 if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width, |
137 info.frame_height, 1)) { | 137 info.frame_height, 1)) { |
138 die("Failed to allocate image."); | 138 die("Failed to allocate image."); |
139 } | 139 } |
140 | 140 |
141 printf("Using %s\n", vpx_codec_iface_name(encoder->interface())); | 141 printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface())); |
142 | 142 |
143 res = vpx_codec_enc_config_default(encoder->interface(), &cfg, 0); | 143 res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0); |
144 if (res) | 144 if (res) |
145 die_codec(&codec, "Failed to get default codec config."); | 145 die_codec(&codec, "Failed to get default codec config."); |
146 | 146 |
147 cfg.g_w = info.frame_width; | 147 cfg.g_w = info.frame_width; |
148 cfg.g_h = info.frame_height; | 148 cfg.g_h = info.frame_height; |
149 cfg.g_timebase.num = info.time_base.numerator; | 149 cfg.g_timebase.num = info.time_base.numerator; |
150 cfg.g_timebase.den = info.time_base.denominator; | 150 cfg.g_timebase.den = info.time_base.denominator; |
151 cfg.rc_target_bitrate = bitrate; | 151 cfg.rc_target_bitrate = bitrate; |
152 | 152 |
153 writer = vpx_video_writer_open(argv[4], kContainerIVF, &info); | 153 writer = vpx_video_writer_open(argv[4], kContainerIVF, &info); |
154 if (!writer) | 154 if (!writer) |
155 die("Failed to open %s for writing.", argv[4]); | 155 die("Failed to open %s for writing.", argv[4]); |
156 | 156 |
157 if (!(infile = fopen(argv[3], "rb"))) | 157 if (!(infile = fopen(argv[3], "rb"))) |
158 die("Failed to open %s for reading.", argv[3]); | 158 die("Failed to open %s for reading.", argv[3]); |
159 | 159 |
160 if (vpx_codec_enc_init(&codec, encoder->interface(), &cfg, 0)) | 160 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0)) |
161 die_codec(&codec, "Failed to initialize encoder"); | 161 die_codec(&codec, "Failed to initialize encoder"); |
162 | 162 |
163 while (vpx_img_read(&raw, infile)) { | 163 while (vpx_img_read(&raw, infile)) { |
164 if (frame_count + 1 == update_frame_num) { | 164 if (frame_count + 1 == update_frame_num) { |
165 vpx_ref_frame_t ref; | 165 vpx_ref_frame_t ref; |
166 ref.frame_type = VP8_LAST_FRAME; | 166 ref.frame_type = VP8_LAST_FRAME; |
167 ref.img = raw; | 167 ref.img = raw; |
168 if (vpx_codec_control(&codec, VP8_SET_REFERENCE, &ref)) | 168 if (vpx_codec_control(&codec, VP8_SET_REFERENCE, &ref)) |
169 die_codec(&codec, "Failed to set reference frame"); | 169 die_codec(&codec, "Failed to set reference frame"); |
170 } | 170 } |
171 | 171 |
172 encode_frame(&codec, &raw, frame_count++, writer); | 172 encode_frame(&codec, &raw, frame_count++, writer); |
173 } | 173 } |
174 encode_frame(&codec, NULL, -1, writer); | 174 encode_frame(&codec, NULL, -1, writer); |
175 | 175 |
176 printf("\n"); | 176 printf("\n"); |
177 fclose(infile); | 177 fclose(infile); |
178 printf("Processed %d frames.\n", frame_count); | 178 printf("Processed %d frames.\n", frame_count); |
179 | 179 |
180 vpx_img_free(&raw); | 180 vpx_img_free(&raw); |
181 if (vpx_codec_destroy(&codec)) | 181 if (vpx_codec_destroy(&codec)) |
182 die_codec(&codec, "Failed to destroy codec."); | 182 die_codec(&codec, "Failed to destroy codec."); |
183 | 183 |
184 vpx_video_writer_close(writer); | 184 vpx_video_writer_close(writer); |
185 | 185 |
186 return EXIT_SUCCESS; | 186 return EXIT_SUCCESS; |
187 } | 187 } |
OLD | NEW |