56#include "vp9/common/vp9_common.h" 
   58#include "./tools_common.h" 
   59#include "./video_writer.h" 
   61static const char *exec_name;
 
   63void usage_exit(
void) {
 
   65          "Usage: %s <width> <height> <infile> <outfile> " 
   66          "<frame> <limit(optional)>\n",
 
   72                           unsigned int frame_out, 
int *mismatch_seen) {
 
   76  if (*mismatch_seen) 
return;
 
   81    die_codec(encoder, 
"Failed to get encoder reference frame");
 
   82  enc_img = ref_enc.img;
 
   84    die_codec(decoder, 
"Failed to get decoder reference frame");
 
   85  dec_img = ref_dec.img;
 
   87  if (!compare_img(&enc_img, &dec_img)) {
 
   92    find_mismatch(&enc_img, &dec_img, y, u, v);
 
   94        "Encode/decode mismatch on frame %d at" 
   98        frame_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0], v[1],
 
  107                        unsigned int frame_in, VpxVideoWriter *writer,
 
  109                        unsigned int *frame_out, 
int *mismatch_seen) {
 
  116  if (res != 
VPX_CODEC_OK) die_codec(ecodec, 
"Failed to encode frame");
 
  130      if (!vpx_video_writer_write_frame(writer, pkt->
data.
frame.
buf,
 
  133        die_codec(ecodec, 
"Failed to write compressed frame");
 
  135      printf(keyframe ? 
"K" : 
".");
 
  143          die_codec(dcodec, 
"Failed to decode frame.");
 
  149  if (got_data && test_decode) {
 
  150    testing_decode(ecodec, dcodec, *frame_out, mismatch_seen);
 
  156int main(
int argc, 
char **argv) {
 
  161  unsigned int frame_in = 0;
 
  165  VpxVideoWriter *writer = NULL;
 
  166  const VpxInterface *encoder = NULL;
 
  172  unsigned int frame_out = 0;
 
  175  unsigned int update_frame_num = 0;
 
  176  int mismatch_seen = 0;
 
  179  const int bitrate = 500;
 
  181  const char *width_arg = NULL;
 
  182  const char *height_arg = NULL;
 
  183  const char *infile_arg = NULL;
 
  184  const char *outfile_arg = NULL;
 
  185  const char *update_frame_num_arg = NULL;
 
  186  unsigned int limit = 0;
 
  194  if (argc < 6) die(
"Invalid number of arguments");
 
  197  height_arg = argv[2];
 
  198  infile_arg = argv[3];
 
  199  outfile_arg = argv[4];
 
  200  update_frame_num_arg = argv[5];
 
  202  encoder = get_vpx_encoder_by_name(
"vp9");
 
  203  if (!encoder) die(
"Unsupported codec.");
 
  205  update_frame_num = (
unsigned int)strtoul(update_frame_num_arg, NULL, 0);
 
  209  if (update_frame_num <= 1) {
 
  210    die(
"Couldn't parse frame number '%s'\n", update_frame_num_arg);
 
  214    limit = (
unsigned int)strtoul(argv[6], NULL, 0);
 
  215    if (update_frame_num > limit)
 
  216      die(
"Update frame number couldn't larger than limit\n");
 
  219  info.codec_fourcc = encoder->fourcc;
 
  220  info.frame_width = (int)strtol(width_arg, NULL, 0);
 
  221  info.frame_height = (int)strtol(height_arg, NULL, 0);
 
  222  info.time_base.numerator = 1;
 
  223  info.time_base.denominator = fps;
 
  225  if (info.frame_width <= 0 || info.frame_height <= 0 ||
 
  226      (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
 
  227    die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
 
  231                     info.frame_height, 1)) {
 
  232    die(
"Failed to allocate image.");
 
  238  if (res) die_codec(&ecodec, 
"Failed to get default codec config.");
 
  240  cfg.
g_w = info.frame_width;
 
  241  cfg.
g_h = info.frame_height;
 
  247  writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
 
  248  if (!writer) die(
"Failed to open %s for writing.", outfile_arg);
 
  250  if (!(infile = fopen(infile_arg, 
"rb")))
 
  251    die(
"Failed to open %s for reading.", infile_arg);
 
  254    die(
"Failed to initialize encoder");
 
  258    die_codec(&ecodec, 
"Failed to set enable auto alt ref");
 
  261    const VpxInterface *decoder = get_vpx_decoder_by_name(
"vp9");
 
  263      die_codec(&dcodec, 
"Failed to initialize decoder.");
 
  267  while (vpx_img_read(&raw, infile)) {
 
  268    if (limit && frame_in >= limit) 
break;
 
  269    if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
 
  275        die_codec(&ecodec, 
"Failed to set reference frame");
 
  276      printf(
" <SET_REF>");
 
  282          die_codec(&dcodec, 
"Failed to set reference frame");
 
  286    encode_frame(&ecodec, &raw, frame_in, writer, test_decode, &dcodec,
 
  287                 &frame_out, &mismatch_seen);
 
  289    if (mismatch_seen) 
break;
 
  294    while (encode_frame(&ecodec, NULL, frame_in, writer, test_decode, &dcodec,
 
  295                        &frame_out, &mismatch_seen)) {
 
  300  printf(
"Processed %d frames.\n", frame_out);
 
  304      printf(
"Encoder/decoder results are matching.\n");
 
  306      printf(
"Encoder/decoder results are NOT matching.\n");
 
  311      die_codec(&dcodec, 
"Failed to destroy decoder");
 
  315    die_codec(&ecodec, 
"Failed to destroy encoder.");
 
  317  vpx_video_writer_close(writer);
 
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
const void * vpx_codec_iter_t
Iterator.
Definition vpx_codec.h:190
const char * vpx_codec_iface_name(vpx_codec_iface_t *iface)
Return the name for a given interface.
#define vpx_codec_control(ctx, id, data)
vpx_codec_control wrapper macro
Definition vpx_codec.h:408
vpx_codec_err_t
Algorithm return codes.
Definition vpx_codec.h:93
@ VPX_CODEC_OK
Operation completed without error.
Definition vpx_codec.h:95
vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, unsigned int data_sz, void *user_priv, long deadline)
Decode data.
#define vpx_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_dec_init_ver()
Definition vpx_decoder.h:143
#define vpx_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_enc_init_ver()
Definition vpx_encoder.h:900
#define VPX_DL_GOOD_QUALITY
deadline parameter analogous to VPx GOOD QUALITY mode.
Definition vpx_encoder.h:1006
const vpx_codec_cx_pkt_t * vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Encoded data iterator.
#define VPX_FRAME_IS_KEY
Definition vpx_encoder.h:123
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, unsigned int usage)
Get a default configuration.
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, vpx_enc_deadline_t deadline)
Encode a frame.
#define VPX_FRAME_IS_FRAGMENT
this is a fragment of the encoded frame
Definition vpx_encoder.h:130
@ VPX_CODEC_CX_FRAME_PKT
Definition vpx_encoder.h:155
@ VP8E_SET_ENABLEAUTOALTREF
Codec control function to enable automatic use of arf frames.
Definition vp8cx.h:182
@ VP8_SET_REFERENCE
pass in an external frame into decoder to be used as reference frame
Definition vp8.h:47
@ VP9_GET_REFERENCE
Definition vp8.h:55
VP9 specific reference frame data struct.
Definition vp8.h:110
int idx
Definition vp8.h:111
vpx_image_t img
Definition vp8.h:112
Codec context structure.
Definition vpx_codec.h:200
Encoder output packet.
Definition vpx_encoder.h:167
vpx_codec_frame_flags_t flags
Definition vpx_encoder.h:177
enum vpx_codec_cx_pkt_kind kind
Definition vpx_encoder.h:168
struct vpx_codec_cx_pkt::@1::@2 frame
size_t sz
Definition vpx_encoder.h:172
void * buf
Definition vpx_encoder.h:171
vpx_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition vpx_encoder.h:174
union vpx_codec_cx_pkt::@1 data
Encoder configuration structure.
Definition vpx_encoder.h:276
unsigned int g_h
Height of the frame.
Definition vpx_encoder.h:321
unsigned int g_w
Width of the frame.
Definition vpx_encoder.h:312
struct vpx_rational g_timebase
Stream timebase units.
Definition vpx_encoder.h:351
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition vpx_encoder.h:380
unsigned int rc_target_bitrate
Target data rate.
Definition vpx_encoder.h:470
Image Descriptor.
Definition vpx_image.h:76
int den
Definition vpx_encoder.h:228
int num
Definition vpx_encoder.h:227
reference frame data struct
Definition vp8.h:101
vpx_ref_frame_type_t frame_type
Definition vp8.h:102
vpx_image_t img
Definition vp8.h:103
Provides definitions for using VP8 or VP9 encoder algorithm within the vpx Codec Interface.
Describes the decoder algorithm interface to applications.
Describes the encoder algorithm interface to applications.
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.
@ VPX_IMG_FMT_I420
Definition vpx_image.h:42
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.