From beff53527bc0ae5944cbbad2610eb0a784b8bff1 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Tue, 25 Jun 2019 08:47:45 +0200 Subject: [PATCH] Switch frame_editor to ABSL_FLAG. Bug: webrtc:10616 Change-Id: I1576c6a615d6a9ea07db61027b9eccd3efb9dcca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137501 Reviewed-by: Karl Wiberg Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#28365} --- rtc_tools/BUILD.gn | 4 +- rtc_tools/frame_editing/frame_editing.cc | 155 ++++++++++++----------- 2 files changed, 82 insertions(+), 77 deletions(-) diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn index c7022b0ea7..c39aaa5806 100644 --- a/rtc_tools/BUILD.gn +++ b/rtc_tools/BUILD.gn @@ -273,13 +273,15 @@ if (!build_with_chromium) { } rtc_executable("frame_editor") { + testonly = true sources = [ "frame_editing/frame_editing.cc", ] deps = [ - ":command_line_parser", ":frame_editing_lib", + "//third_party/abseil-cpp/absl/flags:flag", + "//third_party/abseil-cpp/absl/flags:parse", ] } diff --git a/rtc_tools/frame_editing/frame_editing.cc b/rtc_tools/frame_editing/frame_editing.cc index 4ac9452761..71798d503b 100644 --- a/rtc_tools/frame_editing/frame_editing.cc +++ b/rtc_tools/frame_editing/frame_editing.cc @@ -13,89 +13,92 @@ #include #include +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" #include "rtc_tools/frame_editing/frame_editing_lib.h" -#include "rtc_tools/simple_command_line_parser.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[]) { - std::string program_name = argv[0]; - 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"; + 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"; - webrtc::test::CommandLineParser parser; + 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); - // Init the parser and set the usage message - parser.Init(argc, argv); - parser.SetUsageMessage(usage); - parser.SetFlag("in_path", "-1"); - parser.SetFlag("width", "-1"); - parser.SetFlag("height", "-1"); - parser.SetFlag("f", "-1"); - parser.SetFlag("interval", "-1"); - parser.SetFlag("l", "-1"); - parser.SetFlag("out_path", "edited_output.yuv"); - parser.SetFlag("help", "false"); + const std::string out_path = absl::GetFlag(FLAGS_out_path); - parser.ProcessFlags(); - if (parser.GetFlag("help") == "true") { - parser.PrintUsageMessage(); - exit(EXIT_SUCCESS); - } - parser.PrintEnteredFlags(); - - const char* in_path = parser.GetFlag("in_path").c_str(); - int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10); - int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10); - int first_frame_to_cut = strtol((parser.GetFlag("f")).c_str(), NULL, 10); - int interval = strtol((parser.GetFlag("interval")).c_str(), NULL, 10); - int last_frame_to_cut = strtol((parser.GetFlag("l")).c_str(), NULL, 10); - - const char* out_path = parser.GetFlag("out_path").c_str(); - - if (!strcmp(in_path, "-1")) { + if (in_path.empty()) { fprintf(stderr, "You must specify a file to edit\n"); return -1; }