blob: fd0d488c3b306f2d76a0a43eee446a4fea21b5f9 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_tools/frame_analyzer/video_quality_analysis.h"
19#include "rtc_tools/simple_command_line_parser.h"
Magnus Jedvert10e829a2018-09-05 10:46:18 +020020#include "rtc_tools/video_file_reader.h"
Edward Lemur2e5966b2018-01-30 15:33:02 +010021#include "test/testsupport/perf_test.h"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000022
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000023/*
24 * A command line tool running PSNR and SSIM on a reference video and a test
25 * video. The test video is a record of the reference video which can start at
26 * an arbitrary point. It is possible that there will be repeated frames or
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020027 * skipped frames as well. In order to have a way to compare corresponding
28 * frames from the two videos, two stats files should be provided. One for the
29 * reference video and one for the test video. The stats file
30 * is a text file assumed to be in the format:
31 * frame_xxxx yyyy where xxxx is the frame number in and yyyy is the
32 * corresponding barcode. The video files should be 1420 YUV videos.
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000033 * The tool prints the result to standard output in the Chromium perf format:
34 * RESULT <metric>:<label>= <values>
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000035 *
36 * The max value for PSNR is 48.0 (between equal frames), as for SSIM it is 1.0.
37 *
38 * Usage:
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000039 * frame_analyzer --label=<test_label> --reference_file=<name_of_file>
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020040 * --test_file_ref=<name_of_file> --stats_file_test=<name_of_file>
41 * --stats_file=<name_of_file> --width=<frame_width>
42 * --height=<frame_height>
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000043 */
Robin Raymond1c62ffa2017-12-03 16:45:56 -050044int main(int argc, char* argv[]) {
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000045 std::string program_name = argv[0];
mandermo74568172017-01-17 03:24:57 -080046 std::string usage =
47 "Compares the output video with the initially sent video."
48 "\nExample usage:\n" +
49 program_name +
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020050 " --reference_file=ref.yuv --test_file=test.yuv --width=320 "
51 "--height=240\n"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000052 "Command line flags:\n"
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020053 " - width(int): The width of the reference and test files. Default: -1\n"
54 " - height(int): The height of the reference and test files. "
55 " Default: -1\n"
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000056 " - label(string): The label to use for the perf output."
57 " Default: MY_TEST\n"
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020058 " - stats_file_ref(string): The path to the stats file that will be"
59 " produced for the reference video file."
60 " Default: stats_ref.txt\n"
61 " - stats_file_test(string): The path to the stats file that will be"
62 " produced for the test video file."
63 " Default: stats_test.txt\n"
64 " - reference_file(string): The reference YUV file to compare against."
65 " Default: ref.yuv\n"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000066 " - test_file(string): The test YUV file to run the analysis for."
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020067 " Default: test_file.yuv\n"
Edward Lemur2e5966b2018-01-30 15:33:02 +010068 " - chartjson_result_file: Where to store perf result in chartjson"
69 " format. If not present, no perf result will be stored."
70 " Default: None\n";
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000071
72 webrtc::test::CommandLineParser parser;
73
74 // Init the parser and set the usage message
75 parser.Init(argc, argv);
76 parser.SetUsageMessage(usage);
77
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020078 parser.SetFlag("width", "-1");
79 parser.SetFlag("height", "-1");
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000080 parser.SetFlag("label", "MY_TEST");
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020081 parser.SetFlag("stats_file_ref", "stats_ref.txt");
82 parser.SetFlag("stats_file_test", "stats_test.txt");
83 parser.SetFlag("reference_file", "ref.yuv");
84 parser.SetFlag("test_file", "test.yuv");
Edward Lemur2e5966b2018-01-30 15:33:02 +010085 parser.SetFlag("chartjson_result_file", "");
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000086 parser.SetFlag("help", "false");
87
88 parser.ProcessFlags();
89 if (parser.GetFlag("help") == "true") {
90 parser.PrintUsageMessage();
Thiago Farina3a939862015-04-09 15:45:12 +020091 exit(EXIT_SUCCESS);
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000092 }
93 parser.PrintEnteredFlags();
94
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020095 int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10);
96 int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10);
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000097
Sami Kalliomäki0673bc92018-08-27 17:58:13 +020098 if (width <= 0 || height <= 0) {
99 fprintf(stderr, "Error: width or height cannot be <= 0!\n");
100 return -1;
Magnus Jedvert404be7f2018-08-22 19:23:34 +0200101 }
102
Sami Kalliomäki0673bc92018-08-27 17:58:13 +0200103 webrtc::test::ResultsContainer results;
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +0200104
Magnus Jedvert10e829a2018-09-05 10:46:18 +0200105 rtc::scoped_refptr<webrtc::test::Video> reference_video =
106 webrtc::test::OpenYuvOrY4mFile(parser.GetFlag("reference_file"), width,
107 height);
108 rtc::scoped_refptr<webrtc::test::Video> test_video =
109 webrtc::test::OpenYuvOrY4mFile(parser.GetFlag("test_file"), width,
110 height);
111
112 if (!reference_video || !test_video) {
113 fprintf(stderr, "Error opening video files\n");
114 return 0;
115 }
116
117 webrtc::test::RunAnalysis(
118 reference_video, test_video, parser.GetFlag("stats_file_ref").c_str(),
119 parser.GetFlag("stats_file_test").c_str(), width, height, &results);
Sami Kalliomäki0673bc92018-08-27 17:58:13 +0200120 webrtc::test::GetMaxRepeatedAndSkippedFrames(
121 parser.GetFlag("stats_file_ref"), parser.GetFlag("stats_file_test"),
122 &results);
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +0000123
Edward Lemur2e5966b2018-01-30 15:33:02 +0100124 webrtc::test::PrintAnalysisResults(parser.GetFlag("label"), &results);
125
126 std::string chartjson_result_file = parser.GetFlag("chartjson_result_file");
127 if (!chartjson_result_file.empty()) {
128 webrtc::test::WritePerfResults(chartjson_result_file);
129 }
130
Robin Raymond1c62ffa2017-12-03 16:45:56 -0500131 return 0;
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +0000132}