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

Side by Side Diff: source/libvpx/examples/vp8cx_set_ref.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
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "./video_writer.h" 58 #include "./video_writer.h"
59 59
60 static const char *exec_name; 60 static const char *exec_name;
61 61
62 void usage_exit() { 62 void usage_exit() {
63 fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile> <frame>\n", 63 fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile> <frame>\n",
64 exec_name); 64 exec_name);
65 exit(EXIT_FAILURE); 65 exit(EXIT_FAILURE);
66 } 66 }
67 67
68 static void encode_frame(vpx_codec_ctx_t *codec, 68 static int encode_frame(vpx_codec_ctx_t *codec,
69 vpx_image_t *img, 69 vpx_image_t *img,
70 int frame_index, 70 int frame_index,
71 VpxVideoWriter *writer) { 71 VpxVideoWriter *writer) {
72 int got_pkts = 0;
72 vpx_codec_iter_t iter = NULL; 73 vpx_codec_iter_t iter = NULL;
73 const vpx_codec_cx_pkt_t *pkt = NULL; 74 const vpx_codec_cx_pkt_t *pkt = NULL;
74 const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0, 75 const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0,
75 VPX_DL_GOOD_QUALITY); 76 VPX_DL_GOOD_QUALITY);
76 if (res != VPX_CODEC_OK) 77 if (res != VPX_CODEC_OK)
77 die_codec(codec, "Failed to encode frame"); 78 die_codec(codec, "Failed to encode frame");
78 79
79 while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) { 80 while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
81 got_pkts = 1;
82
80 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { 83 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
81 const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; 84 const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
82 if (!vpx_video_writer_write_frame(writer, 85 if (!vpx_video_writer_write_frame(writer,
83 pkt->data.frame.buf, 86 pkt->data.frame.buf,
84 pkt->data.frame.sz, 87 pkt->data.frame.sz,
85 pkt->data.frame.pts)) { 88 pkt->data.frame.pts)) {
86 die_codec(codec, "Failed to write compressed frame"); 89 die_codec(codec, "Failed to write compressed frame");
87 } 90 }
88 91
89 printf(keyframe ? "K" : "."); 92 printf(keyframe ? "K" : ".");
90 fflush(stdout); 93 fflush(stdout);
91 } 94 }
92 } 95 }
96
97 return got_pkts;
93 } 98 }
94 99
95 int main(int argc, char **argv) { 100 int main(int argc, char **argv) {
96 FILE *infile = NULL; 101 FILE *infile = NULL;
97 vpx_codec_ctx_t codec = {0}; 102 vpx_codec_ctx_t codec = {0};
98 vpx_codec_enc_cfg_t cfg = {0}; 103 vpx_codec_enc_cfg_t cfg = {0};
99 int frame_count = 0; 104 int frame_count = 0;
100 vpx_image_t raw; 105 vpx_image_t raw;
101 vpx_codec_err_t res; 106 vpx_codec_err_t res;
102 VpxVideoInfo info = {0}; 107 VpxVideoInfo info = {0};
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 writer = vpx_video_writer_open(argv[4], kContainerIVF, &info); 158 writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
154 if (!writer) 159 if (!writer)
155 die("Failed to open %s for writing.", argv[4]); 160 die("Failed to open %s for writing.", argv[4]);
156 161
157 if (!(infile = fopen(argv[3], "rb"))) 162 if (!(infile = fopen(argv[3], "rb")))
158 die("Failed to open %s for reading.", argv[3]); 163 die("Failed to open %s for reading.", argv[3]);
159 164
160 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0)) 165 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
161 die_codec(&codec, "Failed to initialize encoder"); 166 die_codec(&codec, "Failed to initialize encoder");
162 167
168 // Encode frames.
163 while (vpx_img_read(&raw, infile)) { 169 while (vpx_img_read(&raw, infile)) {
164 if (frame_count + 1 == update_frame_num) { 170 if (frame_count + 1 == update_frame_num) {
165 vpx_ref_frame_t ref; 171 vpx_ref_frame_t ref;
166 ref.frame_type = VP8_LAST_FRAME; 172 ref.frame_type = VP8_LAST_FRAME;
167 ref.img = raw; 173 ref.img = raw;
168 if (vpx_codec_control(&codec, VP8_SET_REFERENCE, &ref)) 174 if (vpx_codec_control(&codec, VP8_SET_REFERENCE, &ref))
169 die_codec(&codec, "Failed to set reference frame"); 175 die_codec(&codec, "Failed to set reference frame");
170 } 176 }
171 177
172 encode_frame(&codec, &raw, frame_count++, writer); 178 encode_frame(&codec, &raw, frame_count++, writer);
173 } 179 }
174 encode_frame(&codec, NULL, -1, writer); 180
181 // Flush encoder.
182 while (encode_frame(&codec, NULL, -1, writer)) {};
175 183
176 printf("\n"); 184 printf("\n");
177 fclose(infile); 185 fclose(infile);
178 printf("Processed %d frames.\n", frame_count); 186 printf("Processed %d frames.\n", frame_count);
179 187
180 vpx_img_free(&raw); 188 vpx_img_free(&raw);
181 if (vpx_codec_destroy(&codec)) 189 if (vpx_codec_destroy(&codec))
182 die_codec(&codec, "Failed to destroy codec."); 190 die_codec(&codec, "Failed to destroy codec.");
183 191
184 vpx_video_writer_close(writer); 192 vpx_video_writer_close(writer);
185 193
186 return EXIT_SUCCESS; 194 return EXIT_SUCCESS;
187 } 195 }
OLDNEW
« no previous file with comments | « source/libvpx/examples/simple_encoder.c ('k') | source/libvpx/examples/vpx_temporal_svc_encoder.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698