| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 #include <stdio.h> | 32 #include <stdio.h> |
| 33 #include <stdlib.h> | 33 #include <stdlib.h> |
| 34 #include <string.h> | 34 #include <string.h> |
| 35 | 35 |
| 36 #define VPX_CODEC_DISABLE_COMPAT 1 | 36 #define VPX_CODEC_DISABLE_COMPAT 1 |
| 37 | 37 |
| 38 #include "vpx/vp8dx.h" | 38 #include "vpx/vp8dx.h" |
| 39 #include "vpx/vpx_decoder.h" | 39 #include "vpx/vpx_decoder.h" |
| 40 | 40 |
| 41 #include "./ivfdec.h" | |
| 42 #include "./md5_utils.h" | 41 #include "./md5_utils.h" |
| 43 #include "./tools_common.h" | 42 #include "./tools_common.h" |
| 43 #include "./video_reader.h" |
| 44 #include "./vpx_config.h" | 44 #include "./vpx_config.h" |
| 45 | 45 |
| 46 static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) { | 46 static void get_image_md5(const vpx_image_t *img, unsigned char digest[16]) { |
| 47 int plane, y; | 47 int plane, y; |
| 48 MD5Context md5; | 48 MD5Context md5; |
| 49 | 49 |
| 50 MD5Init(&md5); | 50 MD5Init(&md5); |
| 51 | 51 |
| 52 for (plane = 0; plane < 3; ++plane) { | 52 for (plane = 0; plane < 3; ++plane) { |
| 53 const unsigned char *buf = img->planes[plane]; | 53 const unsigned char *buf = img->planes[plane]; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 static const char *exec_name; | 74 static const char *exec_name; |
| 75 | 75 |
| 76 void usage_exit() { | 76 void usage_exit() { |
| 77 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name); | 77 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name); |
| 78 exit(EXIT_FAILURE); | 78 exit(EXIT_FAILURE); |
| 79 } | 79 } |
| 80 | 80 |
| 81 int main(int argc, char **argv) { | 81 int main(int argc, char **argv) { |
| 82 FILE *infile, *outfile; | 82 int frame_cnt = 0; |
| 83 FILE *outfile = NULL; |
| 83 vpx_codec_ctx_t codec; | 84 vpx_codec_ctx_t codec; |
| 84 vpx_codec_iface_t *iface; | 85 VpxVideoReader *reader = NULL; |
| 85 int flags = 0, frame_cnt = 0; | 86 const VpxVideoInfo *info = NULL; |
| 86 vpx_video_t *video; | 87 const VpxInterface *decoder = NULL; |
| 87 | 88 |
| 88 exec_name = argv[0]; | 89 exec_name = argv[0]; |
| 89 | 90 |
| 90 if (argc != 3) | 91 if (argc != 3) |
| 91 die("Invalid number of arguments"); | 92 die("Invalid number of arguments."); |
| 92 | 93 |
| 93 if (!(infile = fopen(argv[1], "rb"))) | 94 reader = vpx_video_reader_open(argv[1]); |
| 94 die("Failed to open %s for reading", argv[1]); | 95 if (!reader) |
| 96 die("Failed to open %s for reading.", argv[1]); |
| 95 | 97 |
| 96 if (!(outfile = fopen(argv[2], "wb"))) | 98 if (!(outfile = fopen(argv[2], "wb"))) |
| 97 die("Failed to open %s for writing", argv[2]); | 99 die("Failed to open %s for writing.", argv[2]); |
| 98 | 100 |
| 99 video = vpx_video_open_file(infile); | 101 info = vpx_video_reader_get_info(reader); |
| 100 if (!video) | |
| 101 die("%s is not an IVF file.", argv[1]); | |
| 102 | 102 |
| 103 iface = get_codec_interface(vpx_video_get_fourcc(video)); | 103 decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc); |
| 104 if (!iface) | 104 if (!decoder) |
| 105 die("Unknown FOURCC code."); | 105 die("Unknown input codec."); |
| 106 | 106 |
| 107 printf("Using %s\n", vpx_codec_iface_name(iface)); | 107 printf("Using %s\n", vpx_codec_iface_name(decoder->interface())); |
| 108 | 108 |
| 109 if (vpx_codec_dec_init(&codec, iface, NULL, flags)) | 109 if (vpx_codec_dec_init(&codec, decoder->interface(), NULL, 0)) |
| 110 die_codec(&codec, "Failed to initialize decoder"); | 110 die_codec(&codec, "Failed to initialize decoder"); |
| 111 | 111 |
| 112 while (vpx_video_read_frame(video)) { | 112 while (vpx_video_reader_read_frame(reader)) { |
| 113 vpx_codec_iter_t iter = NULL; | 113 vpx_codec_iter_t iter = NULL; |
| 114 vpx_image_t *img = NULL; | 114 vpx_image_t *img = NULL; |
| 115 size_t frame_size = 0; | 115 size_t frame_size = 0; |
| 116 const unsigned char *frame = vpx_video_get_frame(video, &frame_size); | 116 const unsigned char *frame = vpx_video_reader_get_frame(reader, |
| 117 &frame_size); |
| 117 if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0)) | 118 if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0)) |
| 118 die_codec(&codec, "Failed to decode frame"); | 119 die_codec(&codec, "Failed to decode frame"); |
| 119 | 120 |
| 120 while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) { | 121 while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) { |
| 121 unsigned char digest[16]; | 122 unsigned char digest[16]; |
| 122 | 123 |
| 123 get_image_md5(img, digest); | 124 get_image_md5(img, digest); |
| 124 print_md5(outfile, digest); | 125 print_md5(outfile, digest); |
| 125 fprintf(outfile, " img-%dx%d-%04d.i420\n", | 126 fprintf(outfile, " img-%dx%d-%04d.i420\n", |
| 126 img->d_w, img->d_h, ++frame_cnt); | 127 img->d_w, img->d_h, ++frame_cnt); |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 printf("Processed %d frames.\n", frame_cnt); | 131 printf("Processed %d frames.\n", frame_cnt); |
| 131 if (vpx_codec_destroy(&codec)) | 132 if (vpx_codec_destroy(&codec)) |
| 132 die_codec(&codec, "Failed to destroy codec"); | 133 die_codec(&codec, "Failed to destroy codec."); |
| 133 | 134 |
| 134 vpx_video_close(video); | 135 vpx_video_reader_close(reader); |
| 135 | 136 |
| 136 fclose(outfile); | 137 fclose(outfile); |
| 137 fclose(infile); | |
| 138 return EXIT_SUCCESS; | 138 return EXIT_SUCCESS; |
| 139 } | 139 } |
| OLD | NEW |