blob: 443a8681a71d25ee92066b0a8c4362c1357a3b72 [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"
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020019#include "rtc_tools/frame_analyzer/video_temporal_aligner.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_tools/simple_command_line_parser.h"
Magnus Jedvert404be7f2018-08-22 19:23:34 +020021#include "rtc_tools/y4m_file_reader.h"
Edward Lemur2e5966b2018-01-30 15:33:02 +010022#include "test/testsupport/perf_test.h"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000023
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000024/*
25 * A command line tool running PSNR and SSIM on a reference video and a test
26 * video. The test video is a record of the reference video which can start at
27 * an arbitrary point. It is possible that there will be repeated frames or
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020028 * skipped frames as well. The video files should be 1420 Y4M videos.
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000029 * The tool prints the result to standard output in the Chromium perf format:
30 * RESULT <metric>:<label>= <values>
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000031 *
32 * The max value for PSNR is 48.0 (between equal frames), as for SSIM it is 1.0.
33 *
34 * Usage:
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000035 * frame_analyzer --label=<test_label> --reference_file=<name_of_file>
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020036 * --test_file_ref=<name_of_file>
vspasova@webrtc.orgac410e22012-08-27 14:57:19 +000037 */
Robin Raymond1c62ffa2017-12-03 16:45:56 -050038int main(int argc, char* argv[]) {
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000039 std::string program_name = argv[0];
mandermo74568172017-01-17 03:24:57 -080040 std::string usage =
41 "Compares the output video with the initially sent video."
42 "\nExample usage:\n" +
43 program_name +
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020044 " --reference_file=ref.y4m --test_file=test.y4m\n"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000045 "Command line flags:\n"
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000046 " - label(string): The label to use for the perf output."
47 " Default: MY_TEST\n"
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020048 " Default: ref.y4m\n"
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000049 " - test_file(string): The test YUV file to run the analysis for."
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020050 " Default: test_file.y4m\n"
Edward Lemur2e5966b2018-01-30 15:33:02 +010051 " - chartjson_result_file: Where to store perf result in chartjson"
52 " format. If not present, no perf result will be stored."
53 " Default: None\n";
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000054
55 webrtc::test::CommandLineParser parser;
56
57 // Init the parser and set the usage message
58 parser.Init(argc, argv);
59 parser.SetUsageMessage(usage);
60
kjellander@webrtc.orgf880f862013-09-10 12:10:01 +000061 parser.SetFlag("label", "MY_TEST");
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020062 parser.SetFlag("reference_file", "ref.y4m");
63 parser.SetFlag("test_file", "test.y4m");
Edward Lemur2e5966b2018-01-30 15:33:02 +010064 parser.SetFlag("chartjson_result_file", "");
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000065 parser.SetFlag("help", "false");
66
67 parser.ProcessFlags();
68 if (parser.GetFlag("help") == "true") {
69 parser.PrintUsageMessage();
Thiago Farina3a939862015-04-09 15:45:12 +020070 exit(EXIT_SUCCESS);
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000071 }
72 parser.PrintEnteredFlags();
73
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +000074 webrtc::test::ResultsContainer results;
75
Magnus Jedvert404be7f2018-08-22 19:23:34 +020076 rtc::scoped_refptr<webrtc::test::Y4mFile> reference_video =
77 webrtc::test::Y4mFile::Open(parser.GetFlag("reference_file"));
78 rtc::scoped_refptr<webrtc::test::Y4mFile> test_video =
79 webrtc::test::Y4mFile::Open(parser.GetFlag("test_file"));
80
81 if (!reference_video || !test_video) {
82 fprintf(stderr, "Error opening video files\n");
83 return 0;
84 }
85
Magnus Jedvert9bb55fc2018-08-24 14:56:03 +020086 const std::vector<size_t> matching_indices =
87 webrtc::test::FindMatchingFrameIndices(reference_video, test_video);
88
89 results.frames =
90 webrtc::test::RunAnalysis(reference_video, test_video, matching_indices);
91
92 const std::vector<webrtc::test::Cluster> clusters =
93 webrtc::test::CalculateFrameClusters(matching_indices);
94 results.max_repeated_frames = webrtc::test::GetMaxRepeatedFrames(clusters);
95 results.max_skipped_frames = webrtc::test::GetMaxSkippedFrames(clusters);
96 results.total_skipped_frames =
97 webrtc::test::GetTotalNumberOfSkippedFrames(clusters);
98 results.decode_errors_ref = 0;
99 results.decode_errors_test = 0;
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +0000100
Edward Lemur2e5966b2018-01-30 15:33:02 +0100101 webrtc::test::PrintAnalysisResults(parser.GetFlag("label"), &results);
102
103 std::string chartjson_result_file = parser.GetFlag("chartjson_result_file");
104 if (!chartjson_result_file.empty()) {
105 webrtc::test::WritePerfResults(chartjson_result_file);
106 }
107
Robin Raymond1c62ffa2017-12-03 16:45:56 -0500108 return 0;
vspasova@webrtc.orgf61dc9b2012-08-22 08:12:00 +0000109}