Chromium Code Reviews| Index: webrtc/tools/frame_analyzer/reference_less_video_analysis.cc |
| diff --git a/webrtc/tools/frame_analyzer/reference_less_video_analysis.cc b/webrtc/tools/frame_analyzer/reference_less_video_analysis.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4e80893357e95e370b07b08c36e75e3543c5d2d4 |
| --- /dev/null |
| +++ b/webrtc/tools/frame_analyzer/reference_less_video_analysis.cc |
| @@ -0,0 +1,215 @@ |
| +/* |
| + * 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
|
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| +#include <stdio.h> |
| +#include <stdlib.h> |
| +#include <string.h> |
| +#include <iostream> |
| +#include <vector> |
| + |
| +#include "webrtc/tools/frame_analyzer/video_quality_analysis.h" |
| +#include "webrtc/tools/simple_command_line_parser.h" |
| + |
| +#define NO_OF_STATS 5 |
|
phoglund
2016/11/23 15:19:56
What does stats mean? I don't get it.
|
| +#define STATS_LINE_LENGTH 28 |
| +#define PSNR_THRESHOLD 47 |
|
phoglund
2016/11/23 15:19:56
PSNR_FREEZE_THRESHOLD?
|
| +#define SSIM_THRESHOLD .999 |
| + |
| +void get_height_width_fps(int *height, int *width, int *fps, |
| + const char* video_file) { |
| + /* |
| + * Parse file header to get height width and fpd. |
| + * File header looks like : |
| + * YUV4MPEG2 W1280 H720 F25:1 Ip A0:0 C420mpeg2 XYSCSS=420MPEG2. |
| + */ |
| + char frame_header[STATS_LINE_LENGTH]; |
| + FILE* input_file = fopen(video_file, "rb"); |
| + fread(frame_header, 1, STATS_LINE_LENGTH, input_file); |
| + |
| + std::string frame_header_stats[NO_OF_STATS]; |
| + int no_of_stats = 0; |
| + char *token = strtok(frame_header, " "); |
| + |
| + while (token != NULL) { |
| + frame_header_stats[no_of_stats++] = token; |
| + token = strtok(NULL, " "); |
| + } |
| + |
| + *width = std::stoi(frame_header_stats[1].erase(0, 1)); |
| + *height = std::stoi(frame_header_stats[2].erase(0, 1)); |
| + *fps = std::stoi(frame_header_stats[3].erase(0, 1)); |
| + |
| + printf("Height: %d Width: %d fps:%d \n", *height, *width, *fps); |
| + fclose(input_file); |
| +} |
| + |
| +void print_freezing_metrics(std::vector<double> PSNR_per_frame, |
| + std::vector<double> SSIM_per_frame) { |
| + /* |
| + * Prints the different metrics mainly: |
| + * 1) Identical frame number, PSNR and SSIM values. |
| + * 2) Length of continuous frozen frames. |
| + * 3) Max length of continuous freezed frames. |
| + * 4) No of unique frames found. |
| + * 5) Total different identical frames found. |
| + * |
| + * Sample output: |
| + * Printing metrics for file: /usr/local/google/home/charujain/restore/ |
| + webrtc-checkout/src/webrtc/tools/test_3.y4m |
| + ============================= |
| + Printing Identical Frames: |
| + Frame Number: 29 PSNR: 48.000000 SSIM: 0.999618 |
| + Frame Number: 39 PSNR: 48.000000 SSIM: 0.999898 |
| + Frame Number: 60 PSNR: 48.000000 SSIM: 0.999564 |
| + Frame Number: 64 PSNR: 48.000000 SSIM: 0.999651 |
| + Frame Number: 69 PSNR: 48.000000 SSIM: 0.999684 |
| + Total number of frames received: 74 |
| + Total identical frames: 5 |
| + Number of unique frames: 69 |
| + Identical continuous frames of window more than one : |
| + 0 0 0 0 0 |
|
kjellander_webrtc
2016/11/23 14:44:23
I don't quite understand these zeros.
Does the fi
|
| + * |
| + */ |
| + printf("Printing Identical Frames: \n"); |
| + |
| + int total_identical_frames = 0; |
| + int previous_identical_frame_number = -1; |
| + int length_of_continuous_identical_frames = 0; |
| + int max_length_of_identical_frames = 0; |
| + std::vector<int> identical_frames; |
| + int no_of_frames = PSNR_per_frame.size(); |
| + |
| + for (int i = 0; i < no_of_frames; i++) { |
| + 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
|
| + >= SSIM_THRESHOLD) { |
| + printf(" Frame Number: %d PSNR: %f SSIM: %f \n", i, PSNR_per_frame[i], |
| + SSIM_per_frame[i]); |
| + if (previous_identical_frame_number != -1 |
| + && previous_identical_frame_number == i-1) { |
| + length_of_continuous_identical_frames++; |
| + previous_identical_frame_number = i; |
| + } else { |
| + max_length_of_identical_frames = std::max(max_length_of_identical_frames |
| + , length_of_continuous_identical_frames); |
| + identical_frames.push_back(length_of_continuous_identical_frames); |
| + length_of_continuous_identical_frames = 0; |
| + } |
| + total_identical_frames++; |
| + } |
| + } |
| + int unique_frames = no_of_frames - total_identical_frames; |
| + printf("Total number of frames received: %d\n", no_of_frames); |
| + printf("Total identical frames: %d\n", total_identical_frames); |
| + printf("Number of unique frames: %d\n", unique_frames); |
| + |
| + // Print identical frames if they appear together. |
| + printf("Identical continuous frames of window more than one : \n"); |
| + for (int i = 0; i < static_cast<int>(identical_frames.size()); i++) |
| + printf("%d ", identical_frames[i]); |
| + printf("\n"); |
| +} |
| + |
| +int main(int argc, char** argv) { |
| + /* |
| + * 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'
|
| + * video analysis. |
| + */ |
| + std::string program_name = argv[0]; |
| + std::string usage = "Outputs the freezing score by comparing current frame " |
| + "with the previous frame.\nExample usage:\n" + program_name + |
| + " --input_file=input_file.txt\n" |
| + "Command line flags:\n" |
| + " - input_file(string): File containing absolute path of the video " |
| + "files to be analyzed. Only y4m file format is supported.\n"; |
| + |
| + webrtc::test::CommandLineParser parser; |
| + |
| + // Init the parser and set the usage message. |
| + parser.Init(argc, argv); |
| + parser.SetUsageMessage(usage); |
| + |
| + parser.SetFlag("input_file", ""); |
| + parser.ProcessFlags(); |
| + if (parser.GetFlag("input_file").empty()) { |
| + parser.PrintUsageMessage(); |
| + exit(EXIT_SUCCESS); |
| + } |
| + std::string video_names_file = parser.GetFlag("input_file"); |
| + const char * video_file = video_names_file.c_str(); |
|
phoglund
2016/11/23 15:19:56
Nit: char*
|
| + |
| + 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
|
| + if (video_file_ptr == NULL) { |
| + printf("Error opening file\n"); |
| + return -1; |
| + } |
| + |
| + char video_file_name[200]; |
| + while (fgets(video_file_name, 200, video_file_ptr)) { |
| + strtok(video_file_name, "\n"); |
| + |
| + // Check for video file extension. |
| + if (std::string(video_file_name).substr(strlen(video_file_name)-3, 3) |
| + != "y4m") { |
| + printf("Only y4m video file format are supported. Found: %s\n", |
| + video_file_name); |
| + return -1; |
| + } |
| + |
| + int height = 0, width = 0, fps = 0; |
| + get_height_width_fps(&height, &width, &fps, video_file_name); |
| + |
| + int no_of_frames = 0; |
| + std::vector<double> PSNR_per_frame; |
| + std::vector<double> SSIM_per_frame; |
| + int size = webrtc::test::GetI420FrameSize(width, height); |
| + |
| + // Allocate buffers for test and reference frames. |
| + uint8_t* current_frame = new uint8_t[size]; |
| + uint8_t* next_frame = new uint8_t[size]; |
| + |
| + while (true) { |
| + if (!(webrtc::test::ExtractFrameFromY4mFile (video_file_name, |
|
phoglund
2016/11/23 15:19:56
!webrtc::test::Extract...
|
| + width, height, |
|
phoglund
2016/11/23 15:19:56
Nit: indent
|
| + no_of_frames, |
| + current_frame))) { |
| + break; |
| + } |
| + |
| + if (!(webrtc::test::ExtractFrameFromY4mFile (video_file_name, |
| + width, height, |
| + no_of_frames+1, |
|
phoglund
2016/11/23 15:19:56
Nit: frames + 1
|
| + next_frame))) { |
| + break; |
| + } |
| + |
| + double result_psnr = webrtc::test::CalculateMetrics(webrtc::test::kPSNR, |
| + current_frame, |
| + next_frame, |
| + width, height); |
| + double result_ssim = webrtc::test::CalculateMetrics(webrtc::test::kSSIM, |
| + current_frame, |
| + next_frame, |
| + width, height); |
| + |
| + PSNR_per_frame.push_back(result_psnr); |
| + SSIM_per_frame.push_back(result_ssim); |
| + no_of_frames++; |
| + } |
| + printf("=============================\n"); |
| + printf("Printing metrics for file: %s\n", video_file_name); |
| + printf("=============================\n"); |
| + print_freezing_metrics(PSNR_per_frame, SSIM_per_frame); |
| + |
| + // Cleanup. |
| + delete[] current_frame; |
| + delete[] next_frame; |
| + } |
| + fclose(video_file_ptr); |
| + return 0; |
| +} |