blob: 4af3389422067acbe1b9a0f785d9d5b0fa8f67ff [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
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000011#include <stdio.h>
12#include <stdlib.h>
13
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000014#include <map>
pbos@webrtc.orgba7f6a82013-06-04 08:14:10 +000015#include <string>
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000016#include <vector>
17
kjellanderd2b63cf2017-06-30 03:04:59 -070018#include "webrtc/rtc_tools/frame_analyzer/video_quality_analysis.h"
19#include "webrtc/rtc_tools/simple_command_line_parser.h"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000020
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000021/*
22 * A command line tool running PSNR and SSIM on a reference video and a test
23 * video. The test video is a record of the reference video which can start at
24 * an arbitrary point. It is possible that there will be repeated frames or
25 * skipped frames as well. In order to have a way to compare corresponding
mandermo74568172017-01-17 03:24:57 -080026 * frames from the two videos, two stats files should be provided. One for the
27 * reference video and one for the test video. The stats file
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000028 * is a text file assumed to be in the format:
mandermo74568172017-01-17 03:24:57 -080029 * frame_xxxx yyyy where xxxx is the frame number in and yyyy is the
30 * corresponding barcode. The video files should be 1420 YUV videos.
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000031 * The tool prints the result to standard output in the Chromium perf format:
32 * RESULT <metric>:<label>= <values>
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000033 *
34 * The max value for PSNR is 48.0 (between equal frames), as for SSIM it is 1.0.
35 *
36 * Usage:
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000037 * frame_analyzer --label=<test_label> --reference_file=<name_of_file>
mandermo74568172017-01-17 03:24:57 -080038 * --test_file_ref=<name_of_file> --stats_file_test=<name_of_file>
39 * --stats_file=<name_of_file> --width=<frame_width>
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000040 * --height=<frame_height>
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000041 */
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000042int main(int argc, char** argv) {
43 std::string program_name = argv[0];
mandermo74568172017-01-17 03:24:57 -080044 std::string usage =
45 "Compares the output video with the initially sent video."
46 "\nExample usage:\n" +
47 program_name +
48 " --reference_file=ref.yuv --test_file=test.yuv --width=320 "
49 "--height=240\n"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000050 "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"
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000054 " - label(string): The label to use for the perf output."
55 " Default: MY_TEST\n"
mandermo74568172017-01-17 03:24:57 -080056 " - stats_file_ref(string): The path to the stats file that will be"
57 " produced for the reference video file."
58 " Default: stats_ref.txt\n"
59 " - stats_file_test(string): The path to the stats file that will be"
60 " produced for the test video file."
61 " Default: stats_test.txt\n"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000062 " - reference_file(string): The reference YUV file to compare against."
63 " Default: ref.yuv\n"
64 " - test_file(string): The test YUV file to run the analysis for."
65 " Default: test_file.yuv\n";
66
67 webrtc::test::CommandLineParser parser;
68
69 // Init the parser and set the usage message
70 parser.Init(argc, argv);
71 parser.SetUsageMessage(usage);
72
73 parser.SetFlag("width", "-1");
74 parser.SetFlag("height", "-1");
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000075 parser.SetFlag("label", "MY_TEST");
mandermo74568172017-01-17 03:24:57 -080076 parser.SetFlag("stats_file_ref", "stats_ref.txt");
77 parser.SetFlag("stats_file_test", "stats_test.txt");
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000078 parser.SetFlag("reference_file", "ref.yuv");
79 parser.SetFlag("test_file", "test.yuv");
80 parser.SetFlag("help", "false");
81
82 parser.ProcessFlags();
83 if (parser.GetFlag("help") == "true") {
84 parser.PrintUsageMessage();
Thiago Farina3a939862015-04-09 15:45:12 +020085 exit(EXIT_SUCCESS);
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000086 }
87 parser.PrintEnteredFlags();
88
89 int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10);
90 int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10);
91
92 if (width <= 0 || height <= 0) {
93 fprintf(stderr, "Error: width or height cannot be <= 0!\n");
94 return -1;
95 }
96
97 webrtc::test::ResultsContainer results;
98
99 webrtc::test::RunAnalysis(parser.GetFlag("reference_file").c_str(),
100 parser.GetFlag("test_file").c_str(),
mandermo74568172017-01-17 03:24:57 -0800101 parser.GetFlag("stats_file_ref").c_str(),
102 parser.GetFlag("stats_file_test").c_str(), width,
103 height, &results);
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +0000104
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +0000105 std::string label = parser.GetFlag("label");
106 webrtc::test::PrintAnalysisResults(label, &results);
mandermo74568172017-01-17 03:24:57 -0800107 webrtc::test::PrintMaxRepeatedAndSkippedFrames(
108 label, parser.GetFlag("stats_file_ref"),
109 parser.GetFlag("stats_file_test"));
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +0000110}