• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 
14 #include <string>
15 
16 #include "absl/flags/flag.h"
17 #include "absl/flags/parse.h"
18 #include "absl/flags/usage.h"
19 #include "rtc_tools/converter/converter.h"
20 
21 ABSL_FLAG(int, width, -1, "Width in pixels of the frames in the input file");
22 ABSL_FLAG(int, height, -1, "Height in pixels of the frames in the input file");
23 ABSL_FLAG(std::string,
24           frames_dir,
25           ".",
26           "The path to the directory where the frames reside");
27 ABSL_FLAG(std::string,
28           output_file,
29           "output.yuv",
30           " The output file to which frames are written");
31 ABSL_FLAG(bool,
32           delete_frames,
33           false,
34           " Whether or not to delete the input frames after the conversion");
35 
36 /*
37  * A command-line tool based on libyuv to convert a set of RGBA files to a YUV
38  * video.
39  * Usage:
40  * rgba_to_i420_converter --frames_dir=<directory_to_rgba_frames>
41  * --output_file=<output_yuv_file> --width=<width_of_input_frames>
42  * --height=<height_of_input_frames>
43  */
main(int argc,char * argv[])44 int main(int argc, char* argv[]) {
45   absl::SetProgramUsageMessage(
46       "Converts RGBA raw image files to I420 frames "
47       "for YUV.\n"
48       "Example usage:\n"
49       "./rgba_to_i420_converter --frames_dir=. "
50       "--output_file=output.yuv --width=320 "
51       "--height=240\n"
52       "IMPORTANT: If you pass the --delete_frames "
53       "command line parameter, the tool will delete "
54       "the input frames after conversion.\n");
55   absl::ParseCommandLine(argc, argv);
56 
57   int width = absl::GetFlag(FLAGS_width);
58   int height = absl::GetFlag(FLAGS_height);
59 
60   if (width <= 0 || height <= 0) {
61     fprintf(stderr, "Error: width or height cannot be <= 0!\n");
62     return -1;
63   }
64 
65   bool del_frames = absl::GetFlag(FLAGS_delete_frames);
66 
67   webrtc::test::Converter converter(width, height);
68   bool success = converter.ConvertRGBAToI420Video(
69       absl::GetFlag(FLAGS_frames_dir), absl::GetFlag(FLAGS_output_file),
70       del_frames);
71 
72   if (success) {
73     fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n");
74     return 0;
75   } else {
76     fprintf(stdout, "Unsuccessful conversion of RGBA frames to YUV video!\n");
77     return -1;
78   }
79 }
80