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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 #include <stdio.h> | 80 #include <stdio.h> |
81 #include <stdlib.h> | 81 #include <stdlib.h> |
82 #include <string.h> | 82 #include <string.h> |
83 | 83 |
84 #define VPX_CODEC_DISABLE_COMPAT 1 | 84 #define VPX_CODEC_DISABLE_COMPAT 1 |
85 | 85 |
86 #include "vpx/vp8dx.h" | 86 #include "vpx/vp8dx.h" |
87 #include "vpx/vpx_decoder.h" | 87 #include "vpx/vpx_decoder.h" |
88 | 88 |
89 #include "./ivfdec.h" | |
90 #include "./tools_common.h" | 89 #include "./tools_common.h" |
| 90 #include "./video_reader.h" |
91 #include "./vpx_config.h" | 91 #include "./vpx_config.h" |
92 | 92 |
93 static const char *exec_name; | 93 static const char *exec_name; |
94 | 94 |
95 void usage_exit() { | 95 void usage_exit() { |
96 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name); | 96 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name); |
97 exit(EXIT_FAILURE); | 97 exit(EXIT_FAILURE); |
98 } | 98 } |
99 | 99 |
100 int main(int argc, char **argv) { | 100 int main(int argc, char **argv) { |
101 FILE *infile, *outfile; | 101 int frame_cnt = 0; |
| 102 FILE *outfile = NULL; |
102 vpx_codec_ctx_t codec; | 103 vpx_codec_ctx_t codec; |
103 vpx_codec_iface_t *iface; | 104 VpxVideoReader *reader = NULL; |
104 int flags = 0, frame_cnt = 0; | 105 const VpxInterface *decoder = NULL; |
105 vpx_video_t *video; | 106 const VpxVideoInfo *info = NULL; |
106 | 107 |
107 exec_name = argv[0]; | 108 exec_name = argv[0]; |
108 | 109 |
109 if (argc != 3) | 110 if (argc != 3) |
110 die("Invalid number of arguments"); | 111 die("Invalid number of arguments."); |
111 | 112 |
112 if (!(infile = fopen(argv[1], "rb"))) | 113 reader = vpx_video_reader_open(argv[1]); |
113 die("Failed to open %s for reading", argv[1]); | 114 if (!reader) |
| 115 die("Failed to open %s for reading.", argv[1]); |
114 | 116 |
115 if (!(outfile = fopen(argv[2], "wb"))) | 117 if (!(outfile = fopen(argv[2], "wb"))) |
116 die("Failed to open %s for writing", argv[2]); | 118 die("Failed to open %s for writing.", argv[2]); |
117 | 119 |
118 video = vpx_video_open_file(infile); | 120 info = vpx_video_reader_get_info(reader); |
119 if (!video) | |
120 die("%s is not an IVF file.", argv[1]); | |
121 | 121 |
122 iface = get_codec_interface(vpx_video_get_fourcc(video)); | 122 decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc); |
123 if (!iface) | 123 if (!decoder) |
124 die("Unknown FOURCC code."); | 124 die("Unknown input codec."); |
125 | 125 |
126 printf("Using %s\n", vpx_codec_iface_name(iface)); | 126 printf("Using %s\n", vpx_codec_iface_name(decoder->interface())); |
127 | 127 |
128 if (vpx_codec_dec_init(&codec, iface, NULL, flags)) | 128 if (vpx_codec_dec_init(&codec, decoder->interface(), NULL, 0)) |
129 die_codec(&codec, "Failed to initialize decoder"); | 129 die_codec(&codec, "Failed to initialize decoder."); |
130 | 130 |
131 while (vpx_video_read_frame(video)) { | 131 while (vpx_video_reader_read_frame(reader)) { |
132 vpx_codec_iter_t iter = NULL; | 132 vpx_codec_iter_t iter = NULL; |
133 vpx_image_t *img = NULL; | 133 vpx_image_t *img = NULL; |
134 size_t frame_size = 0; | 134 size_t frame_size = 0; |
135 const unsigned char *frame = vpx_video_get_frame(video, &frame_size); | 135 const unsigned char *frame = vpx_video_reader_get_frame(reader, |
| 136 &frame_size); |
136 if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0)) | 137 if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0)) |
137 die_codec(&codec, "Failed to decode frame"); | 138 die_codec(&codec, "Failed to decode frame."); |
138 | 139 |
139 while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) { | 140 while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) { |
140 vpx_img_write(img, outfile); | 141 vpx_img_write(img, outfile); |
141 ++frame_cnt; | 142 ++frame_cnt; |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 printf("Processed %d frames.\n", frame_cnt); | 146 printf("Processed %d frames.\n", frame_cnt); |
146 if (vpx_codec_destroy(&codec)) | 147 if (vpx_codec_destroy(&codec)) |
147 die_codec(&codec, "Failed to destroy codec"); | 148 die_codec(&codec, "Failed to destroy codec"); |
148 | 149 |
149 printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n", | 150 printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n", |
150 vpx_video_get_width(video), vpx_video_get_height(video), argv[2]); | 151 info->frame_width, info->frame_height, argv[2]); |
151 | 152 |
152 vpx_video_close(video); | 153 vpx_video_reader_close(reader); |
153 | 154 |
154 fclose(outfile); | 155 fclose(outfile); |
155 fclose(infile); | |
156 | 156 |
157 return EXIT_SUCCESS; | 157 return EXIT_SUCCESS; |
158 } | 158 } |
OLD | NEW |