vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 | [diff] [blame] | 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 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 | [diff] [blame] | 14 | #include <map> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
kjellander | d2b63cf | 2017-06-30 10:04:59 | [diff] [blame^] | 18 | #include "webrtc/rtc_tools/converter/converter.h" |
| 19 | #include "webrtc/rtc_tools/simple_command_line_parser.h" |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * A command-line tool based on libyuv to convert a set of RGBA files to a YUV |
| 23 | * video. |
| 24 | * Usage: |
| 25 | * rgba_to_i420_converter --frames_dir=<directory_to_rgba_frames> |
| 26 | * --output_file=<output_yuv_file> --width=<width_of_input_frames> |
| 27 | * --height=<height_of_input_frames> |
| 28 | */ |
| 29 | int main(int argc, char** argv) { |
| 30 | std::string program_name = argv[0]; |
| 31 | std::string usage = "Converts RGBA raw image files to I420 frames for YUV.\n" |
| 32 | "Example usage:\n" + program_name + |
| 33 | " --frames_dir=. --output_file=output.yuv --width=320 --height=240\n" |
| 34 | "IMPORTANT: If you pass the --delete_frames command line parameter, the " |
| 35 | "tool will delete the input frames after conversion.\n" |
| 36 | "Command line flags:\n" |
| 37 | " - width(int): Width in pixels of the frames in the input file." |
| 38 | " Default: -1\n" |
| 39 | " - height(int): Height in pixels of the frames in the input file." |
| 40 | " Default: -1\n" |
| 41 | " - frames_dir(string): The path to the directory where the frames reside." |
| 42 | " Default: .\n" |
| 43 | " - output_file(string): The output file to which frames are written." |
| 44 | " Default: output.yuv\n" |
| 45 | " - delete_frames(bool): Whether or not to delete the input frames after" |
| 46 | " the conversion. Default: false.\n"; |
| 47 | |
| 48 | webrtc::test::CommandLineParser parser; |
| 49 | |
| 50 | // Init the parser and set the usage message |
| 51 | parser.Init(argc, argv); |
| 52 | parser.SetUsageMessage(usage); |
| 53 | |
| 54 | parser.SetFlag("width", "-1"); |
| 55 | parser.SetFlag("height", "-1"); |
| 56 | parser.SetFlag("frames_dir", "."); |
| 57 | parser.SetFlag("output_file", "output.yuv"); |
| 58 | parser.SetFlag("delete_frames", "false"); |
| 59 | parser.SetFlag("help", "false"); |
| 60 | |
| 61 | parser.ProcessFlags(); |
| 62 | if (parser.GetFlag("help") == "true") { |
| 63 | parser.PrintUsageMessage(); |
Thiago Farina | 3a93986 | 2015-04-09 13:45:12 | [diff] [blame] | 64 | exit(EXIT_SUCCESS); |
vspasova@webrtc.org | f61dc9b | 2012-08-22 08:12:00 | [diff] [blame] | 65 | } |
| 66 | parser.PrintEnteredFlags(); |
| 67 | |
| 68 | int width = strtol((parser.GetFlag("width")).c_str(), NULL, 10); |
| 69 | int height = strtol((parser.GetFlag("height")).c_str(), NULL, 10); |
| 70 | |
| 71 | if (width <= 0 || height <= 0) { |
| 72 | fprintf(stderr, "Error: width or height cannot be <= 0!\n"); |
| 73 | return -1; |
| 74 | } |
| 75 | |
| 76 | bool del_frames = (parser.GetFlag("delete_frames") == "true") ? true : false; |
| 77 | |
| 78 | webrtc::test::Converter converter(width, height); |
| 79 | bool success = converter.ConvertRGBAToI420Video(parser.GetFlag("frames_dir"), |
| 80 | parser.GetFlag("output_file"), |
| 81 | del_frames); |
| 82 | |
| 83 | if (success) { |
| 84 | fprintf(stdout, "Successful conversion of RGBA frames to YUV video!\n"); |
| 85 | return 0; |
| 86 | } else { |
| 87 | fprintf(stdout, "Unsuccessful conversion of RGBA frames to YUV video!\n"); |
| 88 | return -1; |
| 89 | } |
| 90 | } |