]> git.decadent.org.uk Git - videolink.git/blobdiff - generate_dvd.cpp
Added check for missing or empty output file in generate_menu_vob().
[videolink.git] / generate_dvd.cpp
index 1d43a9aba9e9527c1dce6ba1a0a23fd8238b4850..bf1c2b2b80ae8a1ebddd30eadb70003a877bf1d4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2005-6 Ben Hutchings <ben@decadent.org.uk>.
+// Copyright 2005-8 Ben Hutchings <ben@decadent.org.uk>.
 // See the file "COPYING" for licence details.
 
 #include <cerrno>
 #include <sstream>
 #include <stdexcept>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 #include <gdkmm/pixbuf.h>
 #include <glibmm/miscutils.h>
 #include <glibmm/spawn.h>
@@ -234,6 +238,9 @@ void dvd_generator::generate_menu_vob(unsigned index,
     if (!spumux_file)
        throw std::runtime_error("Failed to write control file for spumux");
 
+    std::string output_name(
+       temp_file_name(temp_dir_, "menu-%3d.mpeg", 1 + index));
+
     std::ostringstream command_stream;
     unsigned frame_count(menu_duration_frames(frame_params_));
     if (encoder_ == mpeg_encoder_ffmpeg)
@@ -279,8 +286,7 @@ void dvd_generator::generate_menu_vob(unsigned index,
            " | mplex -v0 -f8 -o/dev/stdout /dev/stdin";
     }
     command_stream
-       << " | spumux -v0 -mdvd " << spumux_name
-       << " > " << temp_file_name(temp_dir_, "menu-%3d.mpeg", 1 + index);
+       << " | spumux -v0 -mdvd " << spumux_name << " > " << output_name;
     std::string command(command_stream.str());
     const char * argv[] = {
        "/bin/sh", "-c", command.c_str(), 0
@@ -295,7 +301,9 @@ void dvd_generator::generate_menu_vob(unsigned index,
                     sigc::slot<void>(),
                     0, 0,
                     &command_result);
-    if (command_result != 0)
+    struct stat stat_buf;
+    if (command_result != 0 || stat(output_name.c_str(), &stat_buf) != 0
+       || stat_buf.st_size == 0)
        throw std::runtime_error("spumux pipeline failed");
 }
 
@@ -376,8 +384,9 @@ void dvd_generator::generate(const std::string & output_dir) const
        const unsigned menu_begin = titleset_num * dvdauthor_anonymous_menus_max;
        const unsigned menu_end =
            have_real_menus
-           ? std::min((titleset_num + 1) * dvdauthor_anonymous_menus_max,
-                      menus_.size())
+           ? std::min<unsigned>(
+               (titleset_num + 1) * dvdauthor_anonymous_menus_max,
+               menus_.size())
            : menu_begin + 1;
 
        for (unsigned menu_index = menu_begin;