2014-01-08 03:15:25 +04:00
|
|
|
/*
|
2016-03-24 21:38:32 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2014-01-08 03:15:25 +04:00
|
|
|
*
|
2016-03-24 21:38:32 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2014-01-08 03:15:25 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Decode With Drops Example
|
|
|
|
// =========================
|
|
|
|
//
|
|
|
|
// This is an example utility which drops a series of frames, as specified
|
|
|
|
// on the command line. This is useful for observing the error recovery
|
|
|
|
// features of the codec.
|
|
|
|
//
|
|
|
|
// Usage
|
|
|
|
// -----
|
|
|
|
// This example adds a single argument to the `simple_decoder` example,
|
|
|
|
// which specifies the range or pattern of frames to drop. The parameter is
|
|
|
|
// parsed as follows:
|
|
|
|
//
|
|
|
|
// Dropping A Range Of Frames
|
|
|
|
// --------------------------
|
|
|
|
// To drop a range of frames, specify the starting frame and the ending
|
|
|
|
// frame to drop, separated by a dash. The following command will drop
|
|
|
|
// frames 5 through 10 (base 1).
|
|
|
|
//
|
|
|
|
// $ ./decode_with_drops in.ivf out.i420 5-10
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Dropping A Pattern Of Frames
|
|
|
|
// ----------------------------
|
|
|
|
// To drop a pattern of frames, specify the number of frames to drop and
|
|
|
|
// the number of frames after which to repeat the pattern, separated by
|
|
|
|
// a forward-slash. The following command will drop 3 of 7 frames.
|
|
|
|
// Specifically, it will decode 4 frames, then drop 3 frames, and then
|
|
|
|
// repeat.
|
|
|
|
//
|
|
|
|
// $ ./decode_with_drops in.ivf out.i420 3/7
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Extra Variables
|
|
|
|
// ---------------
|
|
|
|
// This example maintains the pattern passed on the command line in the
|
|
|
|
// `n`, `m`, and `is_range` variables:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Making The Drop Decision
|
|
|
|
// ------------------------
|
|
|
|
// The example decides whether to drop the frame based on the current
|
|
|
|
// frame number, immediately before decoding the frame.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-01-28 23:25:24 +04:00
|
|
|
|
2016-03-26 02:04:42 +03:00
|
|
|
#include "aom/aomdx.h"
|
2016-03-25 22:11:05 +03:00
|
|
|
#include "aom/aom_decoder.h"
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2015-02-05 03:11:57 +03:00
|
|
|
#include "../tools_common.h"
|
|
|
|
#include "../video_reader.h"
|
2016-03-25 22:11:05 +03:00
|
|
|
#include "./aom_config.h"
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2014-01-28 23:25:24 +04:00
|
|
|
static const char *exec_name;
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2015-05-09 20:33:26 +03:00
|
|
|
void usage_exit(void) {
|
2014-01-28 23:25:24 +04:00
|
|
|
fprintf(stderr, "Usage: %s <infile> <outfile> <N-M|N/M>\n", exec_name);
|
|
|
|
exit(EXIT_FAILURE);
|
2014-01-08 03:15:25 +04:00
|
|
|
}
|
|
|
|
|
2014-01-28 23:25:24 +04:00
|
|
|
int main(int argc, char **argv) {
|
2014-02-06 06:34:46 +04:00
|
|
|
int frame_cnt = 0;
|
|
|
|
FILE *outfile = NULL;
|
2016-03-25 22:11:05 +03:00
|
|
|
aom_codec_ctx_t codec;
|
2016-03-30 00:27:56 +03:00
|
|
|
const AvxInterface *decoder = NULL;
|
|
|
|
AvxVideoReader *reader = NULL;
|
|
|
|
const AvxVideoInfo *info = NULL;
|
2014-02-06 06:34:46 +04:00
|
|
|
int n = 0;
|
|
|
|
int m = 0;
|
|
|
|
int is_range = 0;
|
|
|
|
char *nptr = NULL;
|
2014-01-28 23:25:24 +04:00
|
|
|
|
|
|
|
exec_name = argv[0];
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2016-01-29 03:41:55 +03:00
|
|
|
if (argc != 4) die("Invalid number of arguments.");
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
reader = aom_video_reader_open(argv[1]);
|
2016-01-29 03:41:55 +03:00
|
|
|
if (!reader) die("Failed to open %s for reading.", argv[1]);
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2014-01-28 23:25:24 +04:00
|
|
|
if (!(outfile = fopen(argv[2], "wb")))
|
2014-02-06 06:34:46 +04:00
|
|
|
die("Failed to open %s for writing.", argv[2]);
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2014-01-28 23:25:24 +04:00
|
|
|
n = strtol(argv[3], &nptr, 0);
|
|
|
|
m = strtol(nptr + 1, NULL, 0);
|
|
|
|
is_range = (*nptr == '-');
|
|
|
|
if (!n || !m || (*nptr != '-' && *nptr != '/'))
|
2014-02-06 06:34:46 +04:00
|
|
|
die("Couldn't parse pattern %s.\n", argv[3]);
|
2014-01-08 03:15:25 +04:00
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
info = aom_video_reader_get_info(reader);
|
2014-01-28 23:25:24 +04:00
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
|
2016-01-29 03:41:55 +03:00
|
|
|
if (!decoder) die("Unknown input codec.");
|
2014-01-28 23:25:24 +04:00
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
printf("Using %s\n", aom_codec_iface_name(decoder->codec_interface()));
|
2014-01-28 23:25:24 +04:00
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
if (aom_codec_dec_init(&codec, decoder->codec_interface(), NULL, 0))
|
2014-02-06 06:34:46 +04:00
|
|
|
die_codec(&codec, "Failed to initialize decoder.");
|
2014-01-28 23:25:24 +04:00
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
while (aom_video_reader_read_frame(reader)) {
|
|
|
|
aom_codec_iter_t iter = NULL;
|
|
|
|
aom_image_t *img = NULL;
|
2014-01-28 23:25:24 +04:00
|
|
|
size_t frame_size = 0;
|
|
|
|
int skip;
|
2016-01-29 03:41:55 +03:00
|
|
|
const unsigned char *frame =
|
2016-03-25 22:11:05 +03:00
|
|
|
aom_video_reader_get_frame(reader, &frame_size);
|
|
|
|
if (aom_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
|
2014-02-06 06:34:46 +04:00
|
|
|
die_codec(&codec, "Failed to decode frame.");
|
2014-01-28 23:25:24 +04:00
|
|
|
|
|
|
|
++frame_cnt;
|
|
|
|
|
|
|
|
skip = (is_range && frame_cnt >= n && frame_cnt <= m) ||
|
|
|
|
(!is_range && m - (frame_cnt - 1) % m <= n);
|
|
|
|
|
|
|
|
if (!skip) {
|
|
|
|
putc('.', stdout);
|
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
while ((img = aom_codec_get_frame(&codec, &iter)) != NULL)
|
|
|
|
aom_img_write(img, outfile);
|
2014-01-28 23:25:24 +04:00
|
|
|
} else {
|
|
|
|
putc('X', stdout);
|
2014-01-08 03:15:25 +04:00
|
|
|
}
|
|
|
|
|
2014-01-28 23:25:24 +04:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Processed %d frames.\n", frame_cnt);
|
2016-03-25 22:11:05 +03:00
|
|
|
if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
|
2014-01-28 23:25:24 +04:00
|
|
|
|
|
|
|
printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
|
2014-02-06 06:34:46 +04:00
|
|
|
info->frame_width, info->frame_height, argv[2]);
|
2014-01-28 23:25:24 +04:00
|
|
|
|
2016-03-25 22:11:05 +03:00
|
|
|
aom_video_reader_close(reader);
|
2014-01-28 23:25:24 +04:00
|
|
|
fclose(outfile);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2014-01-08 03:15:25 +04:00
|
|
|
}
|