7 #include "packager/app/mpd_generator_flags.h"
8 #include "packager/base/logging.h"
9 #include "packager/base/strings/string_split.h"
10 #include "packager/base/strings/stringprintf.h"
11 #include "packager/mpd/util/mpd_writer.h"
13 namespace edash_packager {
16 "MPD generation driver program.\n"
17 "This program accepts MediaInfo files in human readable text "
18 "format and outputs an MPD.\n"
19 "The main use case for this is to output MPD for VOD.\n"
21 " Each MediaInfo can only have one of VideoInfo, AudioInfo, or TextInfo.\n"
22 " There will be at most 3 AdaptationSets in the MPD, i.e. 1 video, 1 "
23 "audio, and 1 text.\n"
25 "%s --input=\"video1.media_info,video2.media_info,audio1.media_info\" "
26 "--output=\"video_audio.mpd\"";
32 kFailedToWriteMpdToFileError
35 ExitStatus CheckRequiredFlags() {
36 if (FLAGS_input.empty()) {
37 LOG(ERROR) <<
"--input is required.";
38 return kEmptyInputError;
41 if (FLAGS_output.empty()) {
42 LOG(ERROR) <<
"--output is required.";
43 return kEmptyOutputError;
49 ExitStatus RunMpdGenerator() {
50 DCHECK_EQ(CheckRequiredFlags(), kSuccess);
51 std::vector<std::string> base_urls;
52 std::vector<std::string> input_files;
53 typedef std::vector<std::string>::const_iterator Iterator;
55 base::SplitString(FLAGS_input,
',', &input_files);
57 if (!FLAGS_base_urls.empty()) {
58 base::SplitString(FLAGS_base_urls,
',', &base_urls);
62 for (Iterator it = base_urls.begin(); it != base_urls.end(); ++it)
63 mpd_writer.AddBaseUrl(*it);
65 for (Iterator it = input_files.begin(); it != input_files.end(); ++it) {
66 if (!mpd_writer.AddFile(it->c_str(), FLAGS_output)) {
67 LOG(WARNING) <<
"MpdWriter failed to read " << *it <<
", skipping.";
71 if (!mpd_writer.WriteMpdToFile(FLAGS_output.c_str())) {
72 LOG(ERROR) <<
"Failed to write MPD to " << FLAGS_output;
73 return kFailedToWriteMpdToFileError;
79 int MpdMain(
int argc,
char** argv) {
80 google::SetUsageMessage(base::StringPrintf(kUsage, argv[0]));
81 google::ParseCommandLineFlags(&argc, &argv,
true);
83 ExitStatus status = CheckRequiredFlags();
84 if (status != kSuccess) {
85 google::ShowUsageWithFlags(argv[0]);
89 return RunMpdGenerator();
95 int main(
int argc,
char** argv) {
96 return edash_packager::MpdMain(argc, argv);