diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn index 18f498f1f8..6f76065489 100644 --- a/rtc_tools/BUILD.gn +++ b/rtc_tools/BUILD.gn @@ -21,7 +21,6 @@ group("rtc_tools") { ] if (!build_with_chromium) { deps += [ - ":frame_editor", ":psnr_ssim_analyzer", ":rgba_to_i420_converter", ] @@ -253,30 +252,6 @@ if (!build_with_chromium) { ] } - rtc_static_library("frame_editing_lib") { - sources = [ - "frame_editing/frame_editing_lib.cc", - "frame_editing/frame_editing_lib.h", - ] - - deps = [ - "../common_video", - ] - } - - rtc_executable("frame_editor") { - testonly = true - sources = [ - "frame_editing/frame_editing.cc", - ] - - deps = [ - ":frame_editing_lib", - "//third_party/abseil-cpp/absl/flags:flag", - "//third_party/abseil-cpp/absl/flags:parse", - ] - } - if (rtc_enable_protobuf) { proto_library("chart_proto") { visibility = [ "*" ] @@ -394,7 +369,6 @@ if (rtc_include_tests) { "frame_analyzer/video_geometry_aligner_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", "video_file_reader_unittest.cc", "video_file_writer_unittest.cc", @@ -420,10 +394,7 @@ if (rtc_include_tests) { ] if (!build_with_chromium) { - deps += [ - ":frame_editing_lib", - ":reference_less_video_analysis_lib", - ] + deps += [ ":reference_less_video_analysis_lib" ] } if (rtc_enable_protobuf) { diff --git a/rtc_tools/frame_editing/frame_editing.cc b/rtc_tools/frame_editing/frame_editing.cc deleted file mode 100644 index 8e82110b1e..0000000000 --- a/rtc_tools/frame_editing/frame_editing.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2012 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 -#include -#include - -#include - -#include "absl/flags/flag.h" -#include "absl/flags/parse.h" -#include "rtc_tools/frame_editing/frame_editing_lib.h" - -ABSL_FLAG(std::string, in_path, "", "Path and filename to the input file"); -ABSL_FLAG(int32_t, - width, - -1, - "Width in pixels of the frames in the input file"); -ABSL_FLAG(int32_t, - height, - -1, - "Height in pixels of the frames in the input file"); -ABSL_FLAG(int32_t, f, -1, "First frame to process"); -ABSL_FLAG(int32_t, - interval, - -1, - "Interval specifies with what ratio the number of frames should be " - "increased or decreased with"); -ABSL_FLAG(int32_t, l, -1, "Last frame to process"); -ABSL_FLAG(std::string, - out_path, - "output.yuv", - "The output file to which frames are written"); - -// A command-line tool to edit a YUV-video (I420 sub-sampled). -int main(int argc, char* argv[]) { - absl::ParseCommandLine(argc, argv); - // TODO(bugs.webrtc.org/10616): Add program usage message when Abseil - // flags supports it. - // std::string usage = - // "Deletes a series of frames in a yuv file." - // " Only I420 is supported!\n" - // "Example usage:\n" + - // program_name + - // " --in_path=input.yuv --width=320 --height=240 --f=60 --interval=1 " - // "--l=120" - // " --out_path=edited_clip.yuv\n" - // "Command line flags:\n" - // "--in_path(string): Path and filename to the input file\n" - // "--width(int): Width in pixels of the frames in the input file." - // " Default: -1\n" - // "--height(int): Height in pixels of the frames in the input file." - // " Default: -1\n" - // "--f(int): First frame to process. Default: -1\n" - // "--l(int): Last frame to process. Default: -1\n" - // "Frame numbering starts at 1. The set of frames to be processed includes - // " "the frame with the number and .\n" - // "--interval(int): Interval specifies with what ratio the number of " - // "frames " - // "should be increased or decreased with.\n" - // "If you set to a positive number, frames between and - // " "will be inserted times." - // " If you set to a negative number then the amount of frames " - // "between and will be decreased with a ratio of abs(interval)." - // " Set interval=-1 if every frame between and should be " - // "deleted. Set interval=-2 if every second frame should be deleted, and " - // "so " - // "on. Frame numbering between and starts with 1 and frames with" - // " number n where (n - 1) % interval == 0 will be kept.\n" - // "Example 1:\n" - // "If one clip has 10 frames (1 to 10) and you specify =4, =7 and " - // "interval=2, then you will get a clip that contains frame " - // "1, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9 and 10.\n" - // "Example 2:\n" - // "If you specify f=4, l=7 and interval=-1, then you will get a clip that" - // " contains frame 1, 2, 3, 8, 9 and 10.\n" - // "Example 3:\n" - // "If one clip has 10 frames (1 to 10), and you specify f=1, l=10 and " - // " interval=-4, then you will get a clip that contains frame " - // "1, 5 and 9.\n" - // "No interpolation is done when up-sampling." - // " Default: -1\n" - // "--out_path(string): The output file to which frames are written." - // " Default: output.yuv\n"; - - const std::string in_path = absl::GetFlag(FLAGS_in_path); - int width = absl::GetFlag(FLAGS_width); - int height = absl::GetFlag(FLAGS_height); - int first_frame_to_cut = absl::GetFlag(FLAGS_f); - int interval = absl::GetFlag(FLAGS_interval); - int last_frame_to_cut = absl::GetFlag(FLAGS_l); - - const std::string out_path = absl::GetFlag(FLAGS_out_path); - - if (in_path.empty()) { - fprintf(stderr, "You must specify a file to edit\n"); - return -1; - } - - if (first_frame_to_cut <= 0 || last_frame_to_cut <= 0) { - fprintf(stderr, "Error: You must specify which frames to cut!\n"); - return -2; - } - - if (width <= 0 || height <= 0) { - fprintf(stderr, "Error: width or height cannot be <= 0!\n"); - return -3; - } - return webrtc::EditFrames(in_path, width, height, first_frame_to_cut, - interval, last_frame_to_cut, out_path); -} diff --git a/rtc_tools/frame_editing/frame_editing_lib.cc b/rtc_tools/frame_editing/frame_editing_lib.cc deleted file mode 100644 index 450c0b3a8b..0000000000 --- a/rtc_tools/frame_editing/frame_editing_lib.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2012 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_editing/frame_editing_lib.h" - -#include - -#include -#include -#include - -#include "common_video/libyuv/include/webrtc_libyuv.h" - -namespace webrtc { - -int EditFrames(const std::string& in_path, - int width, - int height, - int first_frame_to_process, - int interval, - int last_frame_to_process, - const std::string& out_path) { - if (last_frame_to_process < first_frame_to_process) { - fprintf(stderr, "The set of frames to cut is empty! (l < f)\n"); - return -10; - } - - FILE* in_fid = fopen(in_path.c_str(), "rb"); - if (!in_fid) { - fprintf(stderr, "Could not read input file: %s.\n", in_path.c_str()); - return -11; - } - - // Frame size of I420. - size_t frame_length = CalcBufferSize(VideoType::kI420, width, height); - - std::unique_ptr temp_buffer(new uint8_t[frame_length]); - - FILE* out_fid = fopen(out_path.c_str(), "wb"); - - if (!out_fid) { - fprintf(stderr, "Could not open output file: %s.\n", out_path.c_str()); - fclose(in_fid); - return -12; - } - - int num_frames_read = 0; - int num_frames_read_between = 0; - size_t num_bytes_read; - - while ((num_bytes_read = fread(temp_buffer.get(), 1, frame_length, in_fid)) == - frame_length) { - num_frames_read++; - if ((num_frames_read < first_frame_to_process) || - (last_frame_to_process < num_frames_read)) { - fwrite(temp_buffer.get(), 1, frame_length, out_fid); - } else { - num_frames_read_between++; - if (interval <= 0) { - if (interval == -1) { - // Remove all frames. - } else { - if (((num_frames_read_between - 1) % interval) == 0) { - // Keep only every |interval| frame. - fwrite(temp_buffer.get(), 1, frame_length, out_fid); - } - } - } else if (interval > 0) { - for (int i = 1; i <= interval; ++i) { - fwrite(temp_buffer.get(), 1, frame_length, out_fid); - } - } - } - } - if (num_bytes_read > 0 && num_bytes_read < frame_length) { - printf("Frame to small! Last frame truncated.\n"); - } - fclose(in_fid); - fclose(out_fid); - - printf("Done editing!\n"); - return 0; -} -} // namespace webrtc diff --git a/rtc_tools/frame_editing/frame_editing_lib.h b/rtc_tools/frame_editing/frame_editing_lib.h deleted file mode 100644 index 91eaa3bfec..0000000000 --- a/rtc_tools/frame_editing/frame_editing_lib.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2012 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. - */ - -#ifndef RTC_TOOLS_FRAME_EDITING_FRAME_EDITING_LIB_H_ -#define RTC_TOOLS_FRAME_EDITING_FRAME_EDITING_LIB_H_ - -#include - -namespace webrtc { - -// Frame numbering starts at 1. The set of frames to be processed includes the -// frame with the number: first_frame_to_process and last_frame_to_process. -// Interval specifies with what interval frames should be cut or kept. -// Example 1: -// If one clip has 10 frames (1 to 10), and you specify -// first_frame_to_process = 4, last_frame_to_process = 7 and interval = -1, -// then you will get a clip that contains frame 1, 2, 3, 8, 9 and 10. -// Example 2: -// I you specify first_frame_to_process = 1, last_frame_to_process = 10 and -// interval = -4, then you will get a clip that contains frame 1, 5, 9. -// Example 3: -// If you specify first_frame_to_process = 4, last_frame_to_process = 7 and -// interval = 2, then you will get a clip that contains frame -// 1, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9 and 10. -// No interpolation is done when up-sampling. - -int EditFrames(const std::string& in_path, - int width, - int height, - int first_frame_to_process, - int interval, - int last_frame_to_process, - const std::string& out_path); -} // namespace webrtc - -#endif // RTC_TOOLS_FRAME_EDITING_FRAME_EDITING_LIB_H_ diff --git a/rtc_tools/frame_editing/frame_editing_unittest.cc b/rtc_tools/frame_editing/frame_editing_unittest.cc deleted file mode 100644 index 891ef7ceb2..0000000000 --- a/rtc_tools/frame_editing/frame_editing_unittest.cc +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2012 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 -#include - -#include -#include -#include - -#include "common_video/libyuv/include/webrtc_libyuv.h" -#include "rtc_tools/frame_editing/frame_editing_lib.h" -#include "test/gtest.h" -#include "test/testsupport/file_utils.h" - -namespace webrtc { -namespace test { - -const int kWidth = 352; -const int kHeight = 288; -const size_t kFrameSize = CalcBufferSize(VideoType::kI420, kWidth, kHeight); - -class FrameEditingTest : public ::testing::Test { - protected: - virtual void SetUp() { - reference_video_ = ResourcePath("foreman_cif", "yuv"); - test_video_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), - "frame_editing_unittest.yuv"); - - original_fid_ = fopen(reference_video_.c_str(), "rb"); - ASSERT_TRUE(original_fid_ != NULL); - - // Ensure the output file exists on disk. - std::ofstream(test_video_.c_str(), std::ios::out); - // Open the output file for reading. - // TODO(holmer): Figure out why this file has to be opened here (test fails - // if it's opened after the write operation performed in EditFrames). - edited_fid_ = fopen(test_video_.c_str(), "rb"); - ASSERT_TRUE(edited_fid_ != NULL); - - original_buffer_.reset(new int[kFrameSize]); - edited_buffer_.reset(new int[kFrameSize]); - num_frames_read_ = 0; - } - virtual void TearDown() { - fclose(original_fid_); - fclose(edited_fid_); - remove(test_video_.c_str()); - } - // Compares the frames in both streams to the end of one of the streams. - void CompareToTheEnd(FILE* test_video_fid, - FILE* ref_video_fid, - std::unique_ptr* ref_buffer, - std::unique_ptr* test_buffer) { - while (!feof(test_video_fid) && !feof(ref_video_fid)) { - num_bytes_read_ = fread(ref_buffer->get(), 1, kFrameSize, ref_video_fid); - if (!feof(ref_video_fid)) { - EXPECT_EQ(kFrameSize, num_bytes_read_); - } - num_bytes_read_ = - fread(test_buffer->get(), 1, kFrameSize, test_video_fid); - if (!feof(test_video_fid)) { - EXPECT_EQ(kFrameSize, num_bytes_read_); - } - if (!feof(test_video_fid) && !feof(test_video_fid)) { - EXPECT_EQ(0, memcmp(ref_buffer->get(), test_buffer->get(), kFrameSize)); - } - } - // There should not be anything left in either stream. - EXPECT_EQ(!feof(test_video_fid), !feof(ref_video_fid)); - } - std::string reference_video_; - std::string test_video_; - FILE* original_fid_; - FILE* edited_fid_; - size_t num_bytes_read_; - std::unique_ptr original_buffer_; - std::unique_ptr edited_buffer_; - int num_frames_read_; -}; - -TEST_F(FrameEditingTest, ValidInPath) { - const int kFirstFrameToProcess = 160; - const int kInterval = -1; - const int kLastFrameToProcess = 240; - - int result = - EditFrames(reference_video_, kWidth, kHeight, kFirstFrameToProcess, - kInterval, kLastFrameToProcess, test_video_); - EXPECT_EQ(0, result); - - for (int i = 1; i < kFirstFrameToProcess; ++i) { - num_bytes_read_ = - fread(original_buffer_.get(), 1, kFrameSize, original_fid_); - EXPECT_EQ(kFrameSize, num_bytes_read_); - - num_bytes_read_ = fread(edited_buffer_.get(), 1, kFrameSize, edited_fid_); - EXPECT_EQ(kFrameSize, num_bytes_read_); - - EXPECT_EQ(0, - memcmp(original_buffer_.get(), edited_buffer_.get(), kFrameSize)); - } - // Do not compare the frames that have been cut. - for (int i = kFirstFrameToProcess; i <= kLastFrameToProcess; ++i) { - num_bytes_read_ = - fread(original_buffer_.get(), 1, kFrameSize, original_fid_); - EXPECT_EQ(kFrameSize, num_bytes_read_); - } - CompareToTheEnd(edited_fid_, original_fid_, &original_buffer_, - &edited_buffer_); -} - -TEST_F(FrameEditingTest, EmptySetToCut) { - const int kFirstFrameToProcess = 2; - const int kInterval = -1; - const int kLastFrameToProcess = 1; - - int result = - EditFrames(reference_video_, kWidth, kHeight, kFirstFrameToProcess, - kInterval, kLastFrameToProcess, test_video_); - EXPECT_EQ(-10, result); -} - -TEST_F(FrameEditingTest, InValidInPath) { - const std::string kRefVideo_ = "PATH/THAT/DOES/NOT/EXIST"; - - const int kFirstFrameToProcess = 30; - const int kInterval = 1; - const int kLastFrameToProcess = 120; - - int result = EditFrames(kRefVideo_, kWidth, kHeight, kFirstFrameToProcess, - kInterval, kLastFrameToProcess, test_video_); - EXPECT_EQ(-11, result); -} - -TEST_F(FrameEditingTest, DeletingEverySecondFrame) { - const int kFirstFrameToProcess = 1; - const int kInterval = -2; - const int kLastFrameToProcess = 10000; - // Set kLastFrameToProcess to a large value so that all frame are processed. - int result = - EditFrames(reference_video_, kWidth, kHeight, kFirstFrameToProcess, - kInterval, kLastFrameToProcess, test_video_); - EXPECT_EQ(0, result); - - while (!feof(original_fid_) && !feof(edited_fid_)) { - num_bytes_read_ = - fread(original_buffer_.get(), 1, kFrameSize, original_fid_); - if (!feof(original_fid_)) { - EXPECT_EQ(kFrameSize, num_bytes_read_); - num_frames_read_++; - } - // We want to compare every second frame of the original to the edited. - // kInterval=-2 and (num_frames_read_ - 1) % kInterval will be -1 for - // every second frame. - // num_frames_read_ - 1 because we have deleted frame number 2, 4 , 6 etc. - if ((num_frames_read_ - 1) % kInterval == -1) { - num_bytes_read_ = fread(edited_buffer_.get(), 1, kFrameSize, edited_fid_); - if (!feof(edited_fid_)) { - EXPECT_EQ(kFrameSize, num_bytes_read_); - } - if (!feof(original_fid_) && !feof(edited_fid_)) { - EXPECT_EQ(0, memcmp(original_buffer_.get(), edited_buffer_.get(), - kFrameSize)); - } - } - } -} - -TEST_F(FrameEditingTest, RepeatFrames) { - const int kFirstFrameToProcess = 160; - const int kInterval = 2; - const int kLastFrameToProcess = 240; - - int result = - EditFrames(reference_video_, kWidth, kHeight, kFirstFrameToProcess, - kInterval, kLastFrameToProcess, test_video_); - EXPECT_EQ(0, result); - - for (int i = 1; i < kFirstFrameToProcess; ++i) { - num_bytes_read_ = - fread(original_buffer_.get(), 1, kFrameSize, original_fid_); - EXPECT_EQ(kFrameSize, num_bytes_read_); - - num_bytes_read_ = fread(edited_buffer_.get(), 1, kFrameSize, edited_fid_); - EXPECT_EQ(kFrameSize, num_bytes_read_); - - EXPECT_EQ(0, - memcmp(original_buffer_.get(), edited_buffer_.get(), kFrameSize)); - } - // Do not compare the frames that have been repeated. - for (int i = kFirstFrameToProcess; i <= kLastFrameToProcess; ++i) { - num_bytes_read_ = - fread(original_buffer_.get(), 1, kFrameSize, original_fid_); - EXPECT_EQ(kFrameSize, num_bytes_read_); - for (int i = 1; i <= kInterval; ++i) { - num_bytes_read_ = fread(edited_buffer_.get(), 1, kFrameSize, edited_fid_); - EXPECT_EQ(kFrameSize, num_bytes_read_); - EXPECT_EQ( - 0, memcmp(original_buffer_.get(), edited_buffer_.get(), kFrameSize)); - } - } - CompareToTheEnd(edited_fid_, original_fid_, &original_buffer_, - &edited_buffer_); -} -} // namespace test -} // namespace webrtc