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=<directory_to_rgba_frames> --output_file=<output_yuv_file> --width=<width_of_input_frames> --height=<height_of_input_frames> Review URL: https://webrtc-codereview.appspot.com/728004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2611 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -13,8 +13,8 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "testsupport/converter/converter.h"
|
#include "test/testsupport/converter/converter.h"
|
||||||
#include "testsupport/frame_reader.h"
|
#include "test/testsupport/frame_reader.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define SEPARATOR '\\'
|
#define SEPARATOR '\\'
|
||||||
@ -33,8 +33,9 @@ Converter::Converter(int width, int height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Converter::ConvertRGBAToI420Video(std::string frames_dir,
|
bool Converter::ConvertRGBAToI420Video(std::string frames_dir,
|
||||||
std::string output_file_name) {
|
std::string output_file_name,
|
||||||
FILE* output_file = fopen(output_file_name.c_str(), "ab");
|
bool delete_frames) {
|
||||||
|
FILE* output_file = fopen(output_file_name.c_str(), "wb");
|
||||||
|
|
||||||
// Open output file in append mode.
|
// Open output file in append mode.
|
||||||
if (output_file == NULL) {
|
if (output_file == NULL) {
|
||||||
@ -70,6 +71,13 @@ bool Converter::ConvertRGBAToI420Video(std::string frames_dir,
|
|||||||
// Read the RGBA frame into rgba_buffer.
|
// Read the RGBA frame into rgba_buffer.
|
||||||
ReadRGBAFrame(input_file_name.c_str(), input_frame_size, 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.
|
// Convert to I420 frame.
|
||||||
libyuv::ABGRToI420(rgba_buffer, SrcStrideFrame(),
|
libyuv::ABGRToI420(rgba_buffer, SrcStrideFrame(),
|
||||||
dst_y, DstStrideY(),
|
dst_y, DstStrideY(),
|
||||||
|
@ -23,9 +23,10 @@ class Converter {
|
|||||||
public:
|
public:
|
||||||
Converter(int width, int height);
|
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,
|
bool ConvertRGBAToI420Video(std::string frames_dir,
|
||||||
std::string output_file_name);
|
std::string output_file_name, bool delete_frames);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int width_; // Width of the video (respectively of the RGBA frames).
|
int width_; // Width of the video (respectively of the RGBA frames).
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "google/gflags.h"
|
#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(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.");
|
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");
|
"reside");
|
||||||
DEFINE_string(output_file, "./output.yuv", "The output file to which frames are"
|
DEFINE_string(output_file, "./output.yuv", "The output file to which frames are"
|
||||||
" written");
|
" 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
|
* 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=<directory_to_rgba_frames>
|
* rgba_to_i420_converter --frames_dir=<directory_to_rgba_frames>
|
||||||
* --output_file=<output_yuv_file> --width=<width_of_input_frames>
|
* --output_file=<output_yuv_file> --width=<width_of_input_frames>
|
||||||
* --height=<height_of_input_frames>
|
* --height=<height_of_input_frames>
|
||||||
*
|
|
||||||
* <output_yuv_file> should be an empty file because we open it in append mode
|
|
||||||
*/
|
*/
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
std::string program_name = argv[0];
|
std::string program_name = argv[0];
|
||||||
std::string usage = "Converts RGBA raw image files to I420 frames for YUV.\n"
|
std::string usage = "Converts RGBA raw image files to I420 frames for YUV.\n"
|
||||||
"Run " + program_name + " --helpshort for usage.\n"
|
"Run " + program_name + " --helpshort for usage.\n"
|
||||||
"Example usage:\n" + program_name +
|
"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::SetUsageMessage(usage);
|
||||||
|
|
||||||
google::ParseCommandLineFlags(&argc, &argv, true);
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
|
||||||
fprintf(stdout, "You entered the following flags: frames_dir=%s, "
|
fprintf(stdout, "You entered the following flags: frames_dir=%s, "
|
||||||
"output_file=%s, width=%d, height=%d\n", FLAGS_frames_dir.c_str(),
|
"output_file=%s, width=%d, height=%d, delete_frames=%d\n",
|
||||||
FLAGS_output_file.c_str(), FLAGS_width, FLAGS_height);
|
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);
|
webrtc::test::Converter converter(FLAGS_width, FLAGS_height);
|
||||||
bool success = converter.ConvertRGBAToI420Video(FLAGS_frames_dir,
|
bool success = converter.ConvertRGBAToI420Video(FLAGS_frames_dir,
|
||||||
FLAGS_output_file);
|
FLAGS_output_file,
|
||||||
|
FLAGS_delete_frames);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n");
|
fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n");
|
||||||
|
Reference in New Issue
Block a user