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"
15 namespace edash_packager {
18 "MPD generation driver program.\n"
19 "This program accepts MediaInfo files in human readable text "
20 "format and outputs an MPD.\n"
21 "The main use case for this is to output MPD for VOD.\n"
23 " Each MediaInfo can only have one of VideoInfo, AudioInfo, or TextInfo.\n"
24 " There will be at most 3 AdaptationSets in the MPD, i.e. 1 video, 1 "
25 "audio, and 1 text.\n"
27 "%s --input=\"video1.media_info,video2.media_info,audio1.media_info\" "
28 "--output=\"video_audio.mpd\"";
34 kFailedToWriteMpdToFileError
37 ExitStatus CheckRequiredFlags() {
38 if (FLAGS_input.empty()) {
39 LOG(ERROR) <<
"--input is required.";
40 return kEmptyInputError;
43 if (FLAGS_output.empty()) {
44 LOG(ERROR) <<
"--output is required.";
45 return kEmptyOutputError;
51 ExitStatus RunMpdGenerator() {
52 DCHECK_EQ(CheckRequiredFlags(), kSuccess);
53 std::vector<std::string> base_urls;
54 std::vector<std::string> input_files;
55 typedef std::vector<std::string>::const_iterator Iterator;
57 base::SplitString(FLAGS_input,
',', &input_files);
59 if (!FLAGS_base_urls.empty()) {
60 base::SplitString(FLAGS_base_urls,
',', &base_urls);
64 for (Iterator it = base_urls.begin(); it != base_urls.end(); ++it)
65 mpd_writer.AddBaseUrl(*it);
67 for (Iterator it = input_files.begin(); it != input_files.end(); ++it) {
68 if (!mpd_writer.AddFile(it->c_str(), FLAGS_output)) {
69 LOG(WARNING) <<
"MpdWriter failed to read " << *it <<
", skipping.";
73 if (!mpd_writer.WriteMpdToFile(FLAGS_output.c_str())) {
74 LOG(ERROR) <<
"Failed to write MPD to " << FLAGS_output;
75 return kFailedToWriteMpdToFileError;
81 int MpdMain(
int argc,
char** argv) {
83 base::CommandLine::Init(argc, argv);
84 CHECK(logging::InitLogging(logging::LoggingSettings()));
86 google::SetUsageMessage(base::StringPrintf(kUsage, argv[0]));
87 google::ParseCommandLineFlags(&argc, &argv,
true);
89 ExitStatus status = CheckRequiredFlags();
90 if (status != kSuccess) {
91 google::ShowUsageWithFlags(argv[0]);
95 return RunMpdGenerator();
101 int main(
int argc,
char** argv) {
102 return edash_packager::MpdMain(argc, argv);