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" |
| 19 | #include "rtc_tools/simple_command_line_parser.h" |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame^] | 20 | #include "test/testsupport/perf_test.h" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 21 | |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 22 | /* |
| 23 | * A command line tool running PSNR and SSIM on a reference video and a test |
| 24 | * video. The test video is a record of the reference video which can start at |
| 25 | * an arbitrary point. It is possible that there will be repeated frames or |
| 26 | * skipped frames as well. In order to have a way to compare corresponding |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 27 | * frames from the two videos, two stats files should be provided. One for the |
| 28 | * reference video and one for the test video. The stats file |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 29 | * is a text file assumed to be in the format: |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 30 | * frame_xxxx yyyy where xxxx is the frame number in and yyyy is the |
| 31 | * corresponding barcode. The video files should be 1420 YUV videos. |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 32 | * The tool prints the result to standard output in the Chromium perf format: |
| 33 | * RESULT <metric>:<label>= <values> |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 34 | * |
| 35 | * The max value for PSNR is 48.0 (between equal frames), as for SSIM it is 1.0. |
| 36 | * |
| 37 | * Usage: |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 38 | * frame_analyzer --label=<test_label> --reference_file=<name_of_file> |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 39 | * --test_file_ref=<name_of_file> --stats_file_test=<name_of_file> |
| 40 | * --stats_file=<name_of_file> --width=<frame_width> |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 41 | * --height=<frame_height> |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 42 | */ |
Robin Raymond | 1c62ffa | 2017-12-03 16:45:56 -0500 | [diff] [blame] | 43 | int main(int argc, char* argv[]) { |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 44 | std::string program_name = argv[0]; |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 45 | std::string usage = |
| 46 | "Compares the output video with the initially sent video." |
| 47 | "\nExample usage:\n" + |
| 48 | program_name + |
| 49 | " --reference_file=ref.yuv --test_file=test.yuv --width=320 " |
| 50 | "--height=240\n" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 51 | "Command line flags:\n" |
vspasova@webrtc.org | ac410e2 | 2012-08-27 14:57:19 +0000 | [diff] [blame] | 52 | " - width(int): The width of the reference and test files. Default: -1\n" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 53 | " - height(int): The height of the reference and test files. " |
| 54 | " Default: -1\n" |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 55 | " - label(string): The label to use for the perf output." |
| 56 | " Default: MY_TEST\n" |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 57 | " - stats_file_ref(string): The path to the stats file that will be" |
| 58 | " produced for the reference video file." |
| 59 | " Default: stats_ref.txt\n" |
| 60 | " - stats_file_test(string): The path to the stats file that will be" |
| 61 | " produced for the test video file." |
| 62 | " Default: stats_test.txt\n" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 63 | " - reference_file(string): The reference YUV file to compare against." |
| 64 | " Default: ref.yuv\n" |
| 65 | " - test_file(string): The test YUV file to run the analysis for." |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame^] | 66 | " Default: test_file.yuv\n" |
| 67 | " - chartjson_result_file: Where to store perf result in chartjson" |
| 68 | " format. If not present, no perf result will be stored." |
| 69 | " Default: None\n"; |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 70 | |
| 71 | webrtc::test::CommandLineParser parser; |
| 72 | |
| 73 | // Init the parser and set the usage message |
| 74 | parser.Init(argc, argv); |
| 75 | parser.SetUsageMessage(usage); |
| 76 | |
| 77 | parser.SetFlag("width", "-1"); |
| 78 | parser.SetFlag("height", "-1"); |
kjellander@webrtc.org | f880f86 | 2013-09-10 12:10:01 +0000 | [diff] [blame] | 79 | parser.SetFlag("label", "MY_TEST"); |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 80 | parser.SetFlag("stats_file_ref", "stats_ref.txt"); |
| 81 | parser.SetFlag("stats_file_test", "stats_test.txt"); |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 82 | parser.SetFlag("reference_file", "ref.yuv"); |
| 83 | parser.SetFlag("test_file", "test.yuv"); |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame^] | 84 | parser.SetFlag("chartjson_result_file", ""); |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 85 | parser.SetFlag("help", "false"); |
| 86 | |
| 87 | parser.ProcessFlags(); |
| 88 | if (parser.GetFlag("help") == "true") { |
| 89 | parser.PrintUsageMessage(); |
Thiago Farina | 3a93986 | 2015-04-09 15:45:12 +0200 | [diff] [blame] | 90 | exit(EXIT_SUCCESS); |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 91 | } |
| 92 | parser.PrintEnteredFlags(); |
| 93 | |
| 94 | int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10); |
| 95 | int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10); |
| 96 | |
| 97 | if (width <= 0 || height <= 0) { |
| 98 | fprintf(stderr, "Error: width or height cannot be <= 0!\n"); |
| 99 | return -1; |
| 100 | } |
| 101 | |
| 102 | webrtc::test::ResultsContainer results; |
| 103 | |
| 104 | webrtc::test::RunAnalysis(parser.GetFlag("reference_file").c_str(), |
| 105 | parser.GetFlag("test_file").c_str(), |
mandermo | 7456817 | 2017-01-17 03:24:57 -0800 | [diff] [blame] | 106 | parser.GetFlag("stats_file_ref").c_str(), |
| 107 | parser.GetFlag("stats_file_test").c_str(), width, |
| 108 | height, &results); |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame^] | 109 | webrtc::test::GetMaxRepeatedAndSkippedFrames( |
| 110 | parser.GetFlag("stats_file_ref"), parser.GetFlag("stats_file_test"), |
| 111 | &results); |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 112 | |
Edward Lemur | 2e5966b | 2018-01-30 15:33:02 +0100 | [diff] [blame^] | 113 | webrtc::test::PrintAnalysisResults(parser.GetFlag("label"), &results); |
| 114 | |
| 115 | std::string chartjson_result_file = parser.GetFlag("chartjson_result_file"); |
| 116 | if (!chartjson_result_file.empty()) { |
| 117 | webrtc::test::WritePerfResults(chartjson_result_file); |
| 118 | } |
| 119 | |
Robin Raymond | 1c62ffa | 2017-12-03 16:45:56 -0500 | [diff] [blame] | 120 | return 0; |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 +0000 | [diff] [blame] | 121 | } |