17 #include "vp9/common/vp9_common.h" 19 #include "../tools_common.h" 20 #include "../video_writer.h" 22 static const char *exec_name;
24 void usage_exit(
void) {
26 "vp9_lossless_encoder: Example demonstrating VP9 lossless " 27 "encoding feature. Supports raw input only.\n");
28 fprintf(stderr,
"Usage: %s <width> <height> <infile> <outfile>\n", exec_name);
33 int frame_index,
int flags, VpxVideoWriter *writer) {
39 if (res !=
VPX_CODEC_OK) die_codec(codec,
"Failed to encode frame");
46 if (!vpx_video_writer_write_frame(writer, pkt->
data.
frame.buf,
49 die_codec(codec,
"Failed to write compressed frame");
51 printf(keyframe ?
"K" :
".");
59 int main(
int argc,
char **argv) {
67 VpxVideoWriter *writer = NULL;
68 const VpxInterface *encoder = NULL;
75 if (argc < 5) die(
"Invalid number of arguments");
77 encoder = get_vpx_encoder_by_name(
"vp9");
78 if (!encoder) die(
"Unsupported codec.");
80 info.codec_fourcc = encoder->fourcc;
81 info.frame_width = (int)strtol(argv[1], NULL, 0);
82 info.frame_height = (int)strtol(argv[2], NULL, 0);
83 info.time_base.numerator = 1;
84 info.time_base.denominator = fps;
86 if (info.frame_width <= 0 || info.frame_height <= 0 ||
87 (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
88 die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
92 info.frame_height, 1)) {
93 die(
"Failed to allocate image.");
99 if (res) die_codec(&codec,
"Failed to get default codec config.");
101 cfg.
g_w = info.frame_width;
102 cfg.
g_h = info.frame_height;
106 writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
107 if (!writer) die(
"Failed to open %s for writing.", argv[4]);
109 if (!(infile = fopen(argv[3],
"rb")))
110 die(
"Failed to open %s for reading.", argv[3]);
113 die_codec(&codec,
"Failed to initialize encoder");
116 die_codec(&codec,
"Failed to use lossless mode");
119 while (vpx_img_read(&raw, infile)) {
120 encode_frame(&codec, &raw, frame_count++, 0, writer);
124 while (encode_frame(&codec, NULL, -1, 0, writer)) {
129 printf(
"Processed %d frames.\n", frame_count);
134 vpx_video_writer_close(writer);
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:357
int den
Definition: vpx_encoder.h:231
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.
Encoder configuration structure.
Definition: vpx_encoder.h:279
Encoder output packet.
Definition: vpx_encoder.h:170
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:55
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:318
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:327
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:171
Codec control function to set lossless encoding mode.
Definition: vp8cx.h:321
Operation completed without error.
Definition: vpx_codec.h:92
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
int num
Definition: vpx_encoder.h:230
#define VPX_DL_GOOD_QUALITY
deadline parameter analogous to VPx GOOD QUALITY mode.
Definition: vpx_encoder.h:851
Provides definitions for using VP8 or VP9 encoder algorithm within the vpx Codec Interface.
#define vpx_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_enc_init_ver()
Definition: vpx_encoder.h:760
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:90
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_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_control_(vpx_codec_ctx_t *ctx, int ctrl_id,...)
Control algorithm.
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
#define VPX_FRAME_IS_KEY
Definition: vpx_encoder.h:122
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:187
Definition: vpx_encoder.h:153
Codec context structure.
Definition: vpx_codec.h:197