ref: 4f8a30b116890f36fb83cbbe20c095e9ebdafccf
parent: 9e41de4d615907809cba089a5206a9155301285d
author: Dmitry Kovalev <[email protected]>
date: Thu Feb 6 09:20:58 EST 2014
Converting vpx_temporal_scalable_patterns to use VpxVideoWriter. Change-Id: I69e868295b9798ba1599a411926de0891680032f
--- a/examples.mk
+++ b/examples.mk
@@ -73,6 +73,8 @@
EXAMPLES-$(CONFIG_ENCODERS) += vpx_temporal_scalable_patterns.c
vpx_temporal_scalable_patterns.SRCS += ivfenc.c ivfenc.h
vpx_temporal_scalable_patterns.SRCS += tools_common.c tools_common.h
+vpx_temporal_scalable_patterns.SRCS += video_common.h
+vpx_temporal_scalable_patterns.SRCS += video_writer.h video_writer.c
vpx_temporal_scalable_patterns.GUID = B18C08F2-A439-4502-A78E-849BE3D60947
vpx_temporal_scalable_patterns.DESCRIPTION = Temporal Scalability Encoder
EXAMPLES-$(CONFIG_VP8_DECODER) += simple_decoder.c
--- a/examples/vpx_temporal_scalable_patterns.c
+++ b/examples/vpx_temporal_scalable_patterns.c
@@ -12,18 +12,17 @@
// encoding scheme based on temporal scalability for video applications
// that benefit from a scalable bitstream.
-#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define VPX_CODEC_DISABLE_COMPAT 1
-#include "./ivfenc.h"
-#include "./tools_common.h"
-#include "./vpx_config.h"
#include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h"
+#include "./tools_common.h"
+#include "./video_writer.h"
+
static const char *exec_name;
void usage_exit() {
@@ -341,7 +340,7 @@
}
int main(int argc, char **argv) {
- FILE *outfile[VPX_TS_MAX_LAYERS];
+ VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS];
vpx_codec_ctx_t codec;
vpx_codec_enc_cfg_t cfg;
int frame_cnt = 0;
@@ -378,7 +377,7 @@
if (strncmp(codec_type, "vp9", 3) == 0) {
#if CONFIG_VP9_ENCODER
interface = vpx_codec_vp9_cx;
- fourcc = 0x30395056;
+ fourcc = VP9_FOURCC;
#else
die("Encoder vp9 selected but not configured");
#endif
@@ -385,7 +384,7 @@
} else {
#if CONFIG_VP8_ENCODER
interface = vpx_codec_vp8_cx;
- fourcc = 0x30385056;
+ fourcc = VP8_FOURCC;
#else
die("Encoder vp8 selected but not configured");
#endif
@@ -427,7 +426,7 @@
cfg.g_timebase.den = strtol(argv[7], NULL, 0);
for (i = 9; i < 9 + mode_to_num_layers[layering_mode]; ++i) {
- cfg.ts_target_bitrate[i-9] = strtol(argv[i], NULL, 0);
+ cfg.ts_target_bitrate[i - 9] = strtol(argv[i], NULL, 0);
}
// Real time parameters.
@@ -466,11 +465,18 @@
// Open an output file for each stream.
for (i = 0; i < cfg.ts_number_layers; ++i) {
- char file_name[512];
+ char file_name[PATH_MAX];
+ VpxVideoInfo info;
+ info.codec_fourcc = fourcc;
+ info.frame_width = cfg.g_w;
+ info.frame_height = cfg.g_h;
+ info.time_base.numerator = cfg.g_timebase.num;
+ info.time_base.denominator = cfg.g_timebase.den;
+
snprintf(file_name, sizeof(file_name), "%s_%d.ivf", argv[2], i);
- if (!(outfile[i] = fopen(file_name, "wb")))
+ outfile[i] = vpx_video_writer_open(file_name, kContainerIVF, &info);
+ if (!outfile[i])
die("Failed to open %s for writing", file_name);
- ivf_write_file_header(outfile[i], &cfg, fourcc, 0);
}
// No spatial layers in this encoder.
cfg.ss_number_layers = 1;
@@ -520,9 +526,8 @@
case VPX_CODEC_CX_FRAME_PKT:
for (i = cfg.ts_layer_id[frame_cnt % cfg.ts_periodicity];
i < cfg.ts_number_layers; ++i) {
- ivf_write_frame_header(outfile[i], pts, pkt->data.frame.sz);
- (void) fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz,
- outfile[i]);
+ vpx_video_writer_write_frame(outfile[i], pkt->data.frame.buf,
+ pkt->data.frame.sz, pts);
++frames_in_layer[i];
}
break;
@@ -534,15 +539,13 @@
pts += frame_duration;
}
fclose(input_ctx.file);
- printf("Processed %d frames: \n", frame_cnt-1);
- if (vpx_codec_destroy(&codec)) {
+ printf("Processed %d frames: \n", frame_cnt - 1);
+ if (vpx_codec_destroy(&codec))
die_codec(&codec, "Failed to destroy codec");
- }
+
// Try to rewrite the output file headers with the actual frame count.
- for (i = 0; i < cfg.ts_number_layers; ++i) {
- if (!fseek(outfile[i], 0, SEEK_SET))
- ivf_write_file_header(outfile[i], &cfg, fourcc, frame_cnt);
- fclose(outfile[i]);
- }
+ for (i = 0; i < cfg.ts_number_layers; ++i)
+ vpx_video_writer_close(outfile[i]);
+
return EXIT_SUCCESS;
}