Commit 8bfd01fe authored by Jim Bankoski's avatar Jim Bankoski Committed by James Bankoski

simple_encoder: make it so we can run it in tests.

Added a limit, resolving a todo and added a limit parameter so that we
can do a very simple fast encode in 1 pass.

Ported from : https://chromium-review.googlesource.com/#/c/343553/

Change-Id: I265cd912d970d560a0b00b86e6c7ec7b6fef1e7b
parent b591df89
......@@ -110,8 +110,8 @@ static const char *exec_name;
void usage_exit(void) {
fprintf(stderr,
"Usage: %s <codec> <width> <height> <infile> <outfile> "
"<keyframe-interval> [<error-resilient>]\nSee comments in "
"simple_encoder.c for more information.\n",
"<keyframe-interval> <error-resilient> <frames to encode>\n"
"See comments in simple_encoder.c for more information.\n",
exec_name);
exit(EXIT_FAILURE);
}
......@@ -143,6 +143,7 @@ static int encode_frame(aom_codec_ctx_t *codec, aom_image_t *img,
return got_pkts;
}
// TODO(tomfinegan): Improve command line parsing and add args for bitrate/fps.
int main(int argc, char **argv) {
FILE *infile = NULL;
aom_codec_ctx_t codec;
......@@ -153,12 +154,11 @@ int main(int argc, char **argv) {
AvxVideoInfo info = { 0 };
AvxVideoWriter *writer = NULL;
const AvxInterface *encoder = NULL;
const int fps = 30; // TODO(dkovalev) add command line argument
const int bitrate = 200; // kbit/s TODO(dkovalev) add command line argument
const int fps = 30;
const int bitrate = 200;
int keyframe_interval = 0;
// TODO(dkovalev): Add some simple command line parsing code to make the
// command line more flexible.
int max_frames = 0;
int frames_encoded = 0;
const char *codec_arg = NULL;
const char *width_arg = NULL;
const char *height_arg = NULL;
......@@ -168,7 +168,7 @@ int main(int argc, char **argv) {
exec_name = argv[0];
if (argc < 7) die("Invalid number of arguments");
if (argc != 9) die("Invalid number of arguments");
codec_arg = argv[1];
width_arg = argv[2];
......@@ -176,6 +176,7 @@ int main(int argc, char **argv) {
infile_arg = argv[4];
outfile_arg = argv[5];
keyframe_interval_arg = argv[6];
max_frames = strtol(argv[8], NULL, 0);
encoder = get_aom_encoder_by_name(codec_arg);
if (!encoder) die("Unsupported codec.");
......@@ -209,7 +210,7 @@ int main(int argc, char **argv) {
cfg.g_timebase.num = info.time_base.numerator;
cfg.g_timebase.den = info.time_base.denominator;
cfg.rc_target_bitrate = bitrate;
cfg.g_error_resilient = argc > 7 ? strtol(argv[7], NULL, 0) : 0;
cfg.g_error_resilient = strtol(argv[7], NULL, 0);
writer = aom_video_writer_open(outfile_arg, kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing.", outfile_arg);
......@@ -226,6 +227,8 @@ int main(int argc, char **argv) {
if (keyframe_interval > 0 && frame_count % keyframe_interval == 0)
flags |= AOM_EFLAG_FORCE_KF;
encode_frame(&codec, &raw, frame_count++, flags, writer);
frames_encoded++;
if (max_frames > 0 && frames_encoded >= max_frames) break;
}
// Flush encoder.
......
......@@ -35,28 +35,19 @@ simple_encoder() {
fi
eval "${AOM_TEST_PREFIX}" "${encoder}" "${codec}" "${YUV_RAW_INPUT_WIDTH}" \
"${YUV_RAW_INPUT_HEIGHT}" "${YUV_RAW_INPUT}" "${output_file}" 9999 \
"${YUV_RAW_INPUT_HEIGHT}" "${YUV_RAW_INPUT}" "${output_file}" 9999 0 5 \
${devnull}
[ -e "${output_file}" ] || return 1
}
simple_encoder_aom() {
if [ "$(aom_encode_available)" = "yes" ]; then
simple_encoder aom || return 1
fi
}
# TODO(tomfinegan): Add a frame limit param to simple_encoder and enable this
# test. AV1 is just too slow right now: This test takes 4m30s+ on a fast
# machine.
DISABLED_simple_encoder_av1() {
simple_encoder_av1() {
if [ "$(av1_encode_available)" = "yes" ]; then
simple_encoder av1 || return 1
fi
}
simple_encoder_tests="simple_encoder_aom
DISABLED_simple_encoder_av1"
simple_encoder_tests="simple_encoder_av1"
run_tests simple_encoder_verify_environment "${simple_encoder_tests}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment