Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: webrtc/tools/frame_analyzer/reference_less_video_analysis_lib.cc

Issue 2515253004: Added tool for reference less video analysis (Closed)
Patch Set: Latest changes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/tools/frame_analyzer/reference_less_video_analysis_lib.cc
diff --git a/webrtc/tools/frame_analyzer/reference_less_video_analysis_lib.cc b/webrtc/tools/frame_analyzer/reference_less_video_analysis_lib.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a0efaeec7e74ecbf82dc2ea2497445a483cef2b3
--- /dev/null
+++ b/webrtc/tools/frame_analyzer/reference_less_video_analysis_lib.cc
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * 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>
kjellander_webrtc 2016/11/28 15:02:08 sort
+#include <numeric>
+
+
+#include "webrtc/tools/frame_analyzer/reference_less_video_analysis_lib.h"
+#include "webrtc/tools/frame_analyzer/video_quality_analysis.h"
+#include "webrtc/tools/simple_command_line_parser.h"
kjellander_webrtc 2016/11/28 15:02:08 is this used? If not, also move the dependency to
+
+#define STATS_LINE_LENGTH 28
+#define PSNR_FREEZE_THRESHOLD 47
+#define SSIM_FREEZE_THRESHOLD .999
+
+void get_height_width_fps(int *height, int *width, int *fps,
kjellander_webrtc 2016/11/28 15:02:08 Can we use https://cs.chromium.org/chromium/src/th
+ const char* video_file) {
+ /*
+ * Parse file header to get height width and fpd.
phoglund 2016/11/25 11:08:08 Nit: fps Actually, the first line is pretty obvio
+ * 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 file_header_stats[5];
+ int no_of_stats = 0;
+ char *save_ptr;
+ char *token = strtok_r(frame_header, " ", &save_ptr);
+
+ while (token != NULL) {
+ file_header_stats[no_of_stats++] = token;
+ token = strtok_r(NULL, " ", &save_ptr);
+ }
+
+ *width = std::stoi(file_header_stats[1].erase(0, 1));
+ *height = std::stoi(file_header_stats[2].erase(0, 1));
+ *fps = std::stoi(file_header_stats[3].erase(0, 1));
+
+ printf("Height: %d Width: %d fps:%d \n", *height, *width, *fps);
+ fclose(input_file);
+}
+
+bool frozen_frame(std::vector<double> psnr_per_frame,
+ std::vector<double> ssim_per_frame, int frame) {
phoglund 2016/11/25 11:08:08 Nit: indent
+ if (psnr_per_frame[frame] >= PSNR_FREEZE_THRESHOLD
phoglund 2016/11/25 11:08:08 Just do return psnr_per_frame[frame] >= PSNR_FREE
+ || ssim_per_frame[frame] >= SSIM_FREEZE_THRESHOLD)
+ return true;
+ return false;
+}
+
+std::vector<int> find_frame_clusters(std::vector<double> psnr_per_frame,
+ std::vector<double> ssim_per_frame) {
+ std::vector<int> identical_frame_clusters;
+ int num_frozen = 0;
+ int total_no_of_frames = psnr_per_frame.size();
+
+ for (int each_frame = 0; each_frame < total_no_of_frames; each_frame++) {
+ if (frozen_frame(psnr_per_frame, ssim_per_frame, each_frame)) {
+ num_frozen++;
+ } else if (num_frozen > 0) {
phoglund 2016/11/25 11:08:08 Nit: indent
+ // Not frozen anymore.
+ identical_frame_clusters.push_back(num_frozen);
+ num_frozen = 0;
+ }
+ }
+ return identical_frame_clusters;
+}
+
+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/
kjellander_webrtc 2016/11/28 15:02:08 Please remove paths referencing your local checkou
+ webrtc-checkout/src/webrtc/tools/test_3.y4m
+ =============================
+ Total number of frames received: 74
+ Total identical frames: 5
+ Number of unique frames: 69
+ 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
+ Print identical frame which appears in clusters :
+ 1 1 1 1 1
kjellander_webrtc 2016/11/28 15:02:08 Can you provide an example where the result is 1 1
+ *
+ */
+ int total_no_of_frames = psnr_per_frame.size();
+ std::vector<int> identical_frame_clusters = find_frame_clusters(
+ psnr_per_frame, ssim_per_frame);
+ int total_identical_frames = std::accumulate(
+ identical_frame_clusters.begin(), identical_frame_clusters.end(), 0);
+ int unique_frames = total_no_of_frames - total_identical_frames;
+
+ printf("Total number of frames received: %d\n", total_no_of_frames);
+ printf("Total identical frames: %d\n", total_identical_frames);
+ printf("Number of unique frames: %d\n", unique_frames);
+
+ printf("Printing Identical Frames: \n");
+ for (int frame = 0; frame < total_no_of_frames; frame++) {
+ if (frozen_frame(psnr_per_frame, ssim_per_frame, frame)) {
+ printf(" Frame Number: %d PSNR: %f SSIM: %f \n", frame,
+ psnr_per_frame[frame], ssim_per_frame[frame]);
+ }
+ }
+
+ printf("Print identical frame which appears in clusters : \n");
+ for (int cluster = 0;
+ cluster < static_cast<int>(identical_frame_clusters.size()); cluster++)
+ printf("%d ", identical_frame_clusters[cluster]);
+ printf("\n");
+}
+
+void compute_metrics(char video_file_name[],
+ std::vector<double>* psnr_per_frame,
+ std::vector<double>* ssim_per_frame) {
+ int height = 0, width = 0, fps = 0;
+ get_height_width_fps(&height, &width, &fps, video_file_name);
+
+ int no_of_frames = 0;
+ 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,
+ width, height,
+ no_of_frames,
+ current_frame))) {
+ break;
+ }
+
+ if (!(webrtc::test::ExtractFrameFromY4mFile (video_file_name,
+ width, height,
+ no_of_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++;
+ }
+ // Cleanup.
+ delete[] current_frame;
+ delete[] next_frame;
+}
+
+void run_analysis(const char* video_file) {
+ FILE* video_file_ptr = fopen(video_file, "r");
+ if (ferror(video_file_ptr)) {
+ printf("Error opening file\n");
kjellander_webrtc 2016/11/28 15:02:08 print the filename here as well for easier debuggi
+ return;
kjellander_webrtc 2016/11/28 15:02:08 Make sure the program exits with a non-zero return
+ }
+
+ char video_file_name[200];
kjellander_webrtc 2016/11/28 15:02:08 200? Please use some established (platform depende
+ while (fgets(video_file_name, 200, video_file_ptr)) {
+ strtok(video_file_name, "\n");
+
+ // Check for video file extension.
kjellander_webrtc 2016/11/28 15:02:08 I think the checks for the file should be done in
+ 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;
+ }
kjellander_webrtc 2016/11/28 15:02:08 Can you add a check that the file is actually y4m
+ std::vector<double> psnr_per_frame;
+ std::vector<double> ssim_per_frame;
+ compute_metrics(video_file_name, &psnr_per_frame, &ssim_per_frame);
+
+ printf("=============================\n");
+ printf("Printing metrics for file: %s\n", video_file_name);
+ printf("=============================\n");
+ print_freezing_metrics(psnr_per_frame, ssim_per_frame);
+ }
+ fclose(video_file_ptr);
+}

Powered by Google App Engine
This is Rietveld 408576698