make Item::set_position() do nothing if the position doesn't change
[ardour.git] / gtk2_ardour / export_video_dialog.cc
index b1b59fa0888399fe0e26de8a0c1b37fe8eb41336..a9d0f99ad1246623199dd31d4e4d8cfc888dae11 100644 (file)
@@ -28,7 +28,8 @@
 #include <fcntl.h>
 
 #include <sigc++/bind.h>
-#include <libgen.h>
+
+#include <glib/gstdio.h>
 
 #include "pbd/error.h"
 #include "pbd/convert.h"
@@ -62,7 +63,7 @@ using namespace PBD;
 using namespace ARDOUR;
 using namespace VideoUtils;
 
-ExportVideoDialog::ExportVideoDialog (Session* s, TimeSelection &tme)
+ExportVideoDialog::ExportVideoDialog (Session* s, TimeSelection &tme, bool range)
        : ArdourDialog (_("Export Video File "))
        , export_range (tme)
        , outfn_path_label (_("File:"), Gtk::ALIGN_LEFT)
@@ -153,7 +154,11 @@ ExportVideoDialog::ExportVideoDialog (Session* s, TimeSelection &tme)
        if (!export_range.empty()) {
                insnd_combo.append_text (_("Selected range"));  // TODO show export_range.start() -> export_range.end_frame()
        }
-       insnd_combo.set_active(0);
+       if (range) {
+               insnd_combo.set_active(2);
+       } else {
+               insnd_combo.set_active(0);
+       }
 
        outfn_path_entry.set_width_chars(38);
        outfn_path_entry.set_text (_session->session_directory().export_path() + G_DIR_SEPARATOR +"export.avi");
@@ -411,8 +416,8 @@ void
 ExportVideoDialog::finished ()
 {
        if (aborted) {
-               unlink(outfn_path_entry.get_text().c_str());
-               unlink (insnd.c_str());
+               ::g_unlink(outfn_path_entry.get_text().c_str());
+               ::g_unlink (insnd.c_str());
                Gtk::Dialog::response(RESPONSE_CANCEL);
        } else if (twopass && firstpass) {
                firstpass = false;
@@ -422,9 +427,9 @@ ExportVideoDialog::finished ()
                if (twopass_checkbox.get_active()) {
                        std::string outfn = outfn_path_entry.get_text();
                        std::string p2log = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
-                       unlink (p2log.c_str());
+                       ::g_unlink (p2log.c_str());
                }
-               unlink (insnd.c_str());
+               ::g_unlink (insnd.c_str());
                Gtk::Dialog::response(RESPONSE_ACCEPT);
        }
 }
@@ -511,9 +516,8 @@ ExportVideoDialog::launch_export ()
                end += av_offset;
        }
        else if (insnd_combo.get_active_row_number() == 2) {
-               // TODO quantize to video-frame ?!
-               start = export_range.start();
-               end   = export_range.end_frame();
+               start = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv(export_range.start());
+               end   = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv(export_range.end_frame());
        }
        if (end <= 0) {
                start = _session->current_start_frame();
@@ -523,6 +527,15 @@ ExportVideoDialog::launch_export ()
        printf("audio export-range %lld -> %lld\n", start, end);
 #endif
 
+       const frameoffset_t vstart = ARDOUR_UI::instance()->video_timeline->get_offset();
+       const frameoffset_t vend   = vstart + ARDOUR_UI::instance()->video_timeline->get_duration();
+
+       if ( (start >= end) || (end < vstart) || (start > vend)) {
+               warning << _("Export Video: export-range does not include video.") << endmsg;
+               Gtk::Dialog::response(RESPONSE_CANCEL);
+               return;
+       }
+
        tsp->set_range (start, end);
        tsp->set_name ("mysession");
        tsp->set_range_id ("session");
@@ -559,13 +572,13 @@ ExportVideoDialog::launch_export ()
                if (gtk_events_pending()) {
                        gtk_main_iteration ();
                } else {
-                       usleep (10000);
+                       Glib::usleep (10000);
                }
        }
        audio_progress_connection.disconnect();
        status->finish ();
        if (status->aborted()) {
-               unlink (insnd.c_str());
+               ::g_unlink (insnd.c_str());
                Gtk::Dialog::response(RESPONSE_CANCEL);
                return;
        }
@@ -582,14 +595,14 @@ ExportVideoDialog::encode_pass (int pass)
        transcoder = new TranscodeFfmpeg(invid);
        if (!transcoder->ffexec_ok()) {
                /* ffmpeg binary was not found. TranscodeFfmpeg prints a warning */
-               unlink (insnd.c_str());
+               ::g_unlink (insnd.c_str());
                Gtk::Dialog::response(RESPONSE_CANCEL);
                return;
        }
        if (!transcoder->probe_ok()) {
                /* video input file can not be read */
                warning << _("Export Video: Video input file cannot be read.") << endmsg;
-         unlink (insnd.c_str());
+         ::g_unlink (insnd.c_str());
          Gtk::Dialog::response(RESPONSE_CANCEL);
          return;
        }
@@ -687,7 +700,7 @@ ExportVideoDialog::encode_pass (int pass)
                ffs["-an"] = "-y";
                ffs["-passlogfile"] =  Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
                ffs["-f"] = get_file_extension(invid).empty()?"mov":get_file_extension(invid);
-#ifdef _OS_WIN32
+#ifdef PLATFORM_WINDOWS
                outfn = "NUL";
 #else
                outfn = "/dev/null";