Adding video reader/writer APIs.
Right now only IVF format is supported which is enough for example code.
Other formats like y4m, webm, raw yuv will be supported later.
Change-Id: I34c6f20731c1851947587ca5c589d7856b675164
diff --git a/examples/decode_to_md5.c b/examples/decode_to_md5.c
index bba2182..077513c 100644
--- a/examples/decode_to_md5.c
+++ b/examples/decode_to_md5.c
@@ -38,9 +38,9 @@
#include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h"
-#include "./ivfdec.h"
#include "./md5_utils.h"
#include "./tools_common.h"
+#include "./video_reader.h"
#include "./vpx_config.h"
static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) {
@@ -79,41 +79,42 @@
}
int main(int argc, char **argv) {
- FILE *infile, *outfile;
+ int frame_cnt = 0;
+ FILE *outfile = NULL;
vpx_codec_ctx_t codec;
- vpx_codec_iface_t *iface;
- int flags = 0, frame_cnt = 0;
- vpx_video_t *video;
+ vpx_codec_iface_t *iface = NULL;
+ VpxVideoReader *reader = NULL;
+ const VpxVideoInfo *info = NULL;
exec_name = argv[0];
if (argc != 3)
- die("Invalid number of arguments");
+ die("Invalid number of arguments.");
- if (!(infile = fopen(argv[1], "rb")))
- die("Failed to open %s for reading", argv[1]);
+ reader = vpx_video_reader_open(argv[1]);
+ if (!reader)
+ die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
- die("Failed to open %s for writing", argv[2]);
+ die("Failed to open %s for writing.", argv[2]);
- video = vpx_video_open_file(infile);
- if (!video)
- die("%s is not an IVF file.", argv[1]);
+ info = vpx_video_reader_get_info(reader);
- iface = get_codec_interface(vpx_video_get_fourcc(video));
+ iface = get_codec_interface(info->codec_fourcc);
if (!iface)
- die("Unknown FOURCC code.");
+ die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(iface));
- if (vpx_codec_dec_init(&codec, iface, NULL, flags))
+ if (vpx_codec_dec_init(&codec, iface, NULL, 0))
die_codec(&codec, "Failed to initialize decoder");
- while (vpx_video_read_frame(video)) {
+ while (vpx_video_reader_read_frame(reader)) {
vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL;
size_t frame_size = 0;
- const unsigned char *frame = vpx_video_get_frame(video, &frame_size);
+ const unsigned char *frame = vpx_video_reader_get_frame(reader,
+ &frame_size);
if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0))
die_codec(&codec, "Failed to decode frame");
@@ -129,11 +130,10 @@
printf("Processed %d frames.\n", frame_cnt);
if (vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec");
+ die_codec(&codec, "Failed to destroy codec.");
- vpx_video_close(video);
+ vpx_video_reader_close(reader);
fclose(outfile);
- fclose(infile);
return EXIT_SUCCESS;
}
diff --git a/examples/decode_with_drops.c b/examples/decode_with_drops.c
index 12686de..e8fc076 100644
--- a/examples/decode_with_drops.c
+++ b/examples/decode_with_drops.c
@@ -56,14 +56,13 @@
#include <stdlib.h>
#include <string.h>
-#include "./ivfdec.h"
-
#define VPX_CODEC_DISABLE_COMPAT 1
#include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h"
#include "./tools_common.h"
+#include "./video_reader.h"
#include "./vpx_config.h"
static const char *exec_name;
@@ -74,52 +73,55 @@
}
int main(int argc, char **argv) {
- FILE *infile, *outfile;
+ int frame_cnt = 0;
+ FILE *outfile = NULL;
vpx_codec_ctx_t codec;
- vpx_codec_iface_t *iface;
- int flags = 0, frame_cnt = 0;
- vpx_video_t *video;
- int n, m, is_range;
- char *nptr;
+ vpx_codec_iface_t *iface = NULL;
+ VpxVideoReader *reader = NULL;
+ const VpxVideoInfo *info = NULL;
+ int n = 0;
+ int m = 0;
+ int is_range = 0;
+ char *nptr = NULL;
exec_name = argv[0];
if (argc != 4)
- die("Invalid number of arguments");
+ die("Invalid number of arguments.");
- if (!(infile = fopen(argv[1], "rb")))
- die("Failed to open %s for reading", argv[1]);
+ reader = vpx_video_reader_open(argv[1]);
+ if (!reader)
+ die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
- die("Failed to open %s for writing", argv[2]);
+ die("Failed to open %s for writing.", argv[2]);
n = strtol(argv[3], &nptr, 0);
m = strtol(nptr + 1, NULL, 0);
is_range = (*nptr == '-');
if (!n || !m || (*nptr != '-' && *nptr != '/'))
- die("Couldn't parse pattern %s\n", argv[3]);
+ die("Couldn't parse pattern %s.\n", argv[3]);
- video = vpx_video_open_file(infile);
- if (!video)
- die("%s is not a supported input file.", argv[1]);
+ info = vpx_video_reader_get_info(reader);
- iface = get_codec_interface(vpx_video_get_fourcc(video));
+ iface = get_codec_interface(info->codec_fourcc);
if (!iface)
- die("Unknown FOURCC code.");
+ die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(iface));
- if (vpx_codec_dec_init(&codec, iface, NULL, flags))
- die_codec(&codec, "Failed to initialize decoder");
+ if (vpx_codec_dec_init(&codec, iface, NULL, 0))
+ die_codec(&codec, "Failed to initialize decoder.");
- while (vpx_video_read_frame(video)) {
+ while (vpx_video_reader_read_frame(reader)) {
vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL;
size_t frame_size = 0;
int skip;
- const unsigned char *frame = vpx_video_get_frame(video, &frame_size);
+ const unsigned char *frame = vpx_video_reader_get_frame(reader,
+ &frame_size);
if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0))
- die_codec(&codec, "Failed to decode frame");
+ die_codec(&codec, "Failed to decode frame.");
++frame_cnt;
@@ -140,15 +142,13 @@
printf("Processed %d frames.\n", frame_cnt);
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",
- vpx_video_get_width(video), vpx_video_get_height(video), argv[2]);
+ info->frame_width, info->frame_height, argv[2]);
- vpx_video_close(video);
-
+ vpx_video_reader_close(reader);
fclose(outfile);
- fclose(infile);
return EXIT_SUCCESS;
}
diff --git a/examples/postproc.c b/examples/postproc.c
index 4ec2d1f..7281f1e 100644
--- a/examples/postproc.c
+++ b/examples/postproc.c
@@ -43,14 +43,13 @@
#include <stdlib.h>
#include <string.h>
-#include "./ivfdec.h"
-
#define VPX_CODEC_DISABLE_COMPAT 1
#include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h"
#include "./tools_common.h"
+#include "./video_reader.h"
#include "./vpx_config.h"
static const char *exec_name;
@@ -61,35 +60,34 @@
}
int main(int argc, char **argv) {
- FILE *infile, *outfile;
- vpx_codec_ctx_t codec;
- vpx_codec_iface_t *iface;
int frame_cnt = 0;
- vpx_video_t *video;
+ FILE *outfile = NULL;
+ vpx_codec_ctx_t codec;
vpx_codec_err_t res;
+ vpx_codec_iface_t *iface = NULL;
+ VpxVideoReader *reader = NULL;
+ const VpxVideoInfo *info = NULL;
exec_name = argv[0];
if (argc != 3)
- die("Invalid number of arguments");
+ die("Invalid number of arguments.");
- if (!(infile = fopen(argv[1], "rb")))
- die("Failed to open %s for reading", argv[1]);
+ reader = vpx_video_reader_open(argv[1]);
+ if (!reader)
+ die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
die("Failed to open %s for writing", argv[2]);
- video = vpx_video_open_file(infile);
- if (!video)
- die("%s is not a supported input file.", argv[1]);
+ info = vpx_video_reader_get_info(reader);
- iface = get_codec_interface(vpx_video_get_fourcc(video));
+ iface = get_codec_interface(info->codec_fourcc);
if (!iface)
- die("Unknown FOURCC code.");
+ die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(iface));
-
res = vpx_codec_dec_init(&codec, iface, NULL, VPX_CODEC_USE_POSTPROC);
if (res == VPX_CODEC_INCAPABLE) {
printf("NOTICE: Postproc not supported.\n");
@@ -97,13 +95,14 @@
}
if (res)
- die_codec(&codec, "Failed to initialize decoder");
+ die_codec(&codec, "Failed to initialize decoder.");
- while (vpx_video_read_frame(video)) {
+ while (vpx_video_reader_read_frame(reader)) {
vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL;
size_t frame_size = 0;
- const unsigned char *frame = vpx_video_get_frame(video, &frame_size);
+ const unsigned char *frame = vpx_video_reader_get_frame(reader,
+ &frame_size);
++frame_cnt;
@@ -111,12 +110,12 @@
vp8_postproc_cfg_t pp = {0, 0, 0};
if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
- die_codec(&codec, "Failed to turn off postproc");
+ die_codec(&codec, "Failed to turn off postproc.");
} else if (frame_cnt % 30 == 16) {
vp8_postproc_cfg_t pp = {VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE,
4, 0};
if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
- die_codec(&codec, "Failed to turn on postproc");
+ die_codec(&codec, "Failed to turn on postproc.");
};
// Decode the frame with 15ms deadline
@@ -133,11 +132,10 @@
die_codec(&codec, "Failed to destroy codec");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
- vpx_video_get_width(video), vpx_video_get_height(video), argv[2]);
+ info->frame_width, info->frame_height, argv[2]);
- vpx_video_close(video);
+ vpx_video_reader_close(reader);
fclose(outfile);
- fclose(infile);
return EXIT_SUCCESS;
}
diff --git a/examples/simple_decoder.c b/examples/simple_decoder.c
index 23399f4..4dc9308 100644
--- a/examples/simple_decoder.c
+++ b/examples/simple_decoder.c
@@ -86,8 +86,8 @@
#include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h"
-#include "./ivfdec.h"
#include "./tools_common.h"
+#include "./video_reader.h"
#include "./vpx_config.h"
static const char *exec_name;
@@ -98,43 +98,44 @@
}
int main(int argc, char **argv) {
- FILE *infile, *outfile;
+ int frame_cnt = 0;
+ FILE *outfile = NULL;
vpx_codec_ctx_t codec;
- vpx_codec_iface_t *iface;
- int flags = 0, frame_cnt = 0;
- vpx_video_t *video;
+ vpx_codec_iface_t *iface = NULL;
+ VpxVideoReader *reader = NULL;
+ const VpxVideoInfo *info = NULL;
exec_name = argv[0];
if (argc != 3)
- die("Invalid number of arguments");
+ die("Invalid number of arguments.");
- if (!(infile = fopen(argv[1], "rb")))
- die("Failed to open %s for reading", argv[1]);
+ reader = vpx_video_reader_open(argv[1]);
+ if (!reader)
+ die("Failed to open %s for reading.", argv[1]);
if (!(outfile = fopen(argv[2], "wb")))
- die("Failed to open %s for writing", argv[2]);
+ die("Failed to open %s for writing.", argv[2]);
- video = vpx_video_open_file(infile);
- if (!video)
- die("%s is not an IVF file.", argv[1]);
+ info = vpx_video_reader_get_info(reader);
- iface = get_codec_interface(vpx_video_get_fourcc(video));
+ iface = get_codec_interface(info->codec_fourcc);
if (!iface)
- die("Unknown FOURCC code.");
+ die("Unknown input codec.");
printf("Using %s\n", vpx_codec_iface_name(iface));
- if (vpx_codec_dec_init(&codec, iface, NULL, flags))
- die_codec(&codec, "Failed to initialize decoder");
+ if (vpx_codec_dec_init(&codec, iface, NULL, 0))
+ die_codec(&codec, "Failed to initialize decoder.");
- while (vpx_video_read_frame(video)) {
+ while (vpx_video_reader_read_frame(reader)) {
vpx_codec_iter_t iter = NULL;
vpx_image_t *img = NULL;
size_t frame_size = 0;
- const unsigned char *frame = vpx_video_get_frame(video, &frame_size);
+ const unsigned char *frame = vpx_video_reader_get_frame(reader,
+ &frame_size);
if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0))
- die_codec(&codec, "Failed to decode frame");
+ die_codec(&codec, "Failed to decode frame.");
while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) {
vpx_img_write(img, outfile);
@@ -147,12 +148,11 @@
die_codec(&codec, "Failed to destroy codec");
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
- vpx_video_get_width(video), vpx_video_get_height(video), argv[2]);
+ info->frame_width, info->frame_height, argv[2]);
- vpx_video_close(video);
+ vpx_video_reader_close(reader);
fclose(outfile);
- fclose(infile);
return EXIT_SUCCESS;
}
diff --git a/examples/simple_encoder.c b/examples/simple_encoder.c
index e64a962..0ae012c 100644
--- a/examples/simple_encoder.c
+++ b/examples/simple_encoder.c
@@ -83,194 +83,131 @@
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
#include <string.h>
+
#define VPX_CODEC_DISABLE_COMPAT 1
-#include "vpx/vpx_encoder.h"
+
#include "vpx/vp8cx.h"
+#include "vpx/vpx_encoder.h"
+
+#include "./tools_common.h"
+#include "./video_writer.h"
+
#define interface (vpx_codec_vp8_cx())
-#define fourcc 0x30385056
-#define IVF_FILE_HDR_SZ (32)
-#define IVF_FRAME_HDR_SZ (12)
+static const char *exec_name;
-static void mem_put_le16(char *mem, unsigned int val) {
- mem[0] = val;
- mem[1] = val>>8;
-}
-
-static void mem_put_le32(char *mem, unsigned int val) {
- mem[0] = val;
- mem[1] = val>>8;
- mem[2] = val>>16;
- mem[3] = val>>24;
-}
-
-static void die(const char *fmt, ...) {
- va_list ap;
-
- va_start(ap, fmt);
- vprintf(fmt, ap);
- if(fmt[strlen(fmt)-1] != '\n')
- printf("\n");
- exit(EXIT_FAILURE);
-}
-
-static void die_codec(vpx_codec_ctx_t *ctx, const char *s) {
- const char *detail = vpx_codec_error_detail(ctx);
-
- printf("%s: %s\n", s, vpx_codec_error(ctx));
- if(detail)
- printf(" %s\n",detail);
- exit(EXIT_FAILURE);
+void usage_exit() {
+ fprintf(stderr, "Usage: %s <width> <height> <infile> <outfile>\n", exec_name);
+ exit(EXIT_FAILURE);
}
static int read_frame(FILE *f, vpx_image_t *img) {
- size_t nbytes, to_read;
- int res = 1;
-
- to_read = img->w*img->h*3/2;
- nbytes = fread(img->planes[0], 1, to_read, f);
- if(nbytes != to_read) {
- res = 0;
- if(nbytes > 0)
- printf("Warning: Read partial frame. Check your width & height!\n");
- }
- return res;
+ int res = 1;
+ size_t to_read = img->w * img->h * 3 / 2;
+ size_t nbytes = fread(img->planes[0], 1, to_read, f);
+ if (nbytes != to_read) {
+ res = 0;
+ if (nbytes > 0)
+ printf("Warning: Read partial frame. Check your width & height!\n");
+ }
+ return res;
}
-static void write_ivf_file_header(FILE *outfile,
- const vpx_codec_enc_cfg_t *cfg,
- int frame_cnt) {
- char header[32];
-
- if(cfg->g_pass != VPX_RC_ONE_PASS && cfg->g_pass != VPX_RC_LAST_PASS)
- return;
- header[0] = 'D';
- header[1] = 'K';
- header[2] = 'I';
- header[3] = 'F';
- mem_put_le16(header+4, 0); /* version */
- mem_put_le16(header+6, 32); /* headersize */
- mem_put_le32(header+8, fourcc); /* headersize */
- mem_put_le16(header+12, cfg->g_w); /* width */
- mem_put_le16(header+14, cfg->g_h); /* height */
- mem_put_le32(header+16, cfg->g_timebase.den); /* rate */
- mem_put_le32(header+20, cfg->g_timebase.num); /* scale */
- mem_put_le32(header+24, frame_cnt); /* length */
- mem_put_le32(header+28, 0); /* unused */
-
- (void) fwrite(header, 1, 32, outfile);
-}
-
-
-static void write_ivf_frame_header(FILE *outfile,
- const vpx_codec_cx_pkt_t *pkt)
-{
- char header[12];
- vpx_codec_pts_t pts;
-
- if(pkt->kind != VPX_CODEC_CX_FRAME_PKT)
- return;
-
- pts = pkt->data.frame.pts;
- mem_put_le32(header, pkt->data.frame.sz);
- mem_put_le32(header+4, pts&0xFFFFFFFF);
- mem_put_le32(header+8, pts >> 32);
-
- (void) fwrite(header, 1, 12, outfile);
+static int is_valid_dimension(int value) {
+ return value >= 16 && (value % 2 == 0);
}
int main(int argc, char **argv) {
- FILE *infile, *outfile;
- vpx_codec_ctx_t codec;
- vpx_codec_enc_cfg_t cfg;
- int frame_cnt = 0;
- vpx_image_t raw;
- vpx_codec_err_t res;
- long width;
- long height;
- int frame_avail;
- int got_data;
- int flags = 0;
+ FILE *infile;
+ vpx_codec_ctx_t codec;
+ vpx_codec_enc_cfg_t cfg;
+ int frame_count = 0;
+ vpx_image_t raw;
+ vpx_codec_err_t res;
+ VpxVideoInfo info;
+ VpxVideoWriter *writer;
+ const int fps = 30; // TODO(dkovalev) add command line argument
+ const int bitrate = 100; // kbit/s TODO(dkovalev) add command line argument
- /* Open files */
- if(argc!=5)
- die("Usage: %s <width> <height> <infile> <outfile>\n", argv[0]);
- width = strtol(argv[1], NULL, 0);
- height = strtol(argv[2], NULL, 0);
- if(width < 16 || width%2 || height <16 || height%2)
- die("Invalid resolution: %ldx%ld", width, height);
- if(!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, width, height, 1))
- die("Faile to allocate image", width, height);
- if(!(outfile = fopen(argv[4], "wb")))
- die("Failed to open %s for writing", argv[4]);
+ exec_name = argv[0];
- printf("Using %s\n",vpx_codec_iface_name(interface));
+ if (argc != 5)
+ die("Invalid number of arguments");
- /* Populate encoder configuration */
- res = vpx_codec_enc_config_default(interface, &cfg, 0);
- if(res) {
- printf("Failed to get config: %s\n", vpx_codec_err_to_string(res));
- return EXIT_FAILURE;
+ info.codec_fourcc = VP8_FOURCC;
+ info.frame_width = strtol(argv[1], NULL, 0);
+ info.frame_height = strtol(argv[2], NULL, 0);
+ info.time_base.numerator = 1;
+ info.time_base.denominator = fps;
+
+ if (!is_valid_dimension(info.frame_width) ||
+ !is_valid_dimension(info.frame_height))
+ die("Invalid resolution: %dx%d", info.frame_width, info.frame_height);
+
+ if (!vpx_img_alloc(&raw, VPX_IMG_FMT_I420, info.frame_width,
+ info.frame_height, 1))
+ die("Failed to allocate image");
+
+ printf("Using %s\n", vpx_codec_iface_name(interface));
+
+ res = vpx_codec_enc_config_default(interface, &cfg, 0);
+ if (res) {
+ printf("Failed to get config: %s\n", vpx_codec_err_to_string(res));
+ return EXIT_FAILURE;
+ }
+
+ cfg.g_w = info.frame_width;
+ cfg.g_h = info.frame_height;
+ cfg.g_timebase.num = info.time_base.numerator;
+ cfg.g_timebase.den = info.time_base.denominator;
+ cfg.rc_target_bitrate = bitrate;
+
+ writer = vpx_video_writer_open(argv[4], kContainerIVF, &info);
+ if (!writer)
+ die("Failed to open %s for writing.", argv[4]);
+
+ // Open input file for this encoding pass
+ if (!(infile = fopen(argv[3], "rb")))
+ die("Failed to open %s for reading.", argv[3]);
+
+ // Initialize codec
+ if (vpx_codec_enc_init(&codec, interface, &cfg, 0))
+ die_codec(&codec, "Failed to initialize encoder");
+
+
+ while (read_frame(infile, &raw)) {
+ vpx_codec_iter_t iter = NULL;
+ const vpx_codec_cx_pkt_t *pkt = NULL;
+ 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");
+
+ ++frame_count;
+
+ 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" : ".");
+ }
}
+ }
+ printf("\n");
- /* Update the default configuration with our settings */
- cfg.rc_target_bitrate = width * height * cfg.rc_target_bitrate
- / cfg.g_w / cfg.g_h;
- cfg.g_w = width;
- cfg.g_h = height;
+ fclose(infile);
- write_ivf_file_header(outfile, &cfg, 0);
+ printf("Processed %d frames.\n", frame_count);
+ vpx_img_free(&raw);
+ if (vpx_codec_destroy(&codec))
+ die_codec(&codec, "Failed to destroy codec.");
+ vpx_video_writer_close(writer);
- /* Open input file for this encoding pass */
- if(!(infile = fopen(argv[3], "rb")))
- die("Failed to open %s for reading", argv[3]);
-
- /* Initialize codec */
- if(vpx_codec_enc_init(&codec, interface, &cfg, 0))
- die_codec(&codec, "Failed to initialize encoder");
-
- frame_avail = 1;
- got_data = 0;
- while(frame_avail || got_data) {
- vpx_codec_iter_t iter = NULL;
- const vpx_codec_cx_pkt_t *pkt;
-
- frame_avail = read_frame(infile, &raw);
- if(vpx_codec_encode(&codec, frame_avail? &raw : NULL, frame_cnt,
- 1, flags, VPX_DL_REALTIME))
- die_codec(&codec, "Failed to encode frame");
- got_data = 0;
- while( (pkt = vpx_codec_get_cx_data(&codec, &iter)) ) {
- got_data = 1;
- switch(pkt->kind) {
- case VPX_CODEC_CX_FRAME_PKT:
- write_ivf_frame_header(outfile, pkt);
- (void) fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz,
- outfile);
- break;
- default:
- break;
- }
- printf(pkt->kind == VPX_CODEC_CX_FRAME_PKT
- && (pkt->data.frame.flags & VPX_FRAME_IS_KEY)? "K":".");
- fflush(stdout);
- }
- frame_cnt++;
- }
- printf("\n");
- fclose(infile);
-
- printf("Processed %d frames.\n",frame_cnt-1);
- vpx_img_free(&raw);
- if(vpx_codec_destroy(&codec))
- die_codec(&codec, "Failed to destroy codec");
-
- /* Try to rewrite the file header with the actual frame count */
- if(!fseek(outfile, 0, SEEK_SET))
- write_ivf_file_header(outfile, &cfg, frame_cnt-1);
- fclose(outfile);
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}