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

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

Issue 592203002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 2 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 10 matching lines...) Expand all
21 // statistics packets. 21 // statistics packets.
22 // 22 //
23 // Updating The Configuration 23 // Updating The Configuration
24 // --------------------------------- 24 // ---------------------------------
25 // In two pass mode, the configuration has to be updated on each pass. The 25 // In two pass mode, the configuration has to be updated on each pass. The
26 // statistics buffer is passed on the last pass. 26 // statistics buffer is passed on the last pass.
27 // 27 //
28 // Encoding A Frame 28 // Encoding A Frame
29 // ---------------- 29 // ----------------
30 // Encoding a frame in two pass mode is identical to the simple encoder 30 // Encoding a frame in two pass mode is identical to the simple encoder
31 // example, except the deadline is set to VPX_DL_BEST_QUALITY to get the 31 // example. To increase the quality while sacrificing encoding speed,
32 // best quality possible. VPX_DL_GOOD_QUALITY could also be used. 32 // VPX_DL_BEST_QUALITY can be used in place of VPX_DL_GOOD_QUALITY.
33 //
34 // 33 //
35 // Processing Statistics Packets 34 // Processing Statistics Packets
36 // ----------------------------- 35 // -----------------------------
37 // Each packet of type `VPX_CODEC_CX_FRAME_PKT` contains the encoded data 36 // Each packet of type `VPX_CODEC_CX_FRAME_PKT` contains the encoded data
38 // for this frame. We write a IVF frame header, followed by the raw data. 37 // for this frame. We write a IVF frame header, followed by the raw data.
39 // 38 //
40 // 39 //
41 // Pass Progress Reporting 40 // Pass Progress Reporting
42 // ----------------------------- 41 // -----------------------------
43 // It's sometimes helpful to see when each pass completes. 42 // It's sometimes helpful to see when each pass completes.
44 // 43 //
45 // 44 //
46 // Clean-up 45 // Clean-up
47 // ----------------------------- 46 // -----------------------------
48 // Destruction of the encoder instance must be done on each pass. The 47 // Destruction of the encoder instance must be done on each pass. The
49 // raw image should be destroyed at the end as usual. 48 // raw image should be destroyed at the end as usual.
50 49
51 #include <stdio.h> 50 #include <stdio.h>
52 #include <stdlib.h> 51 #include <stdlib.h>
53 #include <string.h> 52 #include <string.h>
54 53
55 #define VPX_CODEC_DISABLE_COMPAT 1
56 #include "vpx/vpx_encoder.h" 54 #include "vpx/vpx_encoder.h"
57 55
58 #include "./tools_common.h" 56 #include "./tools_common.h"
59 #include "./video_writer.h" 57 #include "./video_writer.h"
60 58
61 static const char *exec_name; 59 static const char *exec_name;
62 60
63 void usage_exit() { 61 void usage_exit() {
64 fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n", 62 fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n",
65 exec_name); 63 exec_name);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 vpx_codec_ctx_t codec; 133 vpx_codec_ctx_t codec;
136 int frame_count = 0; 134 int frame_count = 0;
137 vpx_fixed_buf_t stats = {NULL, 0}; 135 vpx_fixed_buf_t stats = {NULL, 0};
138 136
139 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0)) 137 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
140 die_codec(&codec, "Failed to initialize encoder"); 138 die_codec(&codec, "Failed to initialize encoder");
141 139
142 // Calculate frame statistics. 140 // Calculate frame statistics.
143 while (vpx_img_read(raw, infile)) { 141 while (vpx_img_read(raw, infile)) {
144 ++frame_count; 142 ++frame_count;
145 get_frame_stats(&codec, raw, frame_count, 1, 0, VPX_DL_BEST_QUALITY, 143 get_frame_stats(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY,
146 &stats); 144 &stats);
147 } 145 }
148 146
149 // Flush encoder. 147 // Flush encoder.
150 while (get_frame_stats(&codec, NULL, frame_count, 1, 0, 148 while (get_frame_stats(&codec, NULL, frame_count, 1, 0,
151 VPX_DL_BEST_QUALITY, &stats)) {} 149 VPX_DL_GOOD_QUALITY, &stats)) {}
152 150
153 printf("Pass 0 complete. Processed %d frames.\n", frame_count); 151 printf("Pass 0 complete. Processed %d frames.\n", frame_count);
154 if (vpx_codec_destroy(&codec)) 152 if (vpx_codec_destroy(&codec))
155 die_codec(&codec, "Failed to destroy codec."); 153 die_codec(&codec, "Failed to destroy codec.");
156 154
157 return stats; 155 return stats;
158 } 156 }
159 157
160 static void pass1(vpx_image_t *raw, 158 static void pass1(vpx_image_t *raw,
161 FILE *infile, 159 FILE *infile,
(...skipping 13 matching lines...) Expand all
175 writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info); 173 writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info);
176 if (!writer) 174 if (!writer)
177 die("Failed to open %s for writing", outfile_name); 175 die("Failed to open %s for writing", outfile_name);
178 176
179 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0)) 177 if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
180 die_codec(&codec, "Failed to initialize encoder"); 178 die_codec(&codec, "Failed to initialize encoder");
181 179
182 // Encode frames. 180 // Encode frames.
183 while (vpx_img_read(raw, infile)) { 181 while (vpx_img_read(raw, infile)) {
184 ++frame_count; 182 ++frame_count;
185 encode_frame(&codec, raw, frame_count, 1, 0, VPX_DL_BEST_QUALITY, writer); 183 encode_frame(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, writer);
186 } 184 }
187 185
188 // Flush encoder. 186 // Flush encoder.
189 while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_BEST_QUALITY, writer)) {} 187 while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_GOOD_QUALITY, writer)) {}
190 188
191 printf("\n"); 189 printf("\n");
192 190
193 if (vpx_codec_destroy(&codec)) 191 if (vpx_codec_destroy(&codec))
194 die_codec(&codec, "Failed to destroy codec."); 192 die_codec(&codec, "Failed to destroy codec.");
195 193
196 vpx_video_writer_close(writer); 194 vpx_video_writer_close(writer);
197 195
198 printf("Pass 1 complete. Processed %d frames.\n", frame_count); 196 printf("Pass 1 complete. Processed %d frames.\n", frame_count);
199 } 197 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 cfg.g_pass = VPX_RC_LAST_PASS; 256 cfg.g_pass = VPX_RC_LAST_PASS;
259 cfg.rc_twopass_stats_in = stats; 257 cfg.rc_twopass_stats_in = stats;
260 pass1(&raw, infile, outfile_arg, encoder, &cfg); 258 pass1(&raw, infile, outfile_arg, encoder, &cfg);
261 free(stats.buf); 259 free(stats.buf);
262 260
263 vpx_img_free(&raw); 261 vpx_img_free(&raw);
264 fclose(infile); 262 fclose(infile);
265 263
266 return EXIT_SUCCESS; 264 return EXIT_SUCCESS;
267 } 265 }
OLDNEW
« no previous file with comments | « source/libvpx/examples/simple_encoder.c ('k') | source/libvpx/examples/vp8_multi_resolution_encoder.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698