Commit 43a83a27 authored by Dmitry Kovalev's avatar Dmitry Kovalev Committed by Gerrit Code Review
Browse files

Merge "set_maps: Flush encoder."

parents c5bb9753 a8e674de
...@@ -125,10 +125,11 @@ static void unset_active_map(const vpx_codec_enc_cfg_t *cfg, ...@@ -125,10 +125,11 @@ 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 void 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 frame_index,
VpxVideoWriter *writer) { VpxVideoWriter *writer) {
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_codec_encode(codec, img, frame_index, 1, 0,
...@@ -137,6 +138,8 @@ static void encode_frame(vpx_codec_ctx_t *codec, ...@@ -137,6 +138,8 @@ static void encode_frame(vpx_codec_ctx_t *codec,
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;
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,
...@@ -150,6 +153,8 @@ static void encode_frame(vpx_codec_ctx_t *codec, ...@@ -150,6 +153,8 @@ static void encode_frame(vpx_codec_ctx_t *codec,
fflush(stdout); fflush(stdout);
} }
} }
return got_pkts;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
...@@ -217,6 +222,7 @@ int main(int argc, char **argv) { ...@@ -217,6 +222,7 @@ int main(int argc, char **argv) {
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");
// Encode frames.
while (vpx_img_read(&raw, infile)) { while (vpx_img_read(&raw, infile)) {
++frame_count; ++frame_count;
...@@ -230,7 +236,10 @@ int main(int argc, char **argv) { ...@@ -230,7 +236,10 @@ int main(int argc, char **argv) {
encode_frame(&codec, &raw, frame_count, writer); encode_frame(&codec, &raw, frame_count, writer);
} }
encode_frame(&codec, NULL, -1, writer);
// Flush encoder.
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);
......
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