1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78#include <stdio.h>
79#include <stdlib.h>
80#include <string.h>
81
83
84#include "../tools_common.h"
85#include "../video_reader.h"
86#include "./vpx_config.h"
87
88static const char *exec_name;
89
90void usage_exit(void) {
91 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
92 exit(EXIT_FAILURE);
93}
94
95int main(int argc, char **argv) {
96 int frame_cnt = 0;
97 FILE *outfile = NULL;
99 VpxVideoReader *reader = NULL;
100 const VpxInterface *decoder = NULL;
101 const VpxVideoInfo *info = NULL;
102
103 exec_name = argv[0];
104
105 if (argc != 3) die("Invalid number of arguments.");
106
107 reader = vpx_video_reader_open(argv[1]);
108 if (!reader) die("Failed to open %s for reading.", argv[1]);
109
110 if (!(outfile = fopen(argv[2], "wb")))
111 die("Failed to open %s for writing.", argv[2]);
112
113 info = vpx_video_reader_get_info(reader);
114
115 decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
116 if (!decoder) die("Unknown input codec.");
117
119
121 die("Failed to initialize decoder.");
122
123 while (vpx_video_reader_read_frame(reader)) {
126 size_t frame_size = 0;
127 const unsigned char *frame =
128 vpx_video_reader_get_frame(reader, &frame_size);
130 die_codec(&codec, "Failed to decode frame.");
131
133 vpx_img_write(img, outfile);
134 ++frame_cnt;
135 }
136 }
137
138 printf("Processed %d frames.\n", frame_cnt);
140
141 printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
142 info->frame_width, info->frame_height, argv[2]);
143
144 vpx_video_reader_close(reader);
145
146 fclose(outfile);
147
148 return EXIT_SUCCESS;
149}
struct vpx_codec_ctx vpx_codec_ctx_t
Codec context structure.
vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
Destroy a codec instance.
const void * vpx_codec_iter_t
Iterator.
Definition vpx_codec.h:190
const char * vpx_codec_iface_name(vpx_codec_iface_t *iface)
Return the name for a given interface.
vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data, unsigned int data_sz, void *user_priv, long deadline)
Decode data.
#define vpx_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for vpx_codec_dec_init_ver()
Definition vpx_decoder.h:143
vpx_image_t * vpx_codec_get_frame(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Decoded frames iterator.
Describes the decoder algorithm interface to applications.
struct vpx_image vpx_image_t
Image Descriptor.