From 8e221ee102d6867f011f58cb8847caa25b43054f Mon Sep 17 00:00:00 2001 From: "vspasova@webrtc.org" Date: Wed, 15 Aug 2012 07:42:00 +0000 Subject: [PATCH] Making the RGBA to I420 tool more useful. Did the following changes: - Made the output file to open in write mode instead of append mode. - Now the tool deletes the RGBA frames after conversion. - Other minor cleanup work. BUG= TEST= rgba_to_i420_converter --frames_dir= --output_file= --width= --height= Review URL: https://webrtc-codereview.appspot.com/728004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2611 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/test/testsupport/converter/converter.cc | 16 ++++++++++++---- src/test/testsupport/converter/converter.h | 5 +++-- .../converter/rgba_to_i420_converter.cc | 18 +++++++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/test/testsupport/converter/converter.cc b/src/test/testsupport/converter/converter.cc index 70b7ea8036..5b84bcf811 100644 --- a/src/test/testsupport/converter/converter.cc +++ b/src/test/testsupport/converter/converter.cc @@ -13,8 +13,8 @@ #include #include -#include "testsupport/converter/converter.h" -#include "testsupport/frame_reader.h" +#include "test/testsupport/converter/converter.h" +#include "test/testsupport/frame_reader.h" #ifdef WIN32 #define SEPARATOR '\\' @@ -33,8 +33,9 @@ Converter::Converter(int width, int height) } bool Converter::ConvertRGBAToI420Video(std::string frames_dir, - std::string output_file_name) { - FILE* output_file = fopen(output_file_name.c_str(), "ab"); + std::string output_file_name, + bool delete_frames) { + FILE* output_file = fopen(output_file_name.c_str(), "wb"); // Open output file in append mode. if (output_file == NULL) { @@ -70,6 +71,13 @@ bool Converter::ConvertRGBAToI420Video(std::string frames_dir, // Read the RGBA frame into rgba_buffer. ReadRGBAFrame(input_file_name.c_str(), input_frame_size, rgba_buffer); + // Delete the input frame. + if (delete_frames) { + if (remove(input_file_name.c_str()) != 0) { + fprintf(stderr, "Cannot delete file %s\n", input_file_name.c_str()); + } + } + // Convert to I420 frame. libyuv::ABGRToI420(rgba_buffer, SrcStrideFrame(), dst_y, DstStrideY(), diff --git a/src/test/testsupport/converter/converter.h b/src/test/testsupport/converter/converter.h index a03fd44598..3c027b08fe 100644 --- a/src/test/testsupport/converter/converter.h +++ b/src/test/testsupport/converter/converter.h @@ -23,9 +23,10 @@ class Converter { public: Converter(int width, int height); - // Converts RGBA to YUV video. + // Converts RGBA to YUV video. If the delete_frames argument is true, the + // method will delete the input frames after conversion. bool ConvertRGBAToI420Video(std::string frames_dir, - std::string output_file_name); + std::string output_file_name, bool delete_frames); private: int width_; // Width of the video (respectively of the RGBA frames). diff --git a/src/test/testsupport/converter/rgba_to_i420_converter.cc b/src/test/testsupport/converter/rgba_to_i420_converter.cc index 8bce66c369..e91d879431 100644 --- a/src/test/testsupport/converter/rgba_to_i420_converter.cc +++ b/src/test/testsupport/converter/rgba_to_i420_converter.cc @@ -10,7 +10,7 @@ #include #include "google/gflags.h" -#include "testsupport/converter/converter.h" +#include "test/testsupport/converter/converter.h" DEFINE_int32(width, -1, "Width in pixels of the frames in the input file."); DEFINE_int32(height, -1, "Height in pixels of the frames in the input file."); @@ -18,6 +18,8 @@ DEFINE_string(frames_dir, ".", "The path to the directory where the frames " "reside"); DEFINE_string(output_file, "./output.yuv", "The output file to which frames are" " written"); +DEFINE_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 @@ -26,26 +28,28 @@ DEFINE_string(output_file, "./output.yuv", "The output file to which frames are" * rgba_to_i420_converter --frames_dir= * --output_file= --width= * --height= - * - * should be an empty file because we open it in append mode */ 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" "Run " + program_name + " --helpshort for usage.\n" "Example usage:\n" + program_name + - " --frames_dir=. --output_file=output.yuv --width=320 --height=240\n"; + " --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."; google::SetUsageMessage(usage); google::ParseCommandLineFlags(&argc, &argv, true); fprintf(stdout, "You entered the following flags: frames_dir=%s, " - "output_file=%s, width=%d, height=%d\n", FLAGS_frames_dir.c_str(), - FLAGS_output_file.c_str(), FLAGS_width, FLAGS_height); + "output_file=%s, width=%d, height=%d, delete_frames=%d\n", + FLAGS_frames_dir.c_str(), FLAGS_output_file.c_str(), + FLAGS_width, FLAGS_height, FLAGS_delete_frames); webrtc::test::Converter converter(FLAGS_width, FLAGS_height); bool success = converter.ConvertRGBAToI420Video(FLAGS_frames_dir, - FLAGS_output_file); + FLAGS_output_file, + FLAGS_delete_frames); if (success) { fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n");