From 62228c41ea17b1f33ab85e80962a931ef74aa593 Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Wed, 5 Sep 2018 15:04:08 +0200 Subject: [PATCH] Reland "Add tool for aliging video files" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a reland of b2c0e8f60fad10e2786e5e131136a0da1299d883 Original change's description: > Add tool for aliging video files > > This class adds logic for aligning a test video to a reference video > by an algorithm that maximizes SSIM between them. Aligned videos will be > easier to run video quality metrics on. This is a generic way of > aligning videos and can be replace the intrusive barcode stamping that > we currently use. This will be done in a follow-up CL. > > Change-Id: I71cf1e2179c0f1e03eff9e4d8fc492fd5cfbbb1c > Bug: webrtc:9642 > Reviewed-on: https://webrtc-review.googlesource.com/94773 > Commit-Queue: Magnus Jedvert > Reviewed-by: Patrik Höglund > Reviewed-by: Paulina Hensman > Cr-Commit-Position: refs/heads/master@{#24407} TBR=phensman,phoglund Bug: webrtc:9642 Change-Id: I35d6b0e598335b8d80fbfa37ba06d5c651bda4f6 Reviewed-on: https://webrtc-review.googlesource.com/98040 Commit-Queue: Magnus Jedvert Reviewed-by: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#24580} --- rtc_tools/BUILD.gn | 7 + .../frame_analyzer/video_temporal_aligner.cc | 229 ++++++++++++++++++ .../frame_analyzer/video_temporal_aligner.h | 53 ++++ .../video_temporal_aligner_unittest.cc | 127 ++++++++++ 4 files changed, 416 insertions(+) create mode 100644 rtc_tools/frame_analyzer/video_temporal_aligner.cc create mode 100644 rtc_tools/frame_analyzer/video_temporal_aligner.h create mode 100644 rtc_tools/frame_analyzer/video_temporal_aligner_unittest.cc diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn index b2a97ea6f3..294cc5ae25 100644 --- a/rtc_tools/BUILD.gn +++ b/rtc_tools/BUILD.gn @@ -77,12 +77,17 @@ rtc_static_library("video_quality_analysis") { sources = [ "frame_analyzer/video_quality_analysis.cc", "frame_analyzer/video_quality_analysis.h", + "frame_analyzer/video_temporal_aligner.cc", + "frame_analyzer/video_temporal_aligner.h", ] deps = [ ":video_file_reader", "../api/video:video_frame_i420", "../common_video", + "../rtc_base:checks", + "../rtc_base:rtc_base_approved", "../test:perf_test", + "//third_party/abseil-cpp/absl/types:optional", "//third_party/libyuv", ] } @@ -298,6 +303,7 @@ if (rtc_include_tests) { } tools_unittests_resources = [ + "../resources/foreman_128x96.yuv", "../resources/foreman_cif.yuv", "../resources/reference_less_video_test_file.y4m", ] @@ -318,6 +324,7 @@ if (rtc_include_tests) { sources = [ "frame_analyzer/reference_less_video_analysis_unittest.cc", "frame_analyzer/video_quality_analysis_unittest.cc", + "frame_analyzer/video_temporal_aligner_unittest.cc", "frame_editing/frame_editing_unittest.cc", "sanitizers_unittest.cc", "simple_command_line_parser_unittest.cc", diff --git a/rtc_tools/frame_analyzer/video_temporal_aligner.cc b/rtc_tools/frame_analyzer/video_temporal_aligner.cc new file mode 100644 index 0000000000..f106852ed2 --- /dev/null +++ b/rtc_tools/frame_analyzer/video_temporal_aligner.cc @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2018 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 "rtc_tools/frame_analyzer/video_temporal_aligner.h" + +#include +#include +#include +#include +#include + +#include "api/video/i420_buffer.h" +#include "rtc_base/checks.h" +#include "rtc_base/refcountedobject.h" +#include "rtc_tools/frame_analyzer/video_quality_analysis.h" +#include "third_party/libyuv/include/libyuv/compare.h" + +namespace webrtc { +namespace test { + +namespace { + +// This constant controls how many frames we look ahead while seeking for the +// match for the next frame. Note that we may span bigger gaps than this number +// since we reset the counter as soon as we find a better match. The seeking +// will stop when there is no improvement in the next kNumberOfFramesLookAhead +// frames. Typically, the SSIM will improve as we get closer and closer to the +// real match. +const int kNumberOfFramesLookAhead = 60; + +// Helper class that takes a video and generates an infinite looping video. +class LoopingVideo : public rtc::RefCountedObject