blob: 6b46cfd858b38629747d285be73ff8d4fb338ef9 [file] [log] [blame]
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000011#include <cstdio>
12#include <cstdlib>
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000013#include <map>
pbos@webrtc.orgba7f6a82013-06-04 08:14:10 +000014#include <string>
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000015#include <vector>
16
pbos@webrtc.orgba7f6a82013-06-04 08:14:10 +000017#include "webrtc/tools/frame_analyzer/video_quality_analysis.h"
18#include "webrtc/tools/simple_command_line_parser.h"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000019
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000020/*
21 * A command line tool running PSNR and SSIM on a reference video and a test
22 * video. The test video is a record of the reference video which can start at
23 * an arbitrary point. It is possible that there will be repeated frames or
24 * skipped frames as well. In order to have a way to compare corresponding
25 * frames from the two videos, a stats file should be provided. The stats file
26 * is a text file assumed to be in the format:
27 * frame_xxxx yyyy
28 * where xxxx is the frame number in the test video and yyyy is the
29 * corresponding frame number in the original video.
30 * The video files should be 1420 YUV videos.
31 * The tool prints the result to the standard output in the following format:
32 * BSTATS
33 * <psnr_value> <ssim_value>; <psnr_value> <ssim_value>; ....
34 * ESTATS
35 * Unique_frames_count:<value>
36 * Max_repeated:<value>
37 * Max_skipped<value>
38 *
39 * The max value for PSNR is 48.0 (between equal frames), as for SSIM it is 1.0.
40 *
41 * Usage:
42 * frame_analyzer --reference_file=<name_of_file> --test_file=<name_of_file>
43 * --stats_file=<name_of_file> --width=<frame_width> --height=<frame_height>
44 */
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000045int main(int argc, char** argv) {
46 std::string program_name = argv[0];
47 std::string usage = "Compares the output video with the initially sent video."
48 "\nExample usage:\n" + program_name + " --stats_file=stats.txt "
49 "--reference_file=ref.yuv --test_file=test.yuv --width=320 --height=240\n"
50 "Command line flags:\n"
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000051 " - width(int): The width of the reference and test files. Default: -1\n"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000052 " - height(int): The height of the reference and test files. "
53 " Default: -1\n"
54 " - stats_file(string): The full name of the file containing the stats"
55 " after decoding of the received YUV video. Default: stats.txt\n"
56 " - reference_file(string): The reference YUV file to compare against."
57 " Default: ref.yuv\n"
58 " - test_file(string): The test YUV file to run the analysis for."
59 " Default: test_file.yuv\n";
60
61 webrtc::test::CommandLineParser parser;
62
63 // Init the parser and set the usage message
64 parser.Init(argc, argv);
65 parser.SetUsageMessage(usage);
66
67 parser.SetFlag("width", "-1");
68 parser.SetFlag("height", "-1");
69 parser.SetFlag("stats_file", "stats.txt");
70 parser.SetFlag("reference_file", "ref.yuv");
71 parser.SetFlag("test_file", "test.yuv");
72 parser.SetFlag("help", "false");
73
74 parser.ProcessFlags();
75 if (parser.GetFlag("help") == "true") {
76 parser.PrintUsageMessage();
77 }
78 parser.PrintEnteredFlags();
79
80 int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10);
81 int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10);
82
83 if (width <= 0 || height <= 0) {
84 fprintf(stderr, "Error: width or height cannot be <= 0!\n");
85 return -1;
86 }
87
88 webrtc::test::ResultsContainer results;
89
90 webrtc::test::RunAnalysis(parser.GetFlag("reference_file").c_str(),
91 parser.GetFlag("test_file").c_str(),
92 parser.GetFlag("stats_file").c_str(), width, height,
93 &results);
94
95 webrtc::test::PrintAnalysisResults(&results);
96 webrtc::test::PrintMaxRepeatedAndSkippedFrames(
97 parser.GetFlag("stats_file").c_str());
98}