7 #include "packager/app/mpd_generator_flags.h"
8 #include "packager/app/vlog_flags.h"
9 #include "packager/base/at_exit.h"
10 #include "packager/base/command_line.h"
11 #include "packager/base/logging.h"
12 #include "packager/base/strings/string_split.h"
13 #include "packager/base/strings/stringprintf.h"
14 #include "packager/mpd/util/mpd_writer.h"
15 #include "packager/version/version.h"
21 #endif // defined(OS_WIN)
26 "MPD generation driver program.\n"
27 "This program accepts MediaInfo files in human readable text "
28 "format and outputs an MPD.\n"
29 "The main use case for this is to output MPD for VOD.\n"
31 " Each MediaInfo can only have one of VideoInfo, AudioInfo, or TextInfo.\n"
32 " There will be at most 3 AdaptationSets in the MPD, i.e. 1 video, 1 "
33 "audio, and 1 text.\n"
35 "%s --input=\"video1.media_info,video2.media_info,audio1.media_info\" "
36 "--output=\"video_audio.mpd\"";
42 kFailedToWriteMpdToFileError
45 ExitStatus CheckRequiredFlags() {
46 if (FLAGS_input.empty()) {
47 LOG(ERROR) <<
"--input is required.";
48 return kEmptyInputError;
51 if (FLAGS_output.empty()) {
52 LOG(ERROR) <<
"--output is required.";
53 return kEmptyOutputError;
59 ExitStatus RunMpdGenerator() {
60 DCHECK_EQ(CheckRequiredFlags(), kSuccess);
61 std::vector<std::string> base_urls;
62 typedef std::vector<std::string>::const_iterator Iterator;
64 std::vector<std::string> input_files = base::SplitString(
65 FLAGS_input,
",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
67 if (!FLAGS_base_urls.empty()) {
68 base_urls = base::SplitString(FLAGS_base_urls,
",", base::KEEP_WHITESPACE,
69 base::SPLIT_WANT_ALL);
73 for (Iterator it = base_urls.begin(); it != base_urls.end(); ++it)
74 mpd_writer.AddBaseUrl(*it);
76 for (Iterator it = input_files.begin(); it != input_files.end(); ++it) {
77 if (!mpd_writer.AddFile(it->c_str(), FLAGS_output)) {
78 LOG(WARNING) <<
"MpdWriter failed to read " << *it <<
", skipping.";
82 if (!mpd_writer.WriteMpdToFile(FLAGS_output.c_str())) {
83 LOG(ERROR) <<
"Failed to write MPD to " << FLAGS_output;
84 return kFailedToWriteMpdToFileError;
90 int MpdMain(
int argc,
char** argv) {
91 base::AtExitManager exit;
93 base::CommandLine::Init(argc, argv);
96 logging::LoggingSettings log_settings;
97 log_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
98 CHECK(logging::InitLogging(log_settings));
100 google::SetVersionString(GetPackagerVersion());
101 google::SetUsageMessage(base::StringPrintf(kUsage, argv[0]));
102 google::ParseCommandLineFlags(&argc, &argv,
true);
104 ExitStatus status = CheckRequiredFlags();
105 if (status != kSuccess) {
106 google::ShowUsageWithFlags(
"Usage");
110 return RunMpdGenerator();
118 int wmain(
int argc,
wchar_t* argv[],
wchar_t* envp[]) {
119 std::unique_ptr<char* [], std::function<void(char**)>> utf8_argv(
120 new char*[argc], [argc](
char** utf8_args) {
128 std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
129 for (
int idx = 0; idx < argc; ++idx) {
130 std::string utf8_arg(converter.to_bytes(argv[idx]));
132 utf8_argv[idx] =
new char[utf8_arg.size()];
133 memcpy(utf8_argv[idx], &utf8_arg[0], utf8_arg.size());
135 return shaka::MpdMain(argc, utf8_argv.get());
138 int main(
int argc,
char** argv) {
139 return shaka::MpdMain(argc, argv);
141 #endif // !defined(OS_WIN)