vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 14 | #include <map> |
pbos@webrtc.org | ba7f6a8 | 2013-06-04 08:14:10 +0000 | [diff] [blame] | 15 | #include <string> |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_tools/frame_analyzer/video_quality_analysis.h" |
Magnus Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 19 | #include "rtc_tools/frame_analyzer/video_temporal_aligner.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "rtc_tools/simple_command_line_parser.h" |
Magnus Jedvert | 404be7f | 2018-08-22 19:23:34 +0200 | [diff] [blame] | 21 | #include "rtc_tools/y4m_file_reader.h" |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame] | 22 | #include "test/testsupport/perf_test.h" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 23 | |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 24 | /* |
| 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 Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 28 | * skipped frames as well. The video files should be 1420 Y4M videos. |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 29 | * The tool prints the result to standard output in the Chromium perf format: |
| 30 | * RESULT <metric>:<label>= <values> |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 31 | * |
| 32 | * The max value for PSNR is 48.0 (between equal frames), as for SSIM it is 1.0. |
| 33 | * |
| 34 | * Usage: |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 35 | * frame_analyzer --label=<test_label> --reference_file=<name_of_file> |
Magnus Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 36 | * --test_file_ref=<name_of_file> |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 37 | */ |
Robin Raymond | 1c62ffa | 2017-12-03 16:45:56 -0500 | [diff] [blame] | 38 | int main(int argc, char* argv[]) { |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 39 | std::string program_name = argv[0]; |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 40 | std::string usage = |
| 41 | "Compares the output video with the initially sent video." |
| 42 | "\nExample usage:\n" + |
| 43 | program_name + |
Magnus Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 44 | " --reference_file=ref.y4m --test_file=test.y4m\n" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 45 | "Command line flags:\n" |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 46 | " - label(string): The label to use for the perf output." |
| 47 | " Default: MY_TEST\n" |
Magnus Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 48 | " Default: ref.y4m\n" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 49 | " - test_file(string): The test YUV file to run the analysis for." |
Magnus Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 50 | " Default: test_file.y4m\n" |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame] | 51 | " - 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.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 54 | |
| 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.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 61 | parser.SetFlag("label", "MY_TEST"); |
Magnus Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 62 | parser.SetFlag("reference_file", "ref.y4m"); |
| 63 | parser.SetFlag("test_file", "test.y4m"); |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame] | 64 | parser.SetFlag("chartjson_result_file", ""); |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 65 | parser.SetFlag("help", "false"); |
| 66 | |
| 67 | parser.ProcessFlags(); |
| 68 | if (parser.GetFlag("help") == "true") { |
| 69 | parser.PrintUsageMessage(); |
Thiago Farina | 3a93986 | 2015-04-09 15:45:12 +0200 | [diff] [blame] | 70 | exit(EXIT_SUCCESS); |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 71 | } |
| 72 | parser.PrintEnteredFlags(); |
| 73 | |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 74 | webrtc::test::ResultsContainer results; |
| 75 | |
Magnus Jedvert | 404be7f | 2018-08-22 19:23:34 +0200 | [diff] [blame] | 76 | 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 Jedvert | 9bb55fc | 2018-08-24 14:56:03 +0200 | [diff] [blame^] | 86 | 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.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 100 | |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame] | 101 | 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 Raymond | 1c62ffa | 2017-12-03 16:45:56 -0500 | [diff] [blame] | 108 | return 0; |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 109 | } |