7 #include "packager/app/mpd_generator_flags.h"
8 #include "packager/app/vlog_flags.h"
9 #include "packager/base/command_line.h"
10 #include "packager/base/logging.h"
11 #include "packager/base/strings/string_split.h"
12 #include "packager/base/strings/stringprintf.h"
13 #include "packager/mpd/util/mpd_writer.h"
14 #include "packager/version/version.h"
16 namespace edash_packager {
19 "MPD generation driver program.\n"
20 "This program accepts MediaInfo files in human readable text "
21 "format and outputs an MPD.\n"
22 "The main use case for this is to output MPD for VOD.\n"
24 " Each MediaInfo can only have one of VideoInfo, AudioInfo, or TextInfo.\n"
25 " There will be at most 3 AdaptationSets in the MPD, i.e. 1 video, 1 "
26 "audio, and 1 text.\n"
28 "%s --input=\"video1.media_info,video2.media_info,audio1.media_info\" "
29 "--output=\"video_audio.mpd\"";
35 kFailedToWriteMpdToFileError
38 ExitStatus CheckRequiredFlags() {
39 if (FLAGS_input.empty()) {
40 LOG(ERROR) <<
"--input is required.";
41 return kEmptyInputError;
44 if (FLAGS_output.empty()) {
45 LOG(ERROR) <<
"--output is required.";
46 return kEmptyOutputError;
52 ExitStatus RunMpdGenerator() {
53 DCHECK_EQ(CheckRequiredFlags(), kSuccess);
54 std::vector<std::string> base_urls;
55 std::vector<std::string> input_files;
56 typedef std::vector<std::string>::const_iterator Iterator;
58 base::SplitString(FLAGS_input,
',', &input_files);
60 if (!FLAGS_base_urls.empty()) {
61 base::SplitString(FLAGS_base_urls,
',', &base_urls);
65 for (Iterator it = base_urls.begin(); it != base_urls.end(); ++it)
66 mpd_writer.AddBaseUrl(*it);
68 for (Iterator it = input_files.begin(); it != input_files.end(); ++it) {
69 if (!mpd_writer.AddFile(it->c_str(), FLAGS_output)) {
70 LOG(WARNING) <<
"MpdWriter failed to read " << *it <<
", skipping.";
74 if (!mpd_writer.WriteMpdToFile(FLAGS_output.c_str())) {
75 LOG(ERROR) <<
"Failed to write MPD to " << FLAGS_output;
76 return kFailedToWriteMpdToFileError;
82 int MpdMain(
int argc,
char** argv) {
84 base::CommandLine::Init(argc, argv);
85 CHECK(logging::InitLogging(logging::LoggingSettings()));
87 google::SetUsageMessage(base::StringPrintf(kUsage, argv[0]));
88 google::ParseCommandLineFlags(&argc, &argv,
true);
90 ExitStatus status = CheckRequiredFlags();
91 if (status != kSuccess) {
92 std::string version_string =
93 base::StringPrintf(
"mpd_generator version %s", kPackagerVersion);
94 google::ShowUsageWithFlags(version_string.c_str());
98 return RunMpdGenerator();
104 int main(
int argc,
char** argv) {
105 return edash_packager::MpdMain(argc, argv);