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#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35
38
39#include "../md5_utils.h"
40#include "../tools_common.h"
41#include "../video_reader.h"
42#include "./vpx_config.h"
43
44static void get_image_md5(
const vpx_image_t *img,
unsigned char digest[16]) {
45 int plane, y;
46 MD5Context md5;
47
48 MD5Init(&md5);
49
50 for (plane = 0; plane < 3; ++plane) {
51 const unsigned char *buf = img->
planes[plane];
52 const int stride = img->
stride[plane];
53 const int w = plane ? (img->
d_w + 1) >> 1 : img->d_w;
54 const int h = plane ? (img->
d_h + 1) >> 1 : img->d_h;
55
56 for (y = 0; y < h; ++y) {
57 MD5Update(&md5, buf, w);
58 buf += stride;
59 }
60 }
61
62 MD5Final(digest, &md5);
63}
64
65static void print_md5(FILE *stream, unsigned char digest[16]) {
66 int i;
67
68 for (i = 0; i < 16; ++i) fprintf(stream, "%02x", digest[i]);
69}
70
71static const char *exec_name;
72
73void usage_exit(void) {
74 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
75 exit(EXIT_FAILURE);
76}
77
78int main(int argc, char **argv) {
79 int frame_cnt = 0;
80 FILE *outfile = NULL;
82 VpxVideoReader *reader = NULL;
83 const VpxVideoInfo *info = NULL;
84 const VpxInterface *decoder = NULL;
85
86 exec_name = argv[0];
87
88 if (argc != 3) die("Invalid number of arguments.");
89
90 reader = vpx_video_reader_open(argv[1]);
91 if (!reader) die("Failed to open %s for reading.", argv[1]);
92
93 if (!(outfile = fopen(argv[2], "wb")))
94 die("Failed to open %s for writing.", argv[2]);
95
96 info = vpx_video_reader_get_info(reader);
97
98 decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
99 if (!decoder) die("Unknown input codec.");
100
102
104 die_codec(&codec, "Failed to initialize decoder");
105
106 while (vpx_video_reader_read_frame(reader)) {
109 size_t frame_size = 0;
110 const unsigned char *frame =
111 vpx_video_reader_get_frame(reader, &frame_size);
113 die_codec(&codec, "Failed to decode frame");
114
116 unsigned char digest[16];
117
118 get_image_md5(img, digest);
119 print_md5(outfile, digest);
120 fprintf(outfile,
" img-%dx%d-%04d.i420\n", img->
d_w, img->
d_h,
121 ++frame_cnt);
122 }
123 }
124
125 printf("Processed %d frames.\n", frame_cnt);
127
128 vpx_video_reader_close(reader);
129
130 fclose(outfile);
131 return EXIT_SUCCESS;
132}
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.
unsigned int d_h
Definition vpx_image.h:88
unsigned int d_w
Definition vpx_image.h:87
unsigned char * planes[4]
Definition vpx_image.h:104
int stride[4]
Definition vpx_image.h:105
Provides definitions for using VP8 or VP9 within the vpx Decoder interface.
Describes the decoder algorithm interface to applications.
struct vpx_image vpx_image_t
Image Descriptor.