OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
kjellander_webrtc
2016/11/23 14:44:23
2016
phoglund
2016/11/23 15:19:56
Nit: 2016
| |
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 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
13 #include <iostream> | |
14 #include <vector> | |
15 | |
16 #include "webrtc/tools/frame_analyzer/video_quality_analysis.h" | |
17 #include "webrtc/tools/simple_command_line_parser.h" | |
18 | |
19 #define NO_OF_STATS 5 | |
phoglund
2016/11/23 15:19:56
What does stats mean? I don't get it.
| |
20 #define STATS_LINE_LENGTH 28 | |
21 #define PSNR_THRESHOLD 47 | |
phoglund
2016/11/23 15:19:56
PSNR_FREEZE_THRESHOLD?
| |
22 #define SSIM_THRESHOLD .999 | |
23 | |
24 void get_height_width_fps(int *height, int *width, int *fps, | |
25 const char* video_file) { | |
26 /* | |
27 * Parse file header to get height width and fpd. | |
28 * File header looks like : | |
29 * YUV4MPEG2 W1280 H720 F25:1 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2. | |
30 */ | |
31 char frame_header[STATS_LINE_LENGTH]; | |
32 FILE* input_file = fopen(video_file, "rb"); | |
33 fread(frame_header, 1, STATS_LINE_LENGTH, input_file); | |
34 | |
35 std::string frame_header_stats[NO_OF_STATS]; | |
36 int no_of_stats = 0; | |
37 char *token = strtok(frame_header, " "); | |
38 | |
39 while (token != NULL) { | |
40 frame_header_stats[no_of_stats++] = token; | |
41 token = strtok(NULL, " "); | |
42 } | |
43 | |
44 *width = std::stoi(frame_header_stats[1].erase(0, 1)); | |
45 *height = std::stoi(frame_header_stats[2].erase(0, 1)); | |
46 *fps = std::stoi(frame_header_stats[3].erase(0, 1)); | |
47 | |
48 printf("Height: %d Width: %d fps:%d \n", *height, *width, *fps); | |
49 fclose(input_file); | |
50 } | |
51 | |
52 void print_freezing_metrics(std::vector<double> PSNR_per_frame, | |
53 std::vector<double> SSIM_per_frame) { | |
54 /* | |
55 * Prints the different metrics mainly: | |
56 * 1) Identical frame number, PSNR and SSIM values. | |
57 * 2) Length of continuous frozen frames. | |
58 * 3) Max length of continuous freezed frames. | |
59 * 4) No of unique frames found. | |
60 * 5) Total different identical frames found. | |
61 * | |
62 * Sample output: | |
63 * Printing metrics for file: /usr/local/google/home/charujain/restore/ | |
64 webrtc-checkout/src/webrtc/tools/test_3.y4m | |
65 ============================= | |
66 Printing Identical Frames: | |
67 Frame Number: 29 PSNR: 48.000000 SSIM: 0.999618 | |
68 Frame Number: 39 PSNR: 48.000000 SSIM: 0.999898 | |
69 Frame Number: 60 PSNR: 48.000000 SSIM: 0.999564 | |
70 Frame Number: 64 PSNR: 48.000000 SSIM: 0.999651 | |
71 Frame Number: 69 PSNR: 48.000000 SSIM: 0.999684 | |
72 Total number of frames received: 74 | |
73 Total identical frames: 5 | |
74 Number of unique frames: 69 | |
75 Identical continuous frames of window more than one : | |
76 0 0 0 0 0 | |
kjellander_webrtc
2016/11/23 14:44:23
I don't quite understand these zeros.
Does the fi
| |
77 * | |
78 */ | |
79 printf("Printing Identical Frames: \n"); | |
80 | |
81 int total_identical_frames = 0; | |
82 int previous_identical_frame_number = -1; | |
83 int length_of_continuous_identical_frames = 0; | |
84 int max_length_of_identical_frames = 0; | |
85 std::vector<int> identical_frames; | |
86 int no_of_frames = PSNR_per_frame.size(); | |
87 | |
88 for (int i = 0; i < no_of_frames; i++) { | |
89 if (PSNR_per_frame[i] >= PSNR_THRESHOLD || SSIM_per_frame[i] | |
phoglund
2016/11/23 15:19:56
This algorithm is a bit hard to read, maybe becaus
| |
90 >= SSIM_THRESHOLD) { | |
91 printf(" Frame Number: %d PSNR: %f SSIM: %f \n", i, PSNR_per_frame[i], | |
92 SSIM_per_frame[i]); | |
93 if (previous_identical_frame_number != -1 | |
94 && previous_identical_frame_number == i-1) { | |
95 length_of_continuous_identical_frames++; | |
96 previous_identical_frame_number = i; | |
97 } else { | |
98 max_length_of_identical_frames = std::max(max_length_of_identical_frames | |
99 , length_of_continuous_identical_frames); | |
100 identical_frames.push_back(length_of_continuous_identical_frames); | |
101 length_of_continuous_identical_frames = 0; | |
102 } | |
103 total_identical_frames++; | |
104 } | |
105 } | |
106 int unique_frames = no_of_frames - total_identical_frames; | |
107 printf("Total number of frames received: %d\n", no_of_frames); | |
108 printf("Total identical frames: %d\n", total_identical_frames); | |
109 printf("Number of unique frames: %d\n", unique_frames); | |
110 | |
111 // Print identical frames if they appear together. | |
112 printf("Identical continuous frames of window more than one : \n"); | |
113 for (int i = 0; i < static_cast<int>(identical_frames.size()); i++) | |
114 printf("%d ", identical_frames[i]); | |
115 printf("\n"); | |
116 } | |
117 | |
118 int main(int argc, char** argv) { | |
119 /* | |
120 * This script captures the freezing metrics for reference less | |
phoglund
2016/11/23 15:19:56
I think in general avoid c-style comments. And it'
| |
121 * video analysis. | |
122 */ | |
123 std::string program_name = argv[0]; | |
124 std::string usage = "Outputs the freezing score by comparing current frame " | |
125 "with the previous frame.\nExample usage:\n" + program_name + | |
126 " --input_file=input_file.txt\n" | |
127 "Command line flags:\n" | |
128 " - input_file(string): File containing absolute path of the video " | |
129 "files to be analyzed. Only y4m file format is supported.\n"; | |
130 | |
131 webrtc::test::CommandLineParser parser; | |
132 | |
133 // Init the parser and set the usage message. | |
134 parser.Init(argc, argv); | |
135 parser.SetUsageMessage(usage); | |
136 | |
137 parser.SetFlag("input_file", ""); | |
138 parser.ProcessFlags(); | |
139 if (parser.GetFlag("input_file").empty()) { | |
140 parser.PrintUsageMessage(); | |
141 exit(EXIT_SUCCESS); | |
142 } | |
143 std::string video_names_file = parser.GetFlag("input_file"); | |
144 const char * video_file = video_names_file.c_str(); | |
phoglund
2016/11/23 15:19:56
Nit: char*
| |
145 | |
146 FILE* video_file_ptr = fopen(video_file, "r"); | |
phoglund
2016/11/23 15:19:56
Extract 146- 215 out to a new function. Short, foc
| |
147 if (video_file_ptr == NULL) { | |
148 printf("Error opening file\n"); | |
149 return -1; | |
150 } | |
151 | |
152 char video_file_name[200]; | |
153 while (fgets(video_file_name, 200, video_file_ptr)) { | |
154 strtok(video_file_name, "\n"); | |
155 | |
156 // Check for video file extension. | |
157 if (std::string(video_file_name).substr(strlen(video_file_name)-3, 3) | |
158 != "y4m") { | |
159 printf("Only y4m video file format are supported. Found: %s\n", | |
160 video_file_name); | |
161 return -1; | |
162 } | |
163 | |
164 int height = 0, width = 0, fps = 0; | |
165 get_height_width_fps(&height, &width, &fps, video_file_name); | |
166 | |
167 int no_of_frames = 0; | |
168 std::vector<double> PSNR_per_frame; | |
169 std::vector<double> SSIM_per_frame; | |
170 int size = webrtc::test::GetI420FrameSize(width, height); | |
171 | |
172 // Allocate buffers for test and reference frames. | |
173 uint8_t* current_frame = new uint8_t[size]; | |
174 uint8_t* next_frame = new uint8_t[size]; | |
175 | |
176 while (true) { | |
177 if (!(webrtc::test::ExtractFrameFromY4mFile (video_file_name, | |
phoglund
2016/11/23 15:19:56
!webrtc::test::Extract...
| |
178 width, height, | |
phoglund
2016/11/23 15:19:56
Nit: indent
| |
179 no_of_frames, | |
180 current_frame))) { | |
181 break; | |
182 } | |
183 | |
184 if (!(webrtc::test::ExtractFrameFromY4mFile (video_file_name, | |
185 width, height, | |
186 no_of_frames+1, | |
phoglund
2016/11/23 15:19:56
Nit: frames + 1
| |
187 next_frame))) { | |
188 break; | |
189 } | |
190 | |
191 double result_psnr = webrtc::test::CalculateMetrics(webrtc::test::kPSNR, | |
192 current_frame, | |
193 next_frame, | |
194 width, height); | |
195 double result_ssim = webrtc::test::CalculateMetrics(webrtc::test::kSSIM, | |
196 current_frame, | |
197 next_frame, | |
198 width, height); | |
199 | |
200 PSNR_per_frame.push_back(result_psnr); | |
201 SSIM_per_frame.push_back(result_ssim); | |
202 no_of_frames++; | |
203 } | |
204 printf("=============================\n"); | |
205 printf("Printing metrics for file: %s\n", video_file_name); | |
206 printf("=============================\n"); | |
207 print_freezing_metrics(PSNR_per_frame, SSIM_per_frame); | |
208 | |
209 // Cleanup. | |
210 delete[] current_frame; | |
211 delete[] next_frame; | |
212 } | |
213 fclose(video_file_ptr); | |
214 return 0; | |
215 } | |
OLD | NEW |