Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: source/libvpx/examples/simple_encoder.c

Issue 478033002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/examples.mk ('k') | source/libvpx/examples/vp8cx_set_ref.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 void usage_exit() { 112 void usage_exit() {
113 fprintf(stderr, 113 fprintf(stderr,
114 "Usage: %s <codec> <width> <height> <infile> <outfile> " 114 "Usage: %s <codec> <width> <height> <infile> <outfile> "
115 "<keyframe-interval> [<error-resilient>]\nSee comments in " 115 "<keyframe-interval> [<error-resilient>]\nSee comments in "
116 "simple_encoder.c for more information.\n", 116 "simple_encoder.c for more information.\n",
117 exec_name); 117 exec_name);
118 exit(EXIT_FAILURE); 118 exit(EXIT_FAILURE);
119 } 119 }
120 120
121 static void encode_frame(vpx_codec_ctx_t *codec, 121 static int encode_frame(vpx_codec_ctx_t *codec,
122 vpx_image_t *img, 122 vpx_image_t *img,
123 int frame_index, 123 int frame_index,
124 int flags, 124 int flags,
125 VpxVideoWriter *writer) { 125 VpxVideoWriter *writer) {
126 int got_pkts = 0;
126 vpx_codec_iter_t iter = NULL; 127 vpx_codec_iter_t iter = NULL;
127 const vpx_codec_cx_pkt_t *pkt = NULL; 128 const vpx_codec_cx_pkt_t *pkt = NULL;
128 const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 129 const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1,
129 flags, VPX_DL_GOOD_QUALITY); 130 flags, VPX_DL_GOOD_QUALITY);
130 if (res != VPX_CODEC_OK) 131 if (res != VPX_CODEC_OK)
131 die_codec(codec, "Failed to encode frame"); 132 die_codec(codec, "Failed to encode frame");
132 133
133 while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) { 134 while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
135 got_pkts = 1;
136
134 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { 137 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
135 const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; 138 const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
136 if (!vpx_video_writer_write_frame(writer, 139 if (!vpx_video_writer_write_frame(writer,
137 pkt->data.frame.buf, 140 pkt->data.frame.buf,
138 pkt->data.frame.sz, 141 pkt->data.frame.sz,
139 pkt->data.frame.pts)) { 142 pkt->data.frame.pts)) {
140 die_codec(codec, "Failed to write compressed frame"); 143 die_codec(codec, "Failed to write compressed frame");
141 } 144 }
142
143 printf(keyframe ? "K" : "."); 145 printf(keyframe ? "K" : ".");
144 fflush(stdout); 146 fflush(stdout);
145 } 147 }
146 } 148 }
149
150 return got_pkts;
147 } 151 }
148 152
149 int main(int argc, char **argv) { 153 int main(int argc, char **argv) {
150 FILE *infile = NULL; 154 FILE *infile = NULL;
151 vpx_codec_ctx_t codec; 155 vpx_codec_ctx_t codec;
152 vpx_codec_enc_cfg_t cfg; 156 vpx_codec_enc_cfg_t cfg;
153 int frame_count = 0; 157 int frame_count = 0;
154 vpx_image_t raw; 158 vpx_image_t raw;
155 vpx_codec_err_t res; 159 vpx_codec_err_t res;
156 VpxVideoInfo info = {0}; 160 VpxVideoInfo info = {0};
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info); 227 writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
224 if (!writer) 228 if (!writer)
225 die("Failed to open %s for writing.", outfile_arg); 229 die("Failed to open %s for writing.", outfile_arg);
226 230
227 if (!(infile = fopen(infile_arg, "rb"))) 231 if (!(infile = fopen(infile_arg, "rb")))
228 die("Failed to open %s for reading.", infile_arg); 232 die("Failed to open %s for reading.", infile_arg);
229 233
230 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0)) 234 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
231 die_codec(&codec, "Failed to initialize encoder"); 235 die_codec(&codec, "Failed to initialize encoder");
232 236
237 // Encode frames.
233 while (vpx_img_read(&raw, infile)) { 238 while (vpx_img_read(&raw, infile)) {
234 int flags = 0; 239 int flags = 0;
235 if (keyframe_interval > 0 && frame_count % keyframe_interval == 0) 240 if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
236 flags |= VPX_EFLAG_FORCE_KF; 241 flags |= VPX_EFLAG_FORCE_KF;
237 encode_frame(&codec, &raw, frame_count++, flags, writer); 242 encode_frame(&codec, &raw, frame_count++, flags, writer);
238 } 243 }
239 encode_frame(&codec, NULL, -1, 0, writer); // flush the encoder 244
245 // Flush encoder.
246 while (encode_frame(&codec, NULL, -1, 0, writer)) {};
240 247
241 printf("\n"); 248 printf("\n");
242 fclose(infile); 249 fclose(infile);
243 printf("Processed %d frames.\n", frame_count); 250 printf("Processed %d frames.\n", frame_count);
244 251
245 vpx_img_free(&raw); 252 vpx_img_free(&raw);
246 if (vpx_codec_destroy(&codec)) 253 if (vpx_codec_destroy(&codec))
247 die_codec(&codec, "Failed to destroy codec."); 254 die_codec(&codec, "Failed to destroy codec.");
248 255
249 vpx_video_writer_close(writer); 256 vpx_video_writer_close(writer);
250 257
251 return EXIT_SUCCESS; 258 return EXIT_SUCCESS;
252 } 259 }
OLDNEW
« no previous file with comments | « source/libvpx/examples.mk ('k') | source/libvpx/examples/vp8cx_set_ref.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698