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

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

Issue 181493009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 9 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/simple_decoder.c ('k') | source/libvpx/examples/twopass_encoder.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 18 matching lines...) Expand all
29 // For encoders, you only have to include `vpx_encoder.h` and then any 29 // For encoders, you only have to include `vpx_encoder.h` and then any
30 // header files for the specific codecs you use. In this case, we're using 30 // header files for the specific codecs you use. In this case, we're using
31 // vp8. The `VPX_CODEC_DISABLE_COMPAT` macro can be defined to ensure 31 // vp8. The `VPX_CODEC_DISABLE_COMPAT` macro can be defined to ensure
32 // strict compliance with the latest SDK by disabling some backwards 32 // strict compliance with the latest SDK by disabling some backwards
33 // compatibility features. Defining this macro is encouraged. 33 // compatibility features. Defining this macro is encouraged.
34 // 34 //
35 // Getting The Default Configuration 35 // Getting The Default Configuration
36 // --------------------------------- 36 // ---------------------------------
37 // Encoders have the notion of "usage profiles." For example, an encoder 37 // Encoders have the notion of "usage profiles." For example, an encoder
38 // may want to publish default configurations for both a video 38 // may want to publish default configurations for both a video
39 // conferencing appliction and a best quality offline encoder. These 39 // conferencing application and a best quality offline encoder. These
40 // obviously have very different default settings. Consult the 40 // obviously have very different default settings. Consult the
41 // documentation for your codec to see if it provides any default 41 // documentation for your codec to see if it provides any default
42 // configurations. All codecs provide a default configuration, number 0, 42 // configurations. All codecs provide a default configuration, number 0,
43 // which is valid for material in the vacinity of QCIF/QVGA. 43 // which is valid for material in the vacinity of QCIF/QVGA.
44 // 44 //
45 // Updating The Configuration 45 // Updating The Configuration
46 // --------------------------------- 46 // ---------------------------------
47 // Almost all applications will want to update the default configuration 47 // Almost all applications will want to update the default configuration
48 // with settings specific to their usage. Here we set the width and height 48 // with settings specific to their usage. Here we set the width and height
49 // of the video file to that specified on the command line. We also scale 49 // of the video file to that specified on the command line. We also scale
(...skipping 23 matching lines...) Expand all
73 // Cleanup 73 // Cleanup
74 // ------- 74 // -------
75 // The `vpx_codec_destroy` call frees any memory allocated by the codec. 75 // The `vpx_codec_destroy` call frees any memory allocated by the codec.
76 // 76 //
77 // Error Handling 77 // Error Handling
78 // -------------- 78 // --------------
79 // This example does not special case any error return codes. If there was 79 // This example does not special case any error return codes. If there was
80 // an error, a descriptive message is printed and the program exits. With 80 // an error, a descriptive message is printed and the program exits. With
81 // few exeptions, vpx_codec functions return an enumerated error status, 81 // few exeptions, vpx_codec functions return an enumerated error status,
82 // with the value `0` indicating success. 82 // with the value `0` indicating success.
83 //
84 // Error Resiliency Features
85 // -------------------------
86 // Error resiliency is controlled by the g_error_resilient member of the
87 // configuration structure. Use the `decode_with_drops` example to decode with
88 // frames 5-10 dropped. Compare the output for a file encoded with this example
89 // versus one encoded with the `simple_encoder` example.
83 90
84 #include <stdio.h> 91 #include <stdio.h>
85 #include <stdlib.h> 92 #include <stdlib.h>
86 #include <string.h> 93 #include <string.h>
87 94
88 #define VPX_CODEC_DISABLE_COMPAT 1 95 #define VPX_CODEC_DISABLE_COMPAT 1
89 #include "vpx/vpx_encoder.h" 96 #include "vpx/vpx_encoder.h"
90 97
91 #include "./tools_common.h" 98 #include "./tools_common.h"
92 #include "./video_writer.h" 99 #include "./video_writer.h"
93 100
94 static const char *exec_name; 101 static const char *exec_name;
95 102
96 void usage_exit() { 103 void usage_exit() {
97 fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile>\n", 104 fprintf(stderr,
105 "Usage: %s <codec> <width> <height> <infile> <outfile> "
106 "[<error-resilient>]\nSee comments in simple_encoder.c for more "
107 "information.\n",
98 exec_name); 108 exec_name);
99 exit(EXIT_FAILURE); 109 exit(EXIT_FAILURE);
100 } 110 }
101 111
102 static void encode_frame(vpx_codec_ctx_t *codec, 112 static void encode_frame(vpx_codec_ctx_t *codec,
103 vpx_image_t *img, 113 vpx_image_t *img,
104 int frame_index, 114 int frame_index,
105 VpxVideoWriter *writer) { 115 VpxVideoWriter *writer) {
106 vpx_codec_iter_t iter = NULL; 116 vpx_codec_iter_t iter = NULL;
107 const vpx_codec_cx_pkt_t *pkt = NULL; 117 const vpx_codec_cx_pkt_t *pkt = NULL;
(...skipping 23 matching lines...) Expand all
131 vpx_codec_ctx_t codec; 141 vpx_codec_ctx_t codec;
132 vpx_codec_enc_cfg_t cfg; 142 vpx_codec_enc_cfg_t cfg;
133 int frame_count = 0; 143 int frame_count = 0;
134 vpx_image_t raw; 144 vpx_image_t raw;
135 vpx_codec_err_t res; 145 vpx_codec_err_t res;
136 VpxVideoInfo info = {0}; 146 VpxVideoInfo info = {0};
137 VpxVideoWriter *writer = NULL; 147 VpxVideoWriter *writer = NULL;
138 const VpxInterface *encoder = NULL; 148 const VpxInterface *encoder = NULL;
139 const int fps = 30; // TODO(dkovalev) add command line argument 149 const int fps = 30; // TODO(dkovalev) add command line argument
140 const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument 150 const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
141 const char *const codec_arg = argv[1]; 151 const char *codec_arg = NULL;
142 const char *const width_arg = argv[2]; 152 const char *width_arg = NULL;
143 const char *const height_arg = argv[3]; 153 const char *height_arg = NULL;
144 const char *const infile_arg = argv[4]; 154 const char *infile_arg = NULL;
145 const char *const outfile_arg = argv[5]; 155 const char *outfile_arg = NULL;
146 156
147 exec_name = argv[0]; 157 exec_name = argv[0];
148 158
149 if (argc != 6) 159 if (argc < 6)
150 die("Invalid number of arguments"); 160 die("Invalid number of arguments");
151 161
162 codec_arg = argv[1];
163 width_arg = argv[2];
164 height_arg = argv[3];
165 infile_arg = argv[4];
166 outfile_arg = argv[5];
167
152 encoder = get_vpx_encoder_by_name(codec_arg); 168 encoder = get_vpx_encoder_by_name(codec_arg);
153 if (!encoder) 169 if (!encoder)
154 die("Unsupported codec."); 170 die("Unsupported codec.");
155 171
156 info.codec_fourcc = encoder->fourcc; 172 info.codec_fourcc = encoder->fourcc;
157 info.frame_width = strtol(width_arg, NULL, 0); 173 info.frame_width = strtol(width_arg, NULL, 0);
158 info.frame_height = strtol(height_arg, NULL, 0); 174 info.frame_height = strtol(height_arg, NULL, 0);
159 info.time_base.numerator = 1; 175 info.time_base.numerator = 1;
160 info.time_base.denominator = fps; 176 info.time_base.denominator = fps;
161 177
(...skipping 13 matching lines...) Expand all
175 191
176 res = vpx_codec_enc_config_default(encoder->interface(), &cfg, 0); 192 res = vpx_codec_enc_config_default(encoder->interface(), &cfg, 0);
177 if (res) 193 if (res)
178 die_codec(&codec, "Failed to get default codec config."); 194 die_codec(&codec, "Failed to get default codec config.");
179 195
180 cfg.g_w = info.frame_width; 196 cfg.g_w = info.frame_width;
181 cfg.g_h = info.frame_height; 197 cfg.g_h = info.frame_height;
182 cfg.g_timebase.num = info.time_base.numerator; 198 cfg.g_timebase.num = info.time_base.numerator;
183 cfg.g_timebase.den = info.time_base.denominator; 199 cfg.g_timebase.den = info.time_base.denominator;
184 cfg.rc_target_bitrate = bitrate; 200 cfg.rc_target_bitrate = bitrate;
201 cfg.g_error_resilient = argc > 6 ? strtol(argv[6], NULL, 0) : 0;
185 202
186 writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info); 203 writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
187 if (!writer) 204 if (!writer)
188 die("Failed to open %s for writing.", outfile_arg); 205 die("Failed to open %s for writing.", outfile_arg);
189 206
190 if (!(infile = fopen(infile_arg, "rb"))) 207 if (!(infile = fopen(infile_arg, "rb")))
191 die("Failed to open %s for reading.", infile_arg); 208 die("Failed to open %s for reading.", infile_arg);
192 209
193 if (vpx_codec_enc_init(&codec, encoder->interface(), &cfg, 0)) 210 if (vpx_codec_enc_init(&codec, encoder->interface(), &cfg, 0))
194 die_codec(&codec, "Failed to initialize encoder"); 211 die_codec(&codec, "Failed to initialize encoder");
195 212
196 while (vpx_img_read(&raw, infile)) 213 while (vpx_img_read(&raw, infile))
197 encode_frame(&codec, &raw, frame_count++, writer); 214 encode_frame(&codec, &raw, frame_count++, writer);
198 encode_frame(&codec, NULL, -1, writer); // flush the encoder 215 encode_frame(&codec, NULL, -1, writer); // flush the encoder
199 216
200 printf("\n"); 217 printf("\n");
201 fclose(infile); 218 fclose(infile);
202 printf("Processed %d frames.\n", frame_count); 219 printf("Processed %d frames.\n", frame_count);
203 220
204 vpx_img_free(&raw); 221 vpx_img_free(&raw);
205 if (vpx_codec_destroy(&codec)) 222 if (vpx_codec_destroy(&codec))
206 die_codec(&codec, "Failed to destroy codec."); 223 die_codec(&codec, "Failed to destroy codec.");
207 224
208 vpx_video_writer_close(writer); 225 vpx_video_writer_close(writer);
209 226
210 return EXIT_SUCCESS; 227 return EXIT_SUCCESS;
211 } 228 }
OLDNEW
« no previous file with comments | « source/libvpx/examples/simple_decoder.c ('k') | source/libvpx/examples/twopass_encoder.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698