00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include <stdio.h>
00056 #include <stdlib.h>
00057 #include <string.h>
00058
00059 #include "vpx/vp8dx.h"
00060 #include "vpx/vpx_decoder.h"
00061
00062 #include "../tools_common.h"
00063 #include "../video_reader.h"
00064 #include "./vpx_config.h"
00065
00066 static const char *exec_name;
00067
00068 void usage_exit(void) {
00069 fprintf(stderr, "Usage: %s <infile> <outfile> <N-M|N/M>\n", exec_name);
00070 exit(EXIT_FAILURE);
00071 }
00072
00073 int main(int argc, char **argv) {
00074 int frame_cnt = 0;
00075 FILE *outfile = NULL;
00076 vpx_codec_ctx_t codec;
00077 const VpxInterface *decoder = NULL;
00078 VpxVideoReader *reader = NULL;
00079 const VpxVideoInfo *info = NULL;
00080 int n = 0;
00081 int m = 0;
00082 int is_range = 0;
00083 char *nptr = NULL;
00084
00085 exec_name = argv[0];
00086
00087 if (argc != 4) die("Invalid number of arguments.");
00088
00089 reader = vpx_video_reader_open(argv[1]);
00090 if (!reader) die("Failed to open %s for reading.", argv[1]);
00091
00092 if (!(outfile = fopen(argv[2], "wb")))
00093 die("Failed to open %s for writing.", argv[2]);
00094
00095 n = (int)strtol(argv[3], &nptr, 0);
00096 m = (int)strtol(nptr + 1, NULL, 0);
00097 is_range = (*nptr == '-');
00098 if (!n || !m || (*nptr != '-' && *nptr != '/'))
00099 die("Couldn't parse pattern %s.\n", argv[3]);
00100
00101 info = vpx_video_reader_get_info(reader);
00102
00103 decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
00104 if (!decoder) die("Unknown input codec.");
00105
00106 printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
00107
00108 if (vpx_codec_dec_init(&codec, decoder->codec_interface(), NULL, 0))
00109 die_codec(&codec, "Failed to initialize decoder.");
00110
00111 while (vpx_video_reader_read_frame(reader)) {
00112 vpx_codec_iter_t iter = NULL;
00113 vpx_image_t *img = NULL;
00114 size_t frame_size = 0;
00115 int skip;
00116 const unsigned char *frame =
00117 vpx_video_reader_get_frame(reader, &frame_size);
00118 if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 0))
00119 die_codec(&codec, "Failed to decode frame.");
00120
00121 ++frame_cnt;
00122
00123 skip = (is_range && frame_cnt >= n && frame_cnt <= m) ||
00124 (!is_range && m - (frame_cnt - 1) % m <= n);
00125
00126 if (!skip) {
00127 putc('.', stdout);
00128
00129 while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL)
00130 vpx_img_write(img, outfile);
00131 } else {
00132 putc('X', stdout);
00133 }
00134
00135 fflush(stdout);
00136 }
00137
00138 printf("Processed %d frames.\n", frame_cnt);
00139 if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
00140
00141 printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
00142 info->frame_width, info->frame_height, argv[2]);
00143
00144 vpx_video_reader_close(reader);
00145 fclose(outfile);
00146
00147 return EXIT_SUCCESS;
00148 }