]> granicus.if.org Git - libvpx/commitdiff
vp8cx_set_ref: Flush encoder.
authorDmitry Kovalev <dkovalev@google.com>
Thu, 14 Aug 2014 17:28:00 +0000 (10:28 -0700)
committerDmitry Kovalev <dkovalev@google.com>
Fri, 15 Aug 2014 17:26:45 +0000 (10:26 -0700)
According to the current API spec we need to call vpx_codec_encode() until
vpx_codec_get_cx_data() returns NULL.

Change-Id: Ide0c531dc0d453df8ec1edb8acb894856d6cc22e

examples/vp8cx_set_ref.c

index 46a40cae68728c01d5cd09de77224db84d0d5b9a..5f3f0a3798e71baad9a040d1a918c1b079480f41 100644 (file)
@@ -65,10 +65,11 @@ void usage_exit() {
   exit(EXIT_FAILURE);
 }
 
-static void encode_frame(vpx_codec_ctx_t *codec,
-                         vpx_image_t *img,
-                         int frame_index,
-                         VpxVideoWriter *writer) {
+static int encode_frame(vpx_codec_ctx_t *codec,
+                        vpx_image_t *img,
+                        int frame_index,
+                        VpxVideoWriter *writer) {
+  int got_pkts = 0;
   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,
@@ -77,6 +78,8 @@ static void encode_frame(vpx_codec_ctx_t *codec,
     die_codec(codec, "Failed to encode frame");
 
   while ((pkt = vpx_codec_get_cx_data(codec, &iter)) != NULL) {
+    got_pkts = 1;
+
     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,
@@ -90,6 +93,8 @@ static void encode_frame(vpx_codec_ctx_t *codec,
       fflush(stdout);
     }
   }
+
+  return got_pkts;
 }
 
 int main(int argc, char **argv) {
@@ -160,6 +165,7 @@ int main(int argc, char **argv) {
   if (vpx_codec_enc_init(&codec, encoder->codec_interface(), &cfg, 0))
     die_codec(&codec, "Failed to initialize encoder");
 
+  // Encode frames.
   while (vpx_img_read(&raw, infile)) {
     if (frame_count + 1 == update_frame_num) {
       vpx_ref_frame_t ref;
@@ -171,7 +177,9 @@ int main(int argc, char **argv) {
 
     encode_frame(&codec, &raw, frame_count++, writer);
   }
-  encode_frame(&codec, NULL, -1, writer);
+
+  // Flush encoder.
+  while (encode_frame(&codec, NULL, -1, writer)) {};
 
   printf("\n");
   fclose(infile);