Commit 374eaf20 authored by Dmitry Kovalev's avatar Dmitry Kovalev

Flushing the encoder in simple_decoder example.

Change-Id: I39d78facc79a364cdc529b8cc4930d74f766d413
parent c00d88cd
......@@ -99,6 +99,33 @@ void usage_exit() {
exit(EXIT_FAILURE);
}
static void encode_frame(vpx_codec_ctx_t *codec,
vpx_image_t *img,
int frame_index,
VpxVideoWriter *writer) {
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
const vpx_codec_err_t res = vpx_codec_encode(codec, img, frame_index, 1, 0,
VPX_DL_GOOD_QUALITY);
if (res != VPX_CODEC_OK)
die_codec(codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer,
pkt->data.frame.buf,
pkt->data.frame.sz,
pkt->data.frame.pts)) {
die_codec(codec, "Failed to write compressed frame");
}
printf(keyframe ? "K" : ".");
fflush(stdout);
}
}
}
int main(int argc, char **argv) {
FILE *infile = NULL;
vpx_codec_ctx_t codec;
......@@ -166,30 +193,10 @@ int main(int argc, char **argv) {
if (vpx_codec_enc_init(&codec, encoder->interface(), &cfg, 0))
die_codec(&codec, "Failed to initialize encoder");
while (vpx_img_read(&raw, infile)) {
vpx_codec_iter_t iter = NULL;
const vpx_codec_cx_pkt_t *pkt = NULL;
++frame_count;
res = vpx_codec_encode(&codec, &raw, frame_count, 1, 0,
VPX_DL_GOOD_QUALITY);
if (res != VPX_CODEC_OK)
die_codec(&codec, "Failed to encode frame");
while ((pkt = vpx_codec_get_cx_data(&codec, &iter)) != NULL) {
if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
const int keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0;
if (!vpx_video_writer_write_frame(writer,
pkt->data.frame.buf,
pkt->data.frame.sz,
pkt->data.frame.pts))
die_codec(&codec, "Failed to write compressed frame.");
printf(keyframe ? "K" : ".");
fflush(stdout);
}
}
}
while (vpx_img_read(&raw, infile))
encode_frame(&codec, &raw, frame_count++, writer);
encode_frame(&codec, NULL, -1, writer); // flush the encoder
printf("\n");
fclose(infile);
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