52#include "../tools_common.h" 
   53#include "../video_writer.h" 
   55static const char *exec_name;
 
   57void usage_exit(
void) {
 
   58  fprintf(stderr, 
"Usage: %s <codec> <width> <height> <infile> <outfile>\n",
 
   67  memset(&roi, 0, 
sizeof(roi));
 
   69  roi.
rows = (cfg->
g_h + 15) / 16;
 
   70  roi.
cols = (cfg->
g_w + 15) / 16;
 
   91    die_codec(codec, 
"Failed to set ROI map");
 
  101  map.
rows = (cfg->
g_h + 15) / 16;
 
  102  map.
cols = (cfg->
g_w + 15) / 16;
 
  108    die_codec(codec, 
"Failed to set active map");
 
  117  map.
rows = (cfg->
g_h + 15) / 16;
 
  118  map.
cols = (cfg->
g_w + 15) / 16;
 
  122    die_codec(codec, 
"Failed to set active map");
 
  126                        int frame_index, VpxVideoWriter *writer) {
 
  132  if (res != 
VPX_CODEC_OK) die_codec(codec, 
"Failed to encode frame");
 
  139      if (!vpx_video_writer_write_frame(writer, pkt->
data.
frame.
buf,
 
  142        die_codec(codec, 
"Failed to write compressed frame");
 
  145      printf(keyframe ? 
"K" : 
".");
 
  153int main(
int argc, 
char **argv) {
 
  161  VpxVideoWriter *writer = NULL;
 
  162  const VpxInterface *encoder = NULL;
 
  164  const double bits_per_pixel_per_frame = 0.067;
 
  167  if (argc != 6) die(
"Invalid number of arguments");
 
  169  memset(&info, 0, 
sizeof(info));
 
  171  encoder = get_vpx_encoder_by_name(argv[1]);
 
  172  if (encoder == NULL) {
 
  173    die(
"Unsupported codec.");
 
  175  assert(encoder != NULL);
 
  176  info.codec_fourcc = encoder->fourcc;
 
  177  info.frame_width = (int)strtol(argv[2], NULL, 0);
 
  178  info.frame_height = (int)strtol(argv[3], NULL, 0);
 
  179  info.time_base.numerator = 1;
 
  180  info.time_base.denominator = fps;
 
  182  if (info.frame_width <= 0 || info.frame_height <= 0 ||
 
  183      (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
 
  184    die(
"Invalid frame size: %dx%d", info.frame_width, info.frame_height);
 
  188                     info.frame_height, 1)) {
 
  189    die(
"Failed to allocate image.");
 
  195  if (res) die_codec(&codec, 
"Failed to get default codec config.");
 
  197  cfg.
g_w = info.frame_width;
 
  198  cfg.
g_h = info.frame_height;
 
  202      (
unsigned int)(bits_per_pixel_per_frame * cfg.
g_w * cfg.
g_h * fps / 1000);
 
  205  writer = vpx_video_writer_open(argv[5], kContainerIVF, &info);
 
  206  if (!writer) die(
"Failed to open %s for writing.", argv[5]);
 
  208  if (!(infile = fopen(argv[4], 
"rb")))
 
  209    die(
"Failed to open %s for reading.", argv[4]);
 
  212    die(
"Failed to initialize encoder");
 
  215  while (vpx_img_read(&raw, infile)) {
 
  218    if (frame_count == 22 && encoder->fourcc == VP8_FOURCC) {
 
  219      set_roi_map(&cfg, &codec);
 
  220    } 
else if (frame_count == 33) {
 
  221      set_active_map(&cfg, &codec);
 
  222    } 
else if (frame_count == 44) {
 
  223      unset_active_map(&cfg, &codec);
 
  226    encode_frame(&codec, &raw, frame_count, writer);
 
  230  while (encode_frame(&codec, NULL, -1, writer)) {
 
  235  printf(
"Processed %d frames.\n", frame_count);
 
  240  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:407
vpx_codec_err_t
Algorithm return codes.
Definition vpx_codec.h:93
@ VPX_CODEC_OK
Operation completed without error.
Definition vpx_codec.h:95
#define vpx_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_enc_init_ver()
Definition vpx_encoder.h:890
#define VPX_DL_GOOD_QUALITY
deadline parameter analogous to VPx GOOD QUALITY mode.
Definition vpx_encoder.h:981
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:118
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, unsigned long deadline)
Encode a frame.
@ VPX_CODEC_CX_FRAME_PKT
Definition vpx_encoder.h:150
@ VP8E_SET_ROI_MAP
Codec control function to pass an ROI map to encoder.
Definition vp8cx.h:147
@ VP8E_SET_ACTIVEMAP
Codec control function to pass an Active map to encoder.
Definition vp8cx.h:153
vpx active region map
Definition vp8cx.h:840
unsigned int rows
Definition vp8cx.h:843
unsigned int cols
Definition vp8cx.h:844
unsigned char * active_map
specify an on (1) or off (0) each 16x16 region within a frame
Definition vp8cx.h:842
Codec context structure.
Definition vpx_codec.h:200
Encoder output packet.
Definition vpx_encoder.h:162
vpx_codec_frame_flags_t flags
Definition vpx_encoder.h:172
enum vpx_codec_cx_pkt_kind kind
Definition vpx_encoder.h:163
struct vpx_codec_cx_pkt::@1::@2 frame
size_t sz
Definition vpx_encoder.h:167
void * buf
Definition vpx_encoder.h:166
vpx_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition vpx_encoder.h:169
union vpx_codec_cx_pkt::@1 data
Encoder configuration structure.
Definition vpx_encoder.h:271
unsigned int g_h
Height of the frame.
Definition vpx_encoder.h:316
unsigned int g_w
Width of the frame.
Definition vpx_encoder.h:307
struct vpx_rational g_timebase
Stream timebase units.
Definition vpx_encoder.h:346
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition vpx_encoder.h:375
unsigned int rc_target_bitrate
Target data rate.
Definition vpx_encoder.h:463
Image Descriptor.
Definition vpx_image.h:72
int den
Definition vpx_encoder.h:223
int num
Definition vpx_encoder.h:222
vpx region of interest map
Definition vp8cx.h:816
unsigned int static_threshold[4]
Definition vp8cx.h:831
unsigned int rows
Definition vp8cx.h:822
unsigned int cols
Definition vp8cx.h:823
int delta_q[8]
Definition vp8cx.h:825
unsigned char * roi_map
Definition vp8cx.h:821
int delta_lf[8]
Definition vp8cx.h:826
Provides definitions for using VP8 or VP9 encoder algorithm within the vpx Codec Interface.
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.