56 #include "../tools_common.h" 57 #include "../video_writer.h" 59 static const char *exec_name;
61 void usage_exit(
void) {
63 "Usage: %s <codec> <width> <height> <infile> <outfile> " 72 unsigned int duration,
74 unsigned int deadline,
82 die_codec(ctx,
"Failed to get frame stats.");
90 stats->
buf = realloc(stats->
buf, stats->
sz + pkt_size);
91 memcpy((uint8_t *)stats->
buf + stats->
sz, pkt_buf, pkt_size);
92 stats->
sz += pkt_size;
102 unsigned int duration,
104 unsigned int deadline,
105 VpxVideoWriter *writer) {
112 die_codec(ctx,
"Failed to encode frame.");
119 if (!vpx_video_writer_write_frame(writer, pkt->
data.
frame.buf,
122 die_codec(ctx,
"Failed to write compressed frame.");
123 printf(keyframe ?
"K" :
".");
133 const VpxInterface *encoder,
141 die_codec(&codec,
"Failed to initialize encoder");
144 while (vpx_img_read(raw, infile)) {
148 if (max_frames > 0 && frame_count >= max_frames)
153 while (get_frame_stats(&codec, NULL, frame_count, 1, 0,
156 printf(
"Pass 0 complete. Processed %d frames.\n", frame_count);
158 die_codec(&codec,
"Failed to destroy codec.");
165 const char *outfile_name,
166 const VpxInterface *encoder,
169 VpxVideoInfo info = {
175 VpxVideoWriter *writer = NULL;
179 writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info);
181 die(
"Failed to open %s for writing", outfile_name);
184 die_codec(&codec,
"Failed to initialize encoder");
187 while (vpx_img_read(raw, infile)) {
191 if (max_frames > 0 && frame_count >= max_frames)
201 die_codec(&codec,
"Failed to destroy codec.");
203 vpx_video_writer_close(writer);
205 printf(
"Pass 1 complete. Processed %d frames.\n", frame_count);
208 int main(
int argc,
char **argv) {
217 const VpxInterface *encoder = NULL;
219 const int bitrate = 200;
220 const char *
const codec_arg = argv[1];
221 const char *
const width_arg = argv[2];
222 const char *
const height_arg = argv[3];
223 const char *
const infile_arg = argv[4];
224 const char *
const outfile_arg = argv[5];
229 die(
"Invalid number of arguments.");
231 max_frames = strtol(argv[6], NULL, 0);
233 encoder = get_vpx_encoder_by_name(codec_arg);
235 die(
"Unsupported codec.");
237 w = strtol(width_arg, NULL, 0);
238 h = strtol(height_arg, NULL, 0);
240 if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
241 die(
"Invalid frame size: %dx%d", w, h);
244 die(
"Failed to allocate image", w, h);
251 die_codec(&codec,
"Failed to get default codec config.");
259 if (!(infile = fopen(infile_arg,
"rb")))
260 die(
"Failed to open %s for reading", infile_arg);
264 stats = pass0(&raw, infile, encoder, &cfg, max_frames);
270 pass1(&raw, infile, outfile_arg, encoder, &cfg, max_frames);
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:214
Image Descriptor.
Definition: vpx_image.h:88
Describes the encoder algorithm interface to applications.
const char * vpx_codec_iface_name(vpx_codec_iface_t *iface)
Return the name for a given interface.
struct vpx_rational g_timebase
Stream timebase units.
Definition: vpx_encoder.h:397
int den
Definition: vpx_encoder.h:261
vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, vpx_codec_pts_t pts, unsigned long duration, vpx_enc_frame_flags_t flags, unsigned long deadline)
Encode a frame.
Definition: vpx_encoder.h:177
Encoder configuration structure.
Definition: vpx_encoder.h:314
Encoder output packet.
Definition: vpx_encoder.h:195
void * buf
Definition: vpx_encoder.h:109
Generic fixed size buffer structure.
Definition: vpx_encoder.h:108
Definition: vpx_encoder.h:268
Definition: vpx_encoder.h:269
struct vpx_codec_cx_pkt::@1::@2 frame
vpx_image_t * vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
Definition: vpx_image.h:56
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:357
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:367
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:196
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:304
Operation completed without error.
Definition: vpx_codec.h:91
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
unsigned int rc_target_bitrate
Target data rate.
Definition: vpx_encoder.h:525
int num
Definition: vpx_encoder.h:260
enum vpx_enc_pass g_pass
Multi-pass Encoding Mode.
Definition: vpx_encoder.h:414
#define VPX_DL_GOOD_QUALITY
Definition: vpx_encoder.h:914
#define vpx_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_enc_init_ver()
Definition: vpx_encoder.h:813
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:89
const vpx_codec_cx_pkt_t * vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Encoded data iterator.
union vpx_codec_cx_pkt::@1 data
vpx_fixed_buf_t rc_twopass_stats_in
Two-pass stats buffer.
Definition: vpx_encoder.h:512
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:119
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, unsigned int reserved)
Get a default configuration.
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
size_t sz
Definition: vpx_encoder.h:110
#define VPX_FRAME_IS_KEY
Definition: vpx_encoder.h:130
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:188
Definition: vpx_encoder.h:176
Codec context structure.
Definition: vpx_codec.h:199