1~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_INCLUDES 2#define VPX_CODEC_DISABLE_COMPAT 1 3#include "vpx/vpx_encoder.h" 4#include "vpx/vp8cx.h" 5#define interface (vpx_codec_vp8_cx()) 6~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_INCLUDES 7 8 9~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DIE_CODEC 10static void die_codec(vpx_codec_ctx_t *ctx, const char *s) { 11 const char *detail = vpx_codec_error_detail(ctx); 12 13 printf("%s: %s\n", s, vpx_codec_error(ctx)); 14 if(detail) 15 printf(" %s\n",detail); 16 exit(EXIT_FAILURE); 17} 18~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DIE_CODEC 19 20 21~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE 22if(argc!=5) 23 die("Usage: %s <width> <height> <infile> <outfile>\n", argv[0]); 24~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ USAGE 25 26 27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_DEF_CFG 28/* Populate encoder configuration */ 29res = vpx_codec_enc_config_default(interface, &cfg, 0); 30if(res) { 31 printf("Failed to get config: %s\n", vpx_codec_err_to_string(res)); 32 return EXIT_FAILURE; 33} 34~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_DEF_CFG 35 36 37~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_SET_CFG 38/* Update the default configuration with our settings */ 39cfg.rc_target_bitrate = width * height * cfg.rc_target_bitrate 40 / cfg.g_w / cfg.g_h; 41cfg.g_w = width; 42cfg.g_h = height; 43~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_SET_CFG 44 45 46~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_INIT 47/* Initialize codec */ 48if(vpx_codec_enc_init(&codec, interface, &cfg, 0)) 49 die_codec(&codec, "Failed to initialize encoder"); 50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENC_INIT 51 52 53~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENCODE_FRAME 54frame_avail = read_frame(infile, &raw); 55if(vpx_codec_encode(&codec, frame_avail? &raw : NULL, frame_cnt, 56 1, flags, VPX_DL_REALTIME)) 57 die_codec(&codec, "Failed to encode frame"); 58~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENCODE_FRAME 59 60 61~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROCESS_FRAME 62case VPX_CODEC_CX_FRAME_PKT: 63 write_ivf_frame_header(outfile, pkt); 64 if(fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, 65 outfile)); 66 break; 67~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PROCESS_FRAME 68 69 70~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DESTROY 71if(vpx_codec_destroy(&codec)) 72 die_codec(&codec, "Failed to destroy codec"); 73~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DESTROY 74