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 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <string.h>
00045
00046 #include "vpx/vp8dx.h"
00047 #include "vpx/vpx_decoder.h"
00048
00049 #include "../tools_common.h"
00050 #include "../video_reader.h"
00051 #include "./vpx_config.h"
00052
00053 static const char *exec_name;
00054
00055 void usage_exit(void) {
00056 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
00057 exit(EXIT_FAILURE);
00058 }
00059
00060 int main(int argc, char **argv) {
00061 int frame_cnt = 0;
00062 FILE *outfile = NULL;
00063 vpx_codec_ctx_t codec;
00064 vpx_codec_err_t res;
00065 VpxVideoReader *reader = NULL;
00066 const VpxInterface *decoder = NULL;
00067 const VpxVideoInfo *info = NULL;
00068
00069 exec_name = argv[0];
00070
00071 if (argc != 3) die("Invalid number of arguments.");
00072
00073 reader = vpx_video_reader_open(argv[1]);
00074 if (!reader) die("Failed to open %s for reading.", argv[1]);
00075
00076 if (!(outfile = fopen(argv[2], "wb")))
00077 die("Failed to open %s for writing", argv[2]);
00078
00079 info = vpx_video_reader_get_info(reader);
00080
00081 decoder = get_vpx_decoder_by_fourcc(info->codec_fourcc);
00082 if (!decoder) die("Unknown input codec.");
00083
00084 printf("Using %s\n", vpx_codec_iface_name(decoder->codec_interface()));
00085
00086 res = vpx_codec_dec_init(&codec, decoder->codec_interface(), NULL,
00087 VPX_CODEC_USE_POSTPROC);
00088 if (res == VPX_CODEC_INCAPABLE)
00089 die_codec(&codec, "Postproc not supported by this decoder.");
00090
00091 if (res) die_codec(&codec, "Failed to initialize decoder.");
00092
00093 while (vpx_video_reader_read_frame(reader)) {
00094 vpx_codec_iter_t iter = NULL;
00095 vpx_image_t *img = NULL;
00096 size_t frame_size = 0;
00097 const unsigned char *frame =
00098 vpx_video_reader_get_frame(reader, &frame_size);
00099
00100 ++frame_cnt;
00101
00102 if (frame_cnt % 30 == 1) {
00103 vp8_postproc_cfg_t pp = { 0, 0, 0 };
00104
00105 if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
00106 die_codec(&codec, "Failed to turn off postproc.");
00107 } else if (frame_cnt % 30 == 16) {
00108 vp8_postproc_cfg_t pp = { VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE, 4,
00109 0 };
00110 if (vpx_codec_control(&codec, VP8_SET_POSTPROC, &pp))
00111 die_codec(&codec, "Failed to turn on postproc.");
00112 };
00113
00114
00115 if (vpx_codec_decode(&codec, frame, (unsigned int)frame_size, NULL, 15000))
00116 die_codec(&codec, "Failed to decode frame");
00117
00118 while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) {
00119 vpx_img_write(img, outfile);
00120 }
00121 }
00122
00123 printf("Processed %d frames.\n", frame_cnt);
00124 if (vpx_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
00125
00126 printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
00127 info->frame_width, info->frame_height, argv[2]);
00128
00129 vpx_video_reader_close(reader);
00130
00131 fclose(outfile);
00132 return EXIT_SUCCESS;
00133 }