Switch rgba_to_i420_converter to ABSL_FLAG.

Bug: webrtc:10616
Change-Id: I45f94e0f43e84b041c72b1bdc5b35ee0e970397e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143179
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28362}
This commit is contained in:
Mirko Bonadei 2019-06-25 08:52:47 +02:00 committed by Commit Bot
parent 6bafc8b278
commit 2308bb223e
2 changed files with 43 additions and 46 deletions

View File

@ -242,6 +242,7 @@ if (!build_with_chromium) {
rtc_executable("rgba_to_i420_converter") {
visibility = [ "*" ]
testonly = true
sources = [
"converter/converter.cc",
"converter/converter.h",
@ -249,8 +250,9 @@ if (!build_with_chromium) {
]
deps = [
":command_line_parser",
"../common_video",
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
"//third_party/libyuv",
]
}

View File

@ -12,8 +12,24 @@
#include <stdlib.h>
#include <string>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "rtc_tools/converter/converter.h"
#include "rtc_tools/simple_command_line_parser.h"
ABSL_FLAG(int, width, -1, "Width in pixels of the frames in the input file");
ABSL_FLAG(int, height, -1, "Height in pixels of the frames in the input file");
ABSL_FLAG(std::string,
frames_dir,
".",
"The path to the directory where the frames reside");
ABSL_FLAG(std::string,
output_file,
"output.yuv",
" The output file to which frames are written");
ABSL_FLAG(bool,
delete_frames,
false,
" Whether or not to delete the input frames after the conversion");
/*
* A command-line tool based on libyuv to convert a set of RGBA files to a YUV
@ -24,60 +40,39 @@
* --height=<height_of_input_frames>
*/
int main(int argc, char* argv[]) {
std::string program_name = argv[0];
std::string usage =
"Converts RGBA raw image files to I420 frames for YUV.\n"
"Example usage:\n" +
program_name +
" --frames_dir=. --output_file=output.yuv --width=320 --height=240\n"
"IMPORTANT: If you pass the --delete_frames command line parameter, the "
"tool will delete the input frames after conversion.\n"
"Command line flags:\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"
" - frames_dir(string): The path to the directory where the frames "
"reside."
" Default: .\n"
" - output_file(string): The output file to which frames are written."
" Default: output.yuv\n"
" - delete_frames(bool): Whether or not to delete the input frames after"
" the conversion. Default: false.\n";
absl::ParseCommandLine(argc, argv);
// TODO(bugs.webrtc.org/10616): Add program usage message when Abseil
// flags supports it.
// std::string usage =
// "Converts RGBA raw image files to I420 frames for YUV.\n"
// "Example usage:\n" +
// program_name +
// " --frames_dir=. --output_file=output.yuv --width=320 --height=240\n"
// "IMPORTANT: If you pass the --delete_frames command line parameter, the
// " "tool will delete the input frames after conversion.\n" "Command line
// flags:\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" " - frames_dir(string):
// The path to the directory where the frames " "reside." " Default: .\n"
// " - output_file(string): The output file to which frames are written."
// " Default: output.yuv\n"
// " - delete_frames(bool): Whether or not to delete the input frames
// after" " the conversion. Default: false.\n";
webrtc::test::CommandLineParser parser;
// Init the parser and set the usage message
parser.Init(argc, argv);
parser.SetUsageMessage(usage);
parser.SetFlag("width", "-1");
parser.SetFlag("height", "-1");
parser.SetFlag("frames_dir", ".");
parser.SetFlag("output_file", "output.yuv");
parser.SetFlag("delete_frames", "false");
parser.SetFlag("help", "false");
parser.ProcessFlags();
if (parser.GetFlag("help") == "true") {
parser.PrintUsageMessage();
exit(EXIT_SUCCESS);
}
parser.PrintEnteredFlags();
int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10);
int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10);
int width = absl::GetFlag(FLAGS_width);
int height = absl::GetFlag(FLAGS_height);
if (width <= 0 || height <= 0) {
fprintf(stderr, "Error: width or height cannot be <= 0!\n");
return -1;
}
bool del_frames = (parser.GetFlag("delete_frames") == "true") ? true : false;
bool del_frames = absl::GetFlag(FLAGS_delete_frames);
webrtc::test::Converter converter(width, height);
bool success = converter.ConvertRGBAToI420Video(
parser.GetFlag("frames_dir"), parser.GetFlag("output_file"), del_frames);
absl::GetFlag(FLAGS_frames_dir), absl::GetFlag(FLAGS_output_file),
del_frames);
if (success) {
fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n");