examples: apply clang-format
Change-Id: I06903104bf822819fae39e42fdb6e44d3f9d7787
This commit is contained in:
@@ -65,8 +65,7 @@ static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) {
|
|||||||
static void print_md5(FILE *stream, unsigned char digest[16]) {
|
static void print_md5(FILE *stream, unsigned char digest[16]) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 16; ++i)
|
for (i = 0; i < 16; ++i) fprintf(stream, "%02x", digest[i]);
|
||||||
fprintf(stream, "%02x", digest[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *exec_name;
|
static const char *exec_name;
|
||||||
@@ -86,12 +85,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
|
|
||||||
if (argc != 3)
|
if (argc != 3) die("Invalid number of arguments.");
|
||||||
die("Invalid number of arguments.");
|
|
||||||
|
|
||||||
reader = vpx_video_reader_open(argv[1]);
|
reader = vpx_video_reader_open(argv[1]);
|
||||||
if (!reader)
|
if (!reader) die("Failed to open %s for reading.", argv[1]);
|
||||||
die("Failed to open %s for reading.", argv[1]);
|
|
||||||
|
|
||||||
if (!(outfile = fopen(argv[2], "wb")))
|
if (!(outfile = fopen(argv[2], "wb")))
|
||||||
die("Failed to open %s for writing.", argv[2]);
|
die("Failed to open %s for writing.", argv[2]);
|
||||||
@@ -99,8 +96,7 @@ int main(int argc, char **argv) {
|
|||||||
info = vpx_video_reader_get_info(reader);
|
info = vpx_video_reader_get_info(reader);
|
||||||
|
|
||||||
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
|
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
|
||||||
if (!decoder)
|
if (!decoder) die("Unknown input codec.");
|
||||||
die("Unknown input codec.");
|
|
||||||
|
|
||||||
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
|
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
|
||||||
|
|
||||||
@@ -111,8 +107,8 @@ int main(int argc, char **argv) {
|
|||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
vpx_image_t *img = NULL;
|
vpx_image_t *img = NULL;
|
||||||
size_t frame_size = 0;
|
size_t frame_size = 0;
|
||||||
const unsigned char *frame = vpx_video_reader_get_frame(reader,
|
const unsigned char *frame =
|
||||||
&frame_size);
|
vpx_video_reader_get_frame(reader, &frame_size);
|
||||||
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
||||||
die_codec(&codec, "Failed to decode frame");
|
die_codec(&codec, "Failed to decode frame");
|
||||||
|
|
||||||
@@ -121,14 +117,13 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
get_image_md5(img, digest);
|
get_image_md5(img, digest);
|
||||||
print_md5(outfile, digest);
|
print_md5(outfile, digest);
|
||||||
fprintf(outfile, " img-%dx%d-%04d.i420\n",
|
fprintf(outfile, " img-%dx%d-%04d.i420\n", img->d_w, img->d_h,
|
||||||
img->d_w, img->d_h, ++frame_cnt);
|
++frame_cnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Processed %d frames.\n", frame_cnt);
|
printf("Processed %d frames.\n", frame_cnt);
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
||||||
die_codec(&codec, "Failed to destroy codec.");
|
|
||||||
|
|
||||||
vpx_video_reader_close(reader);
|
vpx_video_reader_close(reader);
|
||||||
|
|
||||||
|
@@ -84,12 +84,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
|
|
||||||
if (argc != 4)
|
if (argc != 4) die("Invalid number of arguments.");
|
||||||
die("Invalid number of arguments.");
|
|
||||||
|
|
||||||
reader = vpx_video_reader_open(argv[1]);
|
reader = vpx_video_reader_open(argv[1]);
|
||||||
if (!reader)
|
if (!reader) die("Failed to open %s for reading.", argv[1]);
|
||||||
die("Failed to open %s for reading.", argv[1]);
|
|
||||||
|
|
||||||
if (!(outfile = fopen(argv[2], "wb")))
|
if (!(outfile = fopen(argv[2], "wb")))
|
||||||
die("Failed to open %s for writing.", argv[2]);
|
die("Failed to open %s for writing.", argv[2]);
|
||||||
@@ -103,8 +101,7 @@ int main(int argc, char **argv) {
|
|||||||
info = vpx_video_reader_get_info(reader);
|
info = vpx_video_reader_get_info(reader);
|
||||||
|
|
||||||
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
|
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
|
||||||
if (!decoder)
|
if (!decoder) die("Unknown input codec.");
|
||||||
die("Unknown input codec.");
|
|
||||||
|
|
||||||
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
|
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
|
||||||
|
|
||||||
@@ -116,8 +113,8 @@ int main(int argc, char **argv) {
|
|||||||
vpx_image_t *img = NULL;
|
vpx_image_t *img = NULL;
|
||||||
size_t frame_size = 0;
|
size_t frame_size = 0;
|
||||||
int skip;
|
int skip;
|
||||||
const unsigned char *frame = vpx_video_reader_get_frame(reader,
|
const unsigned char *frame =
|
||||||
&frame_size);
|
vpx_video_reader_get_frame(reader, &frame_size);
|
||||||
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
||||||
die_codec(&codec, "Failed to decode frame.");
|
die_codec(&codec, "Failed to decode frame.");
|
||||||
|
|
||||||
@@ -139,8 +136,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Processed %d frames.\n", frame_cnt);
|
printf("Processed %d frames.\n", frame_cnt);
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
||||||
die_codec(&codec, "Failed to destroy codec.");
|
|
||||||
|
|
||||||
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
|
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
|
||||||
info->frame_width, info->frame_height, argv[2]);
|
info->frame_width, info->frame_height, argv[2]);
|
||||||
|
@@ -21,32 +21,28 @@
|
|||||||
static const char *exec_name;
|
static const char *exec_name;
|
||||||
|
|
||||||
void usage_exit(void) {
|
void usage_exit(void) {
|
||||||
fprintf(stderr, "lossless_encoder: Example demonstrating lossless "
|
fprintf(stderr,
|
||||||
"encoding feature. Supports raw input only.\n");
|
"lossless_encoder: Example demonstrating lossless "
|
||||||
|
"encoding feature. Supports raw input only.\n");
|
||||||
fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile>\n", exec_name);
|
fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile>\n", exec_name);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int encode_frame(vpx_codec_ctx_t *codec,
|
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
|
||||||
vpx_image_t *img,
|
int frame_index, int flags, VpxVideoWriter *writer) {
|
||||||
int frame_index,
|
|
||||||
int flags,
|
|
||||||
VpxVideoWriter *writer) {
|
|
||||||
int got_pkts = 0;
|
int got_pkts = 0;
|
||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
const vpx_codec_cx_pkt_t *pkt = NULL;
|
const vpx_codec_cx_pkt_t *pkt = NULL;
|
||||||
const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1,
|
const vpx_codec_err_t res =
|
||||||
flags, VPX_DL_GOOD_QUALITY);
|
vpx_codec_encode(codec, img, frame_index, 1, flags, VPX_DL_GOOD_QUALITY);
|
||||||
if (res != VPX_CODEC_OK)
|
if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame");
|
||||||
die_codec(codec, "Failed to encode frame");
|
|
||||||
|
|
||||||
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
|
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
|
||||||
got_pkts = 1;
|
got_pkts = 1;
|
||||||
|
|
||||||
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
|
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
|
||||||
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
||||||
if (!vpx_video_writer_write_frame(writer,
|
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
|
||||||
pkt->data.frame.buf,
|
|
||||||
pkt->data.frame.sz,
|
pkt->data.frame.sz,
|
||||||
pkt->data.frame.pts)) {
|
pkt->data.frame.pts)) {
|
||||||
die_codec(codec, "Failed to write compressed frame");
|
die_codec(codec, "Failed to write compressed frame");
|
||||||
@@ -66,19 +62,17 @@ int main(int argc, char **argv) {
|
|||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
vpx_image_t raw;
|
vpx_image_t raw;
|
||||||
vpx_codec_err_t res;
|
vpx_codec_err_t res;
|
||||||
VpxVideoInfo info = {0};
|
VpxVideoInfo info = { 0 };
|
||||||
VpxVideoWriter *writer = NULL;
|
VpxVideoWriter *writer = NULL;
|
||||||
const VpxInterface *encoder = NULL;
|
const VpxInterface *encoder = NULL;
|
||||||
const int fps = 30;
|
const int fps = 30;
|
||||||
|
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
|
|
||||||
if (argc < 5)
|
if (argc < 5) die("Invalid number of arguments");
|
||||||
die("Invalid number of arguments");
|
|
||||||
|
|
||||||
encoder = get_vpx_encoder_by_name("vp9");
|
encoder = get_vpx_encoder_by_name("vp9");
|
||||||
if (!encoder)
|
if (!encoder) die("Unsupported codec.");
|
||||||
die("Unsupported codec.");
|
|
||||||
|
|
||||||
info.codec_fourcc = encoder->fourcc;
|
info.codec_fourcc = encoder->fourcc;
|
||||||
info.frame_width = strtol(argv[1], NULL, 0);
|
info.frame_width = strtol(argv[1], NULL, 0);
|
||||||
@@ -86,23 +80,20 @@ int main(int argc, char **argv) {
|
|||||||
info.time_base.numerator = 1;
|
info.time_base.numerator = 1;
|
||||||
info.time_base.denominator = fps;
|
info.time_base.denominator = fps;
|
||||||
|
|
||||||
if (info.frame_width <= 0 ||
|
if (info.frame_width <= 0 || info.frame_height <= 0 ||
|
||||||
info.frame_height <= 0 ||
|
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
|
||||||
(info.frame_width % 2) != 0 ||
|
|
||||||
(info.frame_height % 2) != 0) {
|
|
||||||
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
||||||
info.frame_height, 1)) {
|
info.frame_height, 1)) {
|
||||||
die("Failed to allocate image.");
|
die("Failed to allocate image.");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||||
|
|
||||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||||
if (res)
|
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||||
die_codec(&codec, "Failed to get default codec config.");
|
|
||||||
|
|
||||||
cfg.g_w = info.frame_width;
|
cfg.g_w = info.frame_width;
|
||||||
cfg.g_h = info.frame_height;
|
cfg.g_h = info.frame_height;
|
||||||
@@ -110,8 +101,7 @@ int main(int argc, char **argv) {
|
|||||||
cfg.g_timebase.den = info.time_base.denominator;
|
cfg.g_timebase.den = info.time_base.denominator;
|
||||||
|
|
||||||
writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
|
writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
|
||||||
if (!writer)
|
if (!writer) die("Failed to open %s for writing.", argv[4]);
|
||||||
die("Failed to open %s for writing.", argv[4]);
|
|
||||||
|
|
||||||
if (!(infile = fopen(argv[3], "rb")))
|
if (!(infile = fopen(argv[3], "rb")))
|
||||||
die("Failed to open %s for reading.", argv[3]);
|
die("Failed to open %s for reading.", argv[3]);
|
||||||
@@ -128,15 +118,15 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Flush encoder.
|
// Flush encoder.
|
||||||
while (encode_frame(&codec, NULL, -1, 0, writer)) {}
|
while (encode_frame(&codec, NULL, -1, 0, writer)) {
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
printf("Processed %d frames.\n", frame_count);
|
printf("Processed %d frames.\n", frame_count);
|
||||||
|
|
||||||
vpx_img_free(&raw);
|
vpx_img_free(&raw);
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
||||||
die_codec(&codec, "Failed to destroy codec.");
|
|
||||||
|
|
||||||
vpx_video_writer_close(writer);
|
vpx_video_writer_close(writer);
|
||||||
|
|
||||||
|
@@ -34,10 +34,8 @@ void usage_exit(void) {
|
|||||||
|
|
||||||
static int parse_dim(char *v, int *width, int *height) {
|
static int parse_dim(char *v, int *width, int *height) {
|
||||||
char *x = strchr(v, 'x');
|
char *x = strchr(v, 'x');
|
||||||
if (x == NULL)
|
if (x == NULL) x = strchr(v, 'X');
|
||||||
x = strchr(v, 'X');
|
if (x == NULL) return 0;
|
||||||
if (x == NULL)
|
|
||||||
return 0;
|
|
||||||
*width = atoi(v);
|
*width = atoi(v);
|
||||||
*height = atoi(&x[1]);
|
*height = atoi(&x[1]);
|
||||||
if (*width <= 0 || *height <= 0)
|
if (*width <= 0 || *height <= 0)
|
||||||
@@ -93,30 +91,25 @@ int main(int argc, char *argv[]) {
|
|||||||
else
|
else
|
||||||
frames = INT_MAX;
|
frames = INT_MAX;
|
||||||
|
|
||||||
printf("Input size: %dx%d\n",
|
printf("Input size: %dx%d\n", width, height);
|
||||||
width, height);
|
printf("Target size: %dx%d, Frames: ", target_width, target_height);
|
||||||
printf("Target size: %dx%d, Frames: ",
|
|
||||||
target_width, target_height);
|
|
||||||
if (frames == INT_MAX)
|
if (frames == INT_MAX)
|
||||||
printf("All\n");
|
printf("All\n");
|
||||||
else
|
else
|
||||||
printf("%d\n", frames);
|
printf("%d\n", frames);
|
||||||
|
|
||||||
inbuf = (uint8_t*)malloc(width * height * 3 / 2);
|
inbuf = (uint8_t *)malloc(width * height * 3 / 2);
|
||||||
outbuf = (uint8_t*)malloc(target_width * target_height * 3 / 2);
|
outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2);
|
||||||
inbuf_u = inbuf + width * height;
|
inbuf_u = inbuf + width * height;
|
||||||
inbuf_v = inbuf_u + width * height / 4;
|
inbuf_v = inbuf_u + width * height / 4;
|
||||||
outbuf_u = outbuf + target_width * target_height;
|
outbuf_u = outbuf + target_width * target_height;
|
||||||
outbuf_v = outbuf_u + target_width * target_height / 4;
|
outbuf_v = outbuf_u + target_width * target_height / 4;
|
||||||
f = 0;
|
f = 0;
|
||||||
while (f < frames) {
|
while (f < frames) {
|
||||||
if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1)
|
if (fread(inbuf, width * height * 3 / 2, 1, fpin) != 1) break;
|
||||||
break;
|
vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2, height,
|
||||||
vp9_resize_frame420(inbuf, width, inbuf_u, inbuf_v, width / 2,
|
width, outbuf, target_width, outbuf_u, outbuf_v,
|
||||||
height, width,
|
target_width / 2, target_height, target_width);
|
||||||
outbuf, target_width, outbuf_u, outbuf_v,
|
|
||||||
target_width / 2,
|
|
||||||
target_height, target_width);
|
|
||||||
fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout);
|
fwrite(outbuf, target_width * target_height * 3 / 2, 1, fpout);
|
||||||
f++;
|
f++;
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// VP8 Set Active and ROI Maps
|
// VP8 Set Active and ROI Maps
|
||||||
// ===========================
|
// ===========================
|
||||||
//
|
//
|
||||||
@@ -86,8 +85,7 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
|
|||||||
roi.static_threshold[3] = 0;
|
roi.static_threshold[3] = 0;
|
||||||
|
|
||||||
roi.roi_map = (uint8_t *)malloc(roi.rows * roi.cols);
|
roi.roi_map = (uint8_t *)malloc(roi.rows * roi.cols);
|
||||||
for (i = 0; i < roi.rows * roi.cols; ++i)
|
for (i = 0; i < roi.rows * roi.cols; ++i) roi.roi_map[i] = i % 4;
|
||||||
roi.roi_map[i] = i % 4;
|
|
||||||
|
|
||||||
if (vpx_codec_control(codec, VP8E_SET_ROI_MAP, &roi))
|
if (vpx_codec_control(codec, VP8E_SET_ROI_MAP, &roi))
|
||||||
die_codec(codec, "Failed to set ROI map");
|
die_codec(codec, "Failed to set ROI map");
|
||||||
@@ -98,14 +96,13 @@ static void set_roi_map(const vpx_codec_enc_cfg_t *cfg,
|
|||||||
static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
|
static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
|
||||||
vpx_codec_ctx_t *codec) {
|
vpx_codec_ctx_t *codec) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
vpx_active_map_t map = {0, 0, 0};
|
vpx_active_map_t map = { 0, 0, 0 };
|
||||||
|
|
||||||
map.rows = (cfg->g_h + 15) / 16;
|
map.rows = (cfg->g_h + 15) / 16;
|
||||||
map.cols = (cfg->g_w + 15) / 16;
|
map.cols = (cfg->g_w + 15) / 16;
|
||||||
|
|
||||||
map.active_map = (uint8_t *)malloc(map.rows * map.cols);
|
map.active_map = (uint8_t *)malloc(map.rows * map.cols);
|
||||||
for (i = 0; i < map.rows * map.cols; ++i)
|
for (i = 0; i < map.rows * map.cols; ++i) map.active_map[i] = i % 2;
|
||||||
map.active_map[i] = i % 2;
|
|
||||||
|
|
||||||
if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map))
|
if (vpx_codec_control(codec, VP8E_SET_ACTIVEMAP, &map))
|
||||||
die_codec(codec, "Failed to set active map");
|
die_codec(codec, "Failed to set active map");
|
||||||
@@ -115,7 +112,7 @@ static void set_active_map(const vpx_codec_enc_cfg_t *cfg,
|
|||||||
|
|
||||||
static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
|
static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
|
||||||
vpx_codec_ctx_t *codec) {
|
vpx_codec_ctx_t *codec) {
|
||||||
vpx_active_map_t map = {0, 0, 0};
|
vpx_active_map_t map = { 0, 0, 0 };
|
||||||
|
|
||||||
map.rows = (cfg->g_h + 15) / 16;
|
map.rows = (cfg->g_h + 15) / 16;
|
||||||
map.cols = (cfg->g_w + 15) / 16;
|
map.cols = (cfg->g_w + 15) / 16;
|
||||||
@@ -125,25 +122,21 @@ static void unset_active_map(const vpx_codec_enc_cfg_t *cfg,
|
|||||||
die_codec(codec, "Failed to set active map");
|
die_codec(codec, "Failed to set active map");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int encode_frame(vpx_codec_ctx_t *codec,
|
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
|
||||||
vpx_image_t *img,
|
int frame_index, VpxVideoWriter *writer) {
|
||||||
int frame_index,
|
|
||||||
VpxVideoWriter *writer) {
|
|
||||||
int got_pkts = 0;
|
int got_pkts = 0;
|
||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
const vpx_codec_cx_pkt_t *pkt = NULL;
|
const vpx_codec_cx_pkt_t *pkt = NULL;
|
||||||
const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0,
|
const vpx_codec_err_t res =
|
||||||
VPX_DL_GOOD_QUALITY);
|
vpx_codec_encode(codec, img, frame_index, 1, 0, VPX_DL_GOOD_QUALITY);
|
||||||
if (res != VPX_CODEC_OK)
|
if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame");
|
||||||
die_codec(codec, "Failed to encode frame");
|
|
||||||
|
|
||||||
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
|
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
|
||||||
got_pkts = 1;
|
got_pkts = 1;
|
||||||
|
|
||||||
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
|
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
|
||||||
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
||||||
if (!vpx_video_writer_write_frame(writer,
|
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
|
||||||
pkt->data.frame.buf,
|
|
||||||
pkt->data.frame.sz,
|
pkt->data.frame.sz,
|
||||||
pkt->data.frame.pts)) {
|
pkt->data.frame.pts)) {
|
||||||
die_codec(codec, "Failed to write compressed frame");
|
die_codec(codec, "Failed to write compressed frame");
|
||||||
@@ -167,12 +160,11 @@ int main(int argc, char **argv) {
|
|||||||
VpxVideoInfo info;
|
VpxVideoInfo info;
|
||||||
VpxVideoWriter *writer = NULL;
|
VpxVideoWriter *writer = NULL;
|
||||||
const VpxInterface *encoder = NULL;
|
const VpxInterface *encoder = NULL;
|
||||||
const int fps = 2; // TODO(dkovalev) add command line argument
|
const int fps = 2; // TODO(dkovalev) add command line argument
|
||||||
const double bits_per_pixel_per_frame = 0.067;
|
const double bits_per_pixel_per_frame = 0.067;
|
||||||
|
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
if (argc != 6)
|
if (argc != 6) die("Invalid number of arguments");
|
||||||
die("Invalid number of arguments");
|
|
||||||
|
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
|
|
||||||
@@ -187,35 +179,31 @@ int main(int argc, char **argv) {
|
|||||||
info.time_base.numerator = 1;
|
info.time_base.numerator = 1;
|
||||||
info.time_base.denominator = fps;
|
info.time_base.denominator = fps;
|
||||||
|
|
||||||
if (info.frame_width <= 0 ||
|
if (info.frame_width <= 0 || info.frame_height <= 0 ||
|
||||||
info.frame_height <= 0 ||
|
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
|
||||||
(info.frame_width % 2) != 0 ||
|
|
||||||
(info.frame_height % 2) != 0) {
|
|
||||||
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
||||||
info.frame_height, 1)) {
|
info.frame_height, 1)) {
|
||||||
die("Failed to allocate image.");
|
die("Failed to allocate image.");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||||
|
|
||||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||||
if (res)
|
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||||
die_codec(&codec, "Failed to get default codec config.");
|
|
||||||
|
|
||||||
cfg.g_w = info.frame_width;
|
cfg.g_w = info.frame_width;
|
||||||
cfg.g_h = info.frame_height;
|
cfg.g_h = info.frame_height;
|
||||||
cfg.g_timebase.num = info.time_base.numerator;
|
cfg.g_timebase.num = info.time_base.numerator;
|
||||||
cfg.g_timebase.den = info.time_base.denominator;
|
cfg.g_timebase.den = info.time_base.denominator;
|
||||||
cfg.rc_target_bitrate = (unsigned int)(bits_per_pixel_per_frame * cfg.g_w *
|
cfg.rc_target_bitrate =
|
||||||
cfg.g_h * fps / 1000);
|
(unsigned int)(bits_per_pixel_per_frame * cfg.g_w * cfg.g_h * fps / 1000);
|
||||||
cfg.g_lag_in_frames = 0;
|
cfg.g_lag_in_frames = 0;
|
||||||
|
|
||||||
writer = vpx_video_writer_open(argv[5], kContainerIVF, &info);
|
writer = vpx_video_writer_open(argv[5], kContainerIVF, &info);
|
||||||
if (!writer)
|
if (!writer) die("Failed to open %s for writing.", argv[5]);
|
||||||
die("Failed to open %s for writing.", argv[5]);
|
|
||||||
|
|
||||||
if (!(infile = fopen(argv[4], "rb")))
|
if (!(infile = fopen(argv[4], "rb")))
|
||||||
die("Failed to open %s for reading.", argv[4]);
|
die("Failed to open %s for reading.", argv[4]);
|
||||||
@@ -239,15 +227,15 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Flush encoder.
|
// Flush encoder.
|
||||||
while (encode_frame(&codec, NULL, -1, writer)) {}
|
while (encode_frame(&codec, NULL, -1, writer)) {
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
printf("Processed %d frames.\n", frame_count);
|
printf("Processed %d frames.\n", frame_count);
|
||||||
|
|
||||||
vpx_img_free(&raw);
|
vpx_img_free(&raw);
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
||||||
die_codec(&codec, "Failed to destroy codec.");
|
|
||||||
|
|
||||||
vpx_video_writer_close(writer);
|
vpx_video_writer_close(writer);
|
||||||
|
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Simple Decoder
|
// Simple Decoder
|
||||||
// ==============
|
// ==============
|
||||||
//
|
//
|
||||||
@@ -103,12 +102,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
|
|
||||||
if (argc != 3)
|
if (argc != 3) die("Invalid number of arguments.");
|
||||||
die("Invalid number of arguments.");
|
|
||||||
|
|
||||||
reader = vpx_video_reader_open(argv[1]);
|
reader = vpx_video_reader_open(argv[1]);
|
||||||
if (!reader)
|
if (!reader) die("Failed to open %s for reading.", argv[1]);
|
||||||
die("Failed to open %s for reading.", argv[1]);
|
|
||||||
|
|
||||||
if (!(outfile = fopen(argv[2], "wb")))
|
if (!(outfile = fopen(argv[2], "wb")))
|
||||||
die("Failed to open %s for writing.", argv[2]);
|
die("Failed to open %s for writing.", argv[2]);
|
||||||
@@ -116,8 +113,7 @@ int main(int argc, char **argv) {
|
|||||||
info = vpx_video_reader_get_info(reader);
|
info = vpx_video_reader_get_info(reader);
|
||||||
|
|
||||||
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
|
decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
|
||||||
if (!decoder)
|
if (!decoder) die("Unknown input codec.");
|
||||||
die("Unknown input codec.");
|
|
||||||
|
|
||||||
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
|
printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
|
||||||
|
|
||||||
@@ -128,8 +124,8 @@ int main(int argc, char **argv) {
|
|||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
vpx_image_t *img = NULL;
|
vpx_image_t *img = NULL;
|
||||||
size_t frame_size = 0;
|
size_t frame_size = 0;
|
||||||
const unsigned char *frame = vpx_video_reader_get_frame(reader,
|
const unsigned char *frame =
|
||||||
&frame_size);
|
vpx_video_reader_get_frame(reader, &frame_size);
|
||||||
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
||||||
die_codec(&codec, "Failed to decode frame.");
|
die_codec(&codec, "Failed to decode frame.");
|
||||||
|
|
||||||
@@ -140,8 +136,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("Processed %d frames.\n", frame_cnt);
|
printf("Processed %d frames.\n", frame_cnt);
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
|
||||||
die_codec(&codec, "Failed to destroy codec");
|
|
||||||
|
|
||||||
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
|
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
|
||||||
info->frame_width, info->frame_height, argv[2]);
|
info->frame_width, info->frame_height, argv[2]);
|
||||||
|
@@ -109,32 +109,27 @@ static const char *exec_name;
|
|||||||
void usage_exit(void) {
|
void usage_exit(void) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: %s <codec> <width> <height> <infile> <outfile> "
|
"Usage: %s <codec> <width> <height> <infile> <outfile> "
|
||||||
"<keyframe-interval> <error-resilient> <frames to encode>\n"
|
"<keyframe-interval> <error-resilient> <frames to encode>\n"
|
||||||
"See comments in simple_encoder.c for more information.\n",
|
"See comments in simple_encoder.c for more information.\n",
|
||||||
exec_name);
|
exec_name);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int encode_frame(vpx_codec_ctx_t *codec,
|
static int encode_frame(vpx_codec_ctx_t *codec, vpx_image_t *img,
|
||||||
vpx_image_t *img,
|
int frame_index, int flags, VpxVideoWriter *writer) {
|
||||||
int frame_index,
|
|
||||||
int flags,
|
|
||||||
VpxVideoWriter *writer) {
|
|
||||||
int got_pkts = 0;
|
int got_pkts = 0;
|
||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
const vpx_codec_cx_pkt_t *pkt = NULL;
|
const vpx_codec_cx_pkt_t *pkt = NULL;
|
||||||
const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1,
|
const vpx_codec_err_t res =
|
||||||
flags, VPX_DL_GOOD_QUALITY);
|
vpx_codec_encode(codec, img, frame_index, 1, flags, VPX_DL_GOOD_QUALITY);
|
||||||
if (res != VPX_CODEC_OK)
|
if (res != VPX_CODEC_OK) die_codec(codec, "Failed to encode frame");
|
||||||
die_codec(codec, "Failed to encode frame");
|
|
||||||
|
|
||||||
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
|
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
|
||||||
got_pkts = 1;
|
got_pkts = 1;
|
||||||
|
|
||||||
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
|
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
|
||||||
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
||||||
if (!vpx_video_writer_write_frame(writer,
|
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
|
||||||
pkt->data.frame.buf,
|
|
||||||
pkt->data.frame.sz,
|
pkt->data.frame.sz,
|
||||||
pkt->data.frame.pts)) {
|
pkt->data.frame.pts)) {
|
||||||
die_codec(codec, "Failed to write compressed frame");
|
die_codec(codec, "Failed to write compressed frame");
|
||||||
@@ -155,7 +150,7 @@ int main(int argc, char **argv) {
|
|||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
vpx_image_t raw;
|
vpx_image_t raw;
|
||||||
vpx_codec_err_t res;
|
vpx_codec_err_t res;
|
||||||
VpxVideoInfo info = {0};
|
VpxVideoInfo info = { 0 };
|
||||||
VpxVideoWriter *writer = NULL;
|
VpxVideoWriter *writer = NULL;
|
||||||
const VpxInterface *encoder = NULL;
|
const VpxInterface *encoder = NULL;
|
||||||
const int fps = 30;
|
const int fps = 30;
|
||||||
@@ -172,8 +167,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
|
|
||||||
if (argc != 9)
|
if (argc != 9) die("Invalid number of arguments");
|
||||||
die("Invalid number of arguments");
|
|
||||||
|
|
||||||
codec_arg = argv[1];
|
codec_arg = argv[1];
|
||||||
width_arg = argv[2];
|
width_arg = argv[2];
|
||||||
@@ -184,8 +178,7 @@ int main(int argc, char **argv) {
|
|||||||
max_frames = strtol(argv[8], NULL, 0);
|
max_frames = strtol(argv[8], NULL, 0);
|
||||||
|
|
||||||
encoder = get_vpx_encoder_by_name(codec_arg);
|
encoder = get_vpx_encoder_by_name(codec_arg);
|
||||||
if (!encoder)
|
if (!encoder) die("Unsupported codec.");
|
||||||
die("Unsupported codec.");
|
|
||||||
|
|
||||||
info.codec_fourcc = encoder->fourcc;
|
info.codec_fourcc = encoder->fourcc;
|
||||||
info.frame_width = strtol(width_arg, NULL, 0);
|
info.frame_width = strtol(width_arg, NULL, 0);
|
||||||
@@ -193,27 +186,23 @@ int main(int argc, char **argv) {
|
|||||||
info.time_base.numerator = 1;
|
info.time_base.numerator = 1;
|
||||||
info.time_base.denominator = fps;
|
info.time_base.denominator = fps;
|
||||||
|
|
||||||
if (info.frame_width <= 0 ||
|
if (info.frame_width <= 0 || info.frame_height <= 0 ||
|
||||||
info.frame_height <= 0 ||
|
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
|
||||||
(info.frame_width % 2) != 0 ||
|
|
||||||
(info.frame_height % 2) != 0) {
|
|
||||||
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
||||||
info.frame_height, 1)) {
|
info.frame_height, 1)) {
|
||||||
die("Failed to allocate image.");
|
die("Failed to allocate image.");
|
||||||
}
|
}
|
||||||
|
|
||||||
keyframe_interval = strtol(keyframe_interval_arg, NULL, 0);
|
keyframe_interval = strtol(keyframe_interval_arg, NULL, 0);
|
||||||
if (keyframe_interval < 0)
|
if (keyframe_interval < 0) die("Invalid keyframe interval value.");
|
||||||
die("Invalid keyframe interval value.");
|
|
||||||
|
|
||||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||||
|
|
||||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||||
if (res)
|
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||||
die_codec(&codec, "Failed to get default codec config.");
|
|
||||||
|
|
||||||
cfg.g_w = info.frame_width;
|
cfg.g_w = info.frame_width;
|
||||||
cfg.g_h = info.frame_height;
|
cfg.g_h = info.frame_height;
|
||||||
@@ -223,8 +212,7 @@ int main(int argc, char **argv) {
|
|||||||
cfg.g_error_resilient = strtol(argv[7], NULL, 0);
|
cfg.g_error_resilient = strtol(argv[7], NULL, 0);
|
||||||
|
|
||||||
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
|
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
|
||||||
if (!writer)
|
if (!writer) die("Failed to open %s for writing.", outfile_arg);
|
||||||
die("Failed to open %s for writing.", outfile_arg);
|
|
||||||
|
|
||||||
if (!(infile = fopen(infile_arg, "rb")))
|
if (!(infile = fopen(infile_arg, "rb")))
|
||||||
die("Failed to open %s for reading.", infile_arg);
|
die("Failed to open %s for reading.", infile_arg);
|
||||||
@@ -239,20 +227,19 @@ int main(int argc, char **argv) {
|
|||||||
flags |= VPX_EFLAG_FORCE_KF;
|
flags |= VPX_EFLAG_FORCE_KF;
|
||||||
encode_frame(&codec, &raw, frame_count++, flags, writer);
|
encode_frame(&codec, &raw, frame_count++, flags, writer);
|
||||||
frames_encoded++;
|
frames_encoded++;
|
||||||
if (max_frames > 0 && frames_encoded >= max_frames)
|
if (max_frames > 0 && frames_encoded >= max_frames) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush encoder.
|
// Flush encoder.
|
||||||
while (encode_frame(&codec, NULL, -1, 0, writer)) {};
|
while (encode_frame(&codec, NULL, -1, 0, writer)) {
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
printf("Processed %d frames.\n", frame_count);
|
printf("Processed %d frames.\n", frame_count);
|
||||||
|
|
||||||
vpx_img_free(&raw);
|
vpx_img_free(&raw);
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
||||||
die_codec(&codec, "Failed to destroy codec.");
|
|
||||||
|
|
||||||
vpx_video_writer_close(writer);
|
vpx_video_writer_close(writer);
|
||||||
|
|
||||||
|
@@ -61,25 +61,21 @@ static const char *exec_name;
|
|||||||
void usage_exit(void) {
|
void usage_exit(void) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: %s <codec> <width> <height> <infile> <outfile> "
|
"Usage: %s <codec> <width> <height> <infile> <outfile> "
|
||||||
"<frame limit>\n",
|
"<frame limit>\n",
|
||||||
exec_name);
|
exec_name);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_frame_stats(vpx_codec_ctx_t *ctx,
|
static int get_frame_stats(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
|
||||||
const vpx_image_t *img,
|
vpx_codec_pts_t pts, unsigned int duration,
|
||||||
vpx_codec_pts_t pts,
|
vpx_enc_frame_flags_t flags, unsigned int deadline,
|
||||||
unsigned int duration,
|
|
||||||
vpx_enc_frame_flags_t flags,
|
|
||||||
unsigned int deadline,
|
|
||||||
vpx_fixed_buf_t *stats) {
|
vpx_fixed_buf_t *stats) {
|
||||||
int got_pkts = 0;
|
int got_pkts = 0;
|
||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
const vpx_codec_cx_pkt_t *pkt = NULL;
|
const vpx_codec_cx_pkt_t *pkt = NULL;
|
||||||
const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags,
|
const vpx_codec_err_t res =
|
||||||
deadline);
|
vpx_codec_encode(ctx, img, pts, duration, flags, deadline);
|
||||||
if (res != VPX_CODEC_OK)
|
if (res != VPX_CODEC_OK) die_codec(ctx, "Failed to get frame stats.");
|
||||||
die_codec(ctx, "Failed to get frame stats.");
|
|
||||||
|
|
||||||
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
|
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
|
||||||
got_pkts = 1;
|
got_pkts = 1;
|
||||||
@@ -96,20 +92,16 @@ static int get_frame_stats(vpx_codec_ctx_t *ctx,
|
|||||||
return got_pkts;
|
return got_pkts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int encode_frame(vpx_codec_ctx_t *ctx,
|
static int encode_frame(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
|
||||||
const vpx_image_t *img,
|
vpx_codec_pts_t pts, unsigned int duration,
|
||||||
vpx_codec_pts_t pts,
|
vpx_enc_frame_flags_t flags, unsigned int deadline,
|
||||||
unsigned int duration,
|
|
||||||
vpx_enc_frame_flags_t flags,
|
|
||||||
unsigned int deadline,
|
|
||||||
VpxVideoWriter *writer) {
|
VpxVideoWriter *writer) {
|
||||||
int got_pkts = 0;
|
int got_pkts = 0;
|
||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
const vpx_codec_cx_pkt_t *pkt = NULL;
|
const vpx_codec_cx_pkt_t *pkt = NULL;
|
||||||
const vpx_codec_err_t res = vpx_codec_encode(ctx, img, pts, duration, flags,
|
const vpx_codec_err_t res =
|
||||||
deadline);
|
vpx_codec_encode(ctx, img, pts, duration, flags, deadline);
|
||||||
if (res != VPX_CODEC_OK)
|
if (res != VPX_CODEC_OK) die_codec(ctx, "Failed to encode frame.");
|
||||||
die_codec(ctx, "Failed to encode frame.");
|
|
||||||
|
|
||||||
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
|
while ((pkt = vpx_codec_get_cx_data(ctx, &iter)) != NULL) {
|
||||||
got_pkts = 1;
|
got_pkts = 1;
|
||||||
@@ -117,8 +109,8 @@ static int encode_frame(vpx_codec_ctx_t *ctx,
|
|||||||
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
||||||
|
|
||||||
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
|
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
|
||||||
pkt->data.frame.sz,
|
pkt->data.frame.sz,
|
||||||
pkt->data.frame.pts))
|
pkt->data.frame.pts))
|
||||||
die_codec(ctx, "Failed to write compressed frame.");
|
die_codec(ctx, "Failed to write compressed frame.");
|
||||||
printf(keyframe ? "K" : ".");
|
printf(keyframe ? "K" : ".");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -128,14 +120,12 @@ static int encode_frame(vpx_codec_ctx_t *ctx,
|
|||||||
return got_pkts;
|
return got_pkts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static vpx_fixed_buf_t pass0(vpx_image_t *raw,
|
static vpx_fixed_buf_t pass0(vpx_image_t *raw, FILE *infile,
|
||||||
FILE *infile,
|
|
||||||
const VpxInterface *encoder,
|
const VpxInterface *encoder,
|
||||||
const vpx_codec_enc_cfg_t *cfg,
|
const vpx_codec_enc_cfg_t *cfg, int max_frames) {
|
||||||
int max_frames) {
|
|
||||||
vpx_codec_ctx_t codec;
|
vpx_codec_ctx_t codec;
|
||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
vpx_fixed_buf_t stats = {NULL, 0};
|
vpx_fixed_buf_t stats = { NULL, 0 };
|
||||||
|
|
||||||
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
|
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
|
||||||
die_codec(&codec, "Failed to initialize encoder");
|
die_codec(&codec, "Failed to initialize encoder");
|
||||||
@@ -145,40 +135,33 @@ static vpx_fixed_buf_t pass0(vpx_image_t *raw,
|
|||||||
++frame_count;
|
++frame_count;
|
||||||
get_frame_stats(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY,
|
get_frame_stats(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY,
|
||||||
&stats);
|
&stats);
|
||||||
if (max_frames > 0 && frame_count >= max_frames)
|
if (max_frames > 0 && frame_count >= max_frames) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush encoder.
|
// Flush encoder.
|
||||||
while (get_frame_stats(&codec, NULL, frame_count, 1, 0,
|
while (get_frame_stats(&codec, NULL, frame_count, 1, 0, VPX_DL_GOOD_QUALITY,
|
||||||
VPX_DL_GOOD_QUALITY, &stats)) {}
|
&stats)) {
|
||||||
|
}
|
||||||
|
|
||||||
printf("Pass 0 complete. Processed %d frames.\n", frame_count);
|
printf("Pass 0 complete. Processed %d frames.\n", frame_count);
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
||||||
die_codec(&codec, "Failed to destroy codec.");
|
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pass1(vpx_image_t *raw,
|
static void pass1(vpx_image_t *raw, FILE *infile, const char *outfile_name,
|
||||||
FILE *infile,
|
const VpxInterface *encoder, const vpx_codec_enc_cfg_t *cfg,
|
||||||
const char *outfile_name,
|
|
||||||
const VpxInterface *encoder,
|
|
||||||
const vpx_codec_enc_cfg_t *cfg,
|
|
||||||
int max_frames) {
|
int max_frames) {
|
||||||
VpxVideoInfo info = {
|
VpxVideoInfo info = { encoder->fourcc,
|
||||||
encoder->fourcc,
|
cfg->g_w,
|
||||||
cfg->g_w,
|
cfg->g_h,
|
||||||
cfg->g_h,
|
{ cfg->g_timebase.num, cfg->g_timebase.den } };
|
||||||
{cfg->g_timebase.num, cfg->g_timebase.den}
|
|
||||||
};
|
|
||||||
VpxVideoWriter *writer = NULL;
|
VpxVideoWriter *writer = NULL;
|
||||||
vpx_codec_ctx_t codec;
|
vpx_codec_ctx_t codec;
|
||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
|
|
||||||
writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info);
|
writer = vpx_video_writer_open(outfile_name, kContainerIVF, &info);
|
||||||
if (!writer)
|
if (!writer) die("Failed to open %s for writing", outfile_name);
|
||||||
die("Failed to open %s for writing", outfile_name);
|
|
||||||
|
|
||||||
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
|
if (vpx_codec_enc_init(&codec, encoder->codec_interface(), cfg, 0))
|
||||||
die_codec(&codec, "Failed to initialize encoder");
|
die_codec(&codec, "Failed to initialize encoder");
|
||||||
@@ -188,17 +171,16 @@ static void pass1(vpx_image_t *raw,
|
|||||||
++frame_count;
|
++frame_count;
|
||||||
encode_frame(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, writer);
|
encode_frame(&codec, raw, frame_count, 1, 0, VPX_DL_GOOD_QUALITY, writer);
|
||||||
|
|
||||||
if (max_frames > 0 && frame_count >= max_frames)
|
if (max_frames > 0 && frame_count >= max_frames) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush encoder.
|
// Flush encoder.
|
||||||
while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_GOOD_QUALITY, writer)) {}
|
while (encode_frame(&codec, NULL, -1, 1, 0, VPX_DL_GOOD_QUALITY, writer)) {
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if (vpx_codec_destroy(&codec))
|
if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
||||||
die_codec(&codec, "Failed to destroy codec.");
|
|
||||||
|
|
||||||
vpx_video_writer_close(writer);
|
vpx_video_writer_close(writer);
|
||||||
|
|
||||||
@@ -215,8 +197,8 @@ int main(int argc, char **argv) {
|
|||||||
vpx_fixed_buf_t stats;
|
vpx_fixed_buf_t stats;
|
||||||
|
|
||||||
const VpxInterface *encoder = NULL;
|
const VpxInterface *encoder = NULL;
|
||||||
const int fps = 30; // TODO(dkovalev) add command line argument
|
const int fps = 30; // TODO(dkovalev) add command line argument
|
||||||
const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
|
const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
|
||||||
const char *const codec_arg = argv[1];
|
const char *const codec_arg = argv[1];
|
||||||
const char *const width_arg = argv[2];
|
const char *const width_arg = argv[2];
|
||||||
const char *const height_arg = argv[3];
|
const char *const height_arg = argv[3];
|
||||||
@@ -225,19 +207,17 @@ int main(int argc, char **argv) {
|
|||||||
int max_frames = 0;
|
int max_frames = 0;
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
|
|
||||||
if (argc != 7)
|
if (argc != 7) die("Invalid number of arguments.");
|
||||||
die("Invalid number of arguments.");
|
|
||||||
|
|
||||||
max_frames = strtol(argv[6], NULL, 0);
|
max_frames = strtol(argv[6], NULL, 0);
|
||||||
|
|
||||||
encoder = get_vpx_encoder_by_name(codec_arg);
|
encoder = get_vpx_encoder_by_name(codec_arg);
|
||||||
if (!encoder)
|
if (!encoder) die("Unsupported codec.");
|
||||||
die("Unsupported codec.");
|
|
||||||
|
|
||||||
w = strtol(width_arg, NULL, 0);
|
w = strtol(width_arg, NULL, 0);
|
||||||
h = strtol(height_arg, NULL, 0);
|
h = strtol(height_arg, NULL, 0);
|
||||||
|
|
||||||
if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
|
if (w <= 0 || h <= 0 || (w % 2) != 0 || (h % 2) != 0)
|
||||||
die("Invalid frame size: %dx%d", w, h);
|
die("Invalid frame size: %dx%d", w, h);
|
||||||
|
|
||||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, w, h, 1))
|
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, w, h, 1))
|
||||||
@@ -247,8 +227,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||||
if (res)
|
if (res) die_codec(&codec, "Failed to get default codec config.");
|
||||||
die_codec(&codec, "Failed to get default codec config.");
|
|
||||||
|
|
||||||
cfg.g_w = w;
|
cfg.g_w = w;
|
||||||
cfg.g_h = h;
|
cfg.g_h = h;
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// VP10 Set Reference Frame
|
// VP10 Set Reference Frame
|
||||||
// ============================
|
// ============================
|
||||||
//
|
//
|
||||||
@@ -61,7 +60,8 @@
|
|||||||
static const char *exec_name;
|
static const char *exec_name;
|
||||||
|
|
||||||
void usage_exit() {
|
void usage_exit() {
|
||||||
fprintf(stderr, "Usage: %s <codec> <width> <height> <infile> <outfile> "
|
fprintf(stderr,
|
||||||
|
"Usage: %s <codec> <width> <height> <infile> <outfile> "
|
||||||
"<frame> <limit(optional)>\n",
|
"<frame> <limit(optional)>\n",
|
||||||
exec_name);
|
exec_name);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -70,8 +70,7 @@ void usage_exit() {
|
|||||||
static int compare_img(const vpx_image_t *const img1,
|
static int compare_img(const vpx_image_t *const img1,
|
||||||
const vpx_image_t *const img2) {
|
const vpx_image_t *const img2) {
|
||||||
uint32_t l_w = img1->d_w;
|
uint32_t l_w = img1->d_w;
|
||||||
uint32_t c_w =
|
uint32_t c_w = (img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift;
|
||||||
(img1->d_w + img1->x_chroma_shift) >> img1->x_chroma_shift;
|
|
||||||
const uint32_t c_h =
|
const uint32_t c_h =
|
||||||
(img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift;
|
(img1->d_h + img1->y_chroma_shift) >> img1->y_chroma_shift;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
@@ -99,10 +98,10 @@ static int compare_img(const vpx_image_t *const img1,
|
|||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define mmin(a, b) ((a) < (b) ? (a) : (b))
|
#define mmin(a, b) ((a) < (b) ? (a) : (b))
|
||||||
static void find_mismatch(const vpx_image_t *const img1,
|
static void find_mismatch(const vpx_image_t *const img1,
|
||||||
const vpx_image_t *const img2,
|
const vpx_image_t *const img2, int yloc[4],
|
||||||
int yloc[4], int uloc[4], int vloc[4]) {
|
int uloc[4], int vloc[4]) {
|
||||||
const uint32_t bsize = 64;
|
const uint32_t bsize = 64;
|
||||||
const uint32_t bsizey = bsize >> img1->y_chroma_shift;
|
const uint32_t bsizey = bsize >> img1->y_chroma_shift;
|
||||||
const uint32_t bsizex = bsize >> img1->x_chroma_shift;
|
const uint32_t bsizex = bsize >> img1->x_chroma_shift;
|
||||||
@@ -190,21 +189,18 @@ static void find_mismatch(const vpx_image_t *const img1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testing_decode(vpx_codec_ctx_t *encoder,
|
static void testing_decode(vpx_codec_ctx_t *encoder, vpx_codec_ctx_t *decoder,
|
||||||
vpx_codec_ctx_t *decoder,
|
vpx_codec_enc_cfg_t *cfg, unsigned int frame_out,
|
||||||
vpx_codec_enc_cfg_t *cfg,
|
|
||||||
unsigned int frame_out,
|
|
||||||
int *mismatch_seen) {
|
int *mismatch_seen) {
|
||||||
vpx_image_t enc_img, dec_img;
|
vpx_image_t enc_img, dec_img;
|
||||||
struct vp9_ref_frame ref_enc, ref_dec;
|
struct vp9_ref_frame ref_enc, ref_dec;
|
||||||
|
|
||||||
if (*mismatch_seen)
|
if (*mismatch_seen) return;
|
||||||
return;
|
|
||||||
|
|
||||||
ref_enc.idx = 0;
|
ref_enc.idx = 0;
|
||||||
ref_dec.idx = 0;
|
ref_dec.idx = 0;
|
||||||
if (vpx_codec_control(encoder, VP9_GET_REFERENCE, &ref_enc))
|
if (vpx_codec_control(encoder, VP9_GET_REFERENCE, &ref_enc))
|
||||||
die_codec(encoder, "Failed to get encoder reference frame");
|
die_codec(encoder, "Failed to get encoder reference frame");
|
||||||
enc_img = ref_enc.img;
|
enc_img = ref_enc.img;
|
||||||
if (vpx_codec_control(decoder, VP9_GET_REFERENCE, &ref_dec))
|
if (vpx_codec_control(decoder, VP9_GET_REFERENCE, &ref_dec))
|
||||||
die_codec(decoder, "Failed to get decoder reference frame");
|
die_codec(decoder, "Failed to get decoder reference frame");
|
||||||
@@ -216,37 +212,31 @@ static void testing_decode(vpx_codec_ctx_t *encoder,
|
|||||||
*mismatch_seen = 1;
|
*mismatch_seen = 1;
|
||||||
|
|
||||||
find_mismatch(&enc_img, &dec_img, y, u, v);
|
find_mismatch(&enc_img, &dec_img, y, u, v);
|
||||||
printf("Encode/decode mismatch on frame %d at"
|
printf(
|
||||||
" Y[%d, %d] {%d/%d},"
|
"Encode/decode mismatch on frame %d at"
|
||||||
" U[%d, %d] {%d/%d},"
|
" Y[%d, %d] {%d/%d},"
|
||||||
" V[%d, %d] {%d/%d}",
|
" U[%d, %d] {%d/%d},"
|
||||||
frame_out,
|
" V[%d, %d] {%d/%d}",
|
||||||
y[0], y[1], y[2], y[3],
|
frame_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0], v[1],
|
||||||
u[0], u[1], u[2], u[3],
|
v[2], v[3]);
|
||||||
v[0], v[1], v[2], v[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vpx_img_free(&enc_img);
|
vpx_img_free(&enc_img);
|
||||||
vpx_img_free(&dec_img);
|
vpx_img_free(&dec_img);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int encode_frame(vpx_codec_ctx_t *ecodec,
|
static int encode_frame(vpx_codec_ctx_t *ecodec, vpx_codec_enc_cfg_t *cfg,
|
||||||
vpx_codec_enc_cfg_t *cfg,
|
vpx_image_t *img, unsigned int frame_in,
|
||||||
vpx_image_t *img,
|
VpxVideoWriter *writer, int test_decode,
|
||||||
unsigned int frame_in,
|
vpx_codec_ctx_t *dcodec, unsigned int *frame_out,
|
||||||
VpxVideoWriter *writer,
|
|
||||||
int test_decode,
|
|
||||||
vpx_codec_ctx_t *dcodec,
|
|
||||||
unsigned int *frame_out,
|
|
||||||
int *mismatch_seen) {
|
int *mismatch_seen) {
|
||||||
int got_pkts = 0;
|
int got_pkts = 0;
|
||||||
vpx_codec_iter_t iter = NULL;
|
vpx_codec_iter_t iter = NULL;
|
||||||
const vpx_codec_cx_pkt_t *pkt = NULL;
|
const vpx_codec_cx_pkt_t *pkt = NULL;
|
||||||
int got_data;
|
int got_data;
|
||||||
const vpx_codec_err_t res = vpx_codec_encode(ecodec, img, frame_in, 1,
|
const vpx_codec_err_t res =
|
||||||
0, VPX_DL_GOOD_QUALITY);
|
vpx_codec_encode(ecodec, img, frame_in, 1, 0, VPX_DL_GOOD_QUALITY);
|
||||||
if (res != VPX_CODEC_OK)
|
if (res != VPX_CODEC_OK) die_codec(ecodec, "Failed to encode frame");
|
||||||
die_codec(ecodec, "Failed to encode frame");
|
|
||||||
|
|
||||||
got_data = 0;
|
got_data = 0;
|
||||||
|
|
||||||
@@ -257,11 +247,10 @@ static int encode_frame(vpx_codec_ctx_t *ecodec,
|
|||||||
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
|
||||||
|
|
||||||
if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) {
|
if (!(pkt->data.frame.flags & VPX_FRAME_IS_FRAGMENT)) {
|
||||||
*frame_out += 1;
|
*frame_out += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vpx_video_writer_write_frame(writer,
|
if (!vpx_video_writer_write_frame(writer, pkt->data.frame.buf,
|
||||||
pkt->data.frame.buf,
|
|
||||||
pkt->data.frame.sz,
|
pkt->data.frame.sz,
|
||||||
pkt->data.frame.pts)) {
|
pkt->data.frame.pts)) {
|
||||||
die_codec(ecodec, "Failed to write compressed frame");
|
die_codec(ecodec, "Failed to write compressed frame");
|
||||||
@@ -290,12 +279,12 @@ static int encode_frame(vpx_codec_ctx_t *ecodec,
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
FILE *infile = NULL;
|
FILE *infile = NULL;
|
||||||
// Encoder
|
// Encoder
|
||||||
vpx_codec_ctx_t ecodec = {0};
|
vpx_codec_ctx_t ecodec = { 0 };
|
||||||
vpx_codec_enc_cfg_t cfg = {0};
|
vpx_codec_enc_cfg_t cfg = { 0 };
|
||||||
unsigned int frame_in = 0;
|
unsigned int frame_in = 0;
|
||||||
vpx_image_t raw;
|
vpx_image_t raw;
|
||||||
vpx_codec_err_t res;
|
vpx_codec_err_t res;
|
||||||
VpxVideoInfo info = {0};
|
VpxVideoInfo info = { 0 };
|
||||||
VpxVideoWriter *writer = NULL;
|
VpxVideoWriter *writer = NULL;
|
||||||
const VpxInterface *encoder = NULL;
|
const VpxInterface *encoder = NULL;
|
||||||
|
|
||||||
@@ -320,8 +309,7 @@ int main(int argc, char **argv) {
|
|||||||
unsigned int limit = 0;
|
unsigned int limit = 0;
|
||||||
exec_name = argv[0];
|
exec_name = argv[0];
|
||||||
|
|
||||||
if (argc < 7)
|
if (argc < 7) die("Invalid number of arguments");
|
||||||
die("Invalid number of arguments");
|
|
||||||
|
|
||||||
codec_arg = argv[1];
|
codec_arg = argv[1];
|
||||||
width_arg = argv[2];
|
width_arg = argv[2];
|
||||||
@@ -330,15 +318,13 @@ int main(int argc, char **argv) {
|
|||||||
outfile_arg = argv[5];
|
outfile_arg = argv[5];
|
||||||
|
|
||||||
encoder = get_vpx_encoder_by_name(codec_arg);
|
encoder = get_vpx_encoder_by_name(codec_arg);
|
||||||
if (!encoder)
|
if (!encoder) die("Unsupported codec.");
|
||||||
die("Unsupported codec.");
|
|
||||||
|
|
||||||
update_frame_num = atoi(argv[6]);
|
update_frame_num = atoi(argv[6]);
|
||||||
// In VP10, the reference buffers (cm->buffer_pool->frame_bufs[i].buf) are
|
// In VP10, the reference buffers (cm->buffer_pool->frame_bufs[i].buf) are
|
||||||
// allocated while calling vpx_codec_encode(), thus, setting reference for
|
// allocated while calling vpx_codec_encode(), thus, setting reference for
|
||||||
// 1st frame isn't supported.
|
// 1st frame isn't supported.
|
||||||
if (update_frame_num <= 1)
|
if (update_frame_num <= 1) die("Couldn't parse frame number '%s'\n", argv[6]);
|
||||||
die("Couldn't parse frame number '%s'\n", argv[6]);
|
|
||||||
|
|
||||||
if (argc > 7) {
|
if (argc > 7) {
|
||||||
limit = atoi(argv[7]);
|
limit = atoi(argv[7]);
|
||||||
@@ -352,23 +338,20 @@ int main(int argc, char **argv) {
|
|||||||
info.time_base.numerator = 1;
|
info.time_base.numerator = 1;
|
||||||
info.time_base.denominator = fps;
|
info.time_base.denominator = fps;
|
||||||
|
|
||||||
if (info.frame_width <= 0 ||
|
if (info.frame_width <= 0 || info.frame_height <= 0 ||
|
||||||
info.frame_height <= 0 ||
|
(info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
|
||||||
(info.frame_width % 2) != 0 ||
|
|
||||||
(info.frame_height % 2) != 0) {
|
|
||||||
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
|
||||||
info.frame_height, 1)) {
|
info.frame_height, 1)) {
|
||||||
die("Failed to allocate image.");
|
die("Failed to allocate image.");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
printf("Using %s\n", vpx_codec_iface_name(encoder->codec_interface()));
|
||||||
|
|
||||||
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
res = vpx_codec_enc_config_default(encoder->codec_interface(), &cfg, 0);
|
||||||
if (res)
|
if (res) die_codec(&ecodec, "Failed to get default codec config.");
|
||||||
die_codec(&ecodec, "Failed to get default codec config.");
|
|
||||||
|
|
||||||
cfg.g_w = info.frame_width;
|
cfg.g_w = info.frame_width;
|
||||||
cfg.g_h = info.frame_height;
|
cfg.g_h = info.frame_height;
|
||||||
@@ -378,8 +361,7 @@ int main(int argc, char **argv) {
|
|||||||
cfg.g_lag_in_frames = 3;
|
cfg.g_lag_in_frames = 3;
|
||||||
|
|
||||||
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
|
writer = vpx_video_writer_open(outfile_arg, kContainerIVF, &info);
|
||||||
if (!writer)
|
if (!writer) die("Failed to open %s for writing.", outfile_arg);
|
||||||
die("Failed to open %s for writing.", outfile_arg);
|
|
||||||
|
|
||||||
if (!(infile = fopen(infile_arg, "rb")))
|
if (!(infile = fopen(infile_arg, "rb")))
|
||||||
die("Failed to open %s for reading.", infile_arg);
|
die("Failed to open %s for reading.", infile_arg);
|
||||||
@@ -392,15 +374,14 @@ int main(int argc, char **argv) {
|
|||||||
die_codec(&ecodec, "Failed to set enable auto alt ref");
|
die_codec(&ecodec, "Failed to set enable auto alt ref");
|
||||||
|
|
||||||
if (test_decode) {
|
if (test_decode) {
|
||||||
const VpxInterface *decoder = get_vpx_decoder_by_name(codec_arg);
|
const VpxInterface *decoder = get_vpx_decoder_by_name(codec_arg);
|
||||||
if (vpx_codec_dec_init(&dcodec, decoder->codec_interface(), NULL, 0))
|
if (vpx_codec_dec_init(&dcodec, decoder->codec_interface(), NULL, 0))
|
||||||
die_codec(&dcodec, "Failed to initialize decoder.");
|
die_codec(&dcodec, "Failed to initialize decoder.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode frames.
|
// Encode frames.
|
||||||
while (vpx_img_read(&raw, infile)) {
|
while (vpx_img_read(&raw, infile)) {
|
||||||
if (limit && frame_in >= limit)
|
if (limit && frame_in >= limit) break;
|
||||||
break;
|
|
||||||
if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
|
if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
|
||||||
vpx_ref_frame_t ref;
|
vpx_ref_frame_t ref;
|
||||||
ref.frame_type = VP8_LAST_FRAME;
|
ref.frame_type = VP8_LAST_FRAME;
|
||||||
@@ -418,17 +399,17 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encode_frame(&ecodec, &cfg, &raw, frame_in, writer, test_decode,
|
encode_frame(&ecodec, &cfg, &raw, frame_in, writer, test_decode, &dcodec,
|
||||||
&dcodec, &frame_out, &mismatch_seen);
|
&frame_out, &mismatch_seen);
|
||||||
frame_in++;
|
frame_in++;
|
||||||
if (mismatch_seen)
|
if (mismatch_seen) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush encoder.
|
// Flush encoder.
|
||||||
if (!mismatch_seen)
|
if (!mismatch_seen)
|
||||||
while (encode_frame(&ecodec, &cfg, NULL, frame_in, writer, test_decode,
|
while (encode_frame(&ecodec, &cfg, NULL, frame_in, writer, test_decode,
|
||||||
&dcodec, &frame_out, &mismatch_seen)) {}
|
&dcodec, &frame_out, &mismatch_seen)) {
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
|
Reference in New Issue
Block a user