26 #include <sys/types.h>
30 #include <sigc++/bind.h>
32 #include <glib/gstdio.h>
72 , _previous_progress(0)
74 , _video_source_aspect_ratio(-1)
75 , _suspend_signals(false)
76 , outfn_path_label (
_(
"File:"),
Gtk::ALIGN_LEFT)
77 , outfn_browse_button (
_(
"Browse"))
78 , invid_path_label (
_(
"Video:"),
Gtk::ALIGN_LEFT)
79 , invid_browse_button (
_(
"Browse"))
80 , transcode_button (
_(
"Export"))
81 , abort_button (
_(
"Abort"))
83 , scale_checkbox (
_(
"Scale Video (W x H):"))
84 , scale_aspect (
_(
"Retain Aspect"))
85 , width_adjustment (768, 128, 1920, 1, 16, 0)
86 , width_spinner (width_adjustment)
87 , height_adjustment (576, 128, 1920, 1, 16, 0)
88 , height_spinner (height_adjustment)
89 , aspect_checkbox (
_(
"Set Aspect Ratio:"))
90 , normalize_checkbox (
_(
"Normalize Audio"))
91 , twopass_checkbox (
_(
"2 Pass Encoding"))
92 , optimizations_checkbox (
_(
"Codec Optimizations:"))
93 , optimizations_label (
"-")
94 , deinterlace_checkbox (
_(
"Deinterlace"))
95 , bframes_checkbox (
_(
"Use [2] B-frames (MPEG 2 or 4 only)"))
96 , fps_checkbox (
_(
"Override FPS (Default is to retain FPS from the input video file):"))
97 , meta_checkbox (
_(
"Include Session Metadata"))
99 , debug_checkbox (
_(
"Debug Mode: Print ffmpeg command and output to stdout."))
102 set_name (
"ExportVideoDialog");
104 set_skip_taskbar_hint (
true);
105 set_resizable (
false);
108 vbox = manage (
new VBox);
109 VBox* options_box = manage (
new VBox);
115 l = manage (
new Label (
_(
"No ffprobe or ffmpeg executables could be found on this system. Video Export is not possible until you install those tools. See the Log window for more information."), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
117 vbox->pack_start (*l,
false,
false, 8);
118 get_vbox()->pack_start (*
vbox,
false,
false);
119 add_button (Stock::OK, RESPONSE_CANCEL);
120 show_all_children ();
126 l = manage (
new Label (
_(
"<b>Output:</b> (file extension defines format)"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
127 l->set_use_markup ();
128 vbox->pack_start (*l,
false,
false, 4);
130 path_hbox = manage (
new HBox);
134 vbox->pack_start (*path_hbox,
false,
false, 2);
136 l = manage (
new Label (
_(
"<b>Input Video:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
137 l->set_use_markup ();
138 vbox->pack_start (*l,
false,
false, 4);
140 path_hbox = manage (
new HBox);
144 vbox->pack_start (*path_hbox,
false,
false, 2);
146 path_hbox = manage (
new HBox);
147 l = manage (
new Label (
_(
"Audio:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
148 path_hbox->pack_start (*l,
false,
false, 3);
149 l = manage (
new Label (
_(
"Master Bus"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
150 path_hbox->pack_start (*l,
false,
false, 2);
151 vbox->pack_start (*path_hbox,
false,
false, 2);
157 l = manage (
new Label (
_(
"<b>Settings:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
158 l->set_use_markup ();
159 options_box->pack_start (*l,
false,
true, 4);
161 Table* t = manage (
new Table (4, 12));
164 options_box->pack_start (*t,
true,
true, 4);
165 l = manage (
new Label (
_(
"Range:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
166 t->attach (*l, 0, 1, ty, ty+1);
168 l = manage (
new Label (
_(
"Preset:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
169 t->attach (*l, 0, 1, ty, ty+1);
171 l = manage (
new Label (
_(
"Video Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
172 t->attach (*l, 0, 1, ty, ty+1);
174 l = manage (
new Label (
_(
"Video KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
175 t->attach (*l, 2, 3, ty, ty+1);
177 l = manage (
new Label (
_(
"Audio Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
178 t->attach (*l, 0, 1, ty, ty+1);
180 l = manage (
new Label (
_(
"Audio KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
181 t->attach (*l, 2, 3, ty, ty+1);
183 l = manage (
new Label (
_(
"Audio Samplerate:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER,
false));
184 t->attach (*l, 0, 1, ty, ty+1);
192 t->attach (
fps_combo, 3, 4, ty, ty+1); ty++;
273 vbox->pack_start (*options_box,
false,
true, 4);
274 get_vbox()->set_spacing (4);
275 get_vbox()->pack_start (*
vbox,
false,
false);
298 show_all_children ();
317 if (infile ==
"" || !Glib::file_test(infile, Glib::FILE_TEST_EXISTS)) {
343 if (av_offset < 0 ) {
344 insnd_combo.append_text (
_(
"from 00:00:00:00 to the video's end"));
346 insnd_combo.append_text (
_(
"from the video's start to the video's end"));
381 bool filenameset =
false;
383 if (node->
property(
X_(
"OriginalVideoFile"))) {
384 std::string filename = node->
property(
X_(
"OriginalVideoFile"))->
value();
385 if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
397 if (filename.at(0) != G_DIR_SEPARATOR)
401 if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS))
425 prop = node->
property (
X_(
"CodecOptimzations"));
465 if (fabs(tcfps - 23.976) < 0.01) {
fps_combo.set_active(0); }
466 else if (fabs(tcfps - 24.0 ) < 0.01) {
fps_combo.set_active(1); }
467 else if (fabs(tcfps - 24.976) < 0.01) {
fps_combo.set_active(2); }
468 else if (fabs(tcfps - 25.0 ) < 0.01) {
fps_combo.set_active(3); }
469 else if (fabs(tcfps - 29.97 ) < 0.01) {
fps_combo.set_active(4); }
470 else if (fabs(tcfps - 30.0 ) < 0.01) {
fps_combo.set_active(5); }
471 else if (fabs(tcfps - 59.94 ) < 0.01) {
fps_combo.set_active(6); }
472 else if (fabs(tcfps - 60.0 ) < 0.01) {
fps_combo.set_active(7); }
485 show_all_children ();
547 if (a == 0 || c > a) {
548 pbar.set_pulse_step(.1);
551 double progress = (double)c / (
double) a;
558 pbar.set_fraction (progress);
566 std::string status_text;
567 double progress = 0.0;
569 pbar.set_text (
_(
"Normalizing audio"));
573 pbar.set_text (
_(
"Exporting audio"));
583 pbar.set_fraction (progress);
592 ::g_unlink (
_insnd.c_str());
594 Gtk::Dialog::response(RESPONSE_CANCEL);
602 std::string p2log = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR +
"ffmpeg2pass";
603 ::g_unlink (p2log.c_str());
605 ::g_unlink (
_insnd.c_str());
607 Gtk::Dialog::response(RESPONSE_ACCEPT);
627 pbar.set_size_request(300,-1);
628 pbar.set_text(
_(
"Exporting Audio..."));
642 std::string vtl_normalize =
_normalize ?
"true" :
"false";
644 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
645 "<ExportFormatSpecification name=\"VTL-WAV-16\" id=\"3094591e-ccb9-4385-a93f-c9955ffeb1f0\">"
646 " <Encoding id=\"F_WAV\" type=\"T_Sndfile\" extension=\"wav\" name=\"WAV\" has-sample-format=\"true\" channel-limit=\"256\"/>"
647 " <SampleRate rate=\""+ vtl_samplerate +
"\"/>"
648 " <SRCQuality quality=\"SRC_SincBest\"/>"
650 " <Option name=\"sample-format\" value=\"SF_16\"/>"
651 " <Option name=\"dithering\" value=\"D_None\"/>"
652 " <Option name=\"tag-metadata\" value=\"true\"/>"
653 " <Option name=\"tag-support\" value=\"false\"/>"
654 " <Option name=\"broadcast-info\" value=\"false\"/>"
655 " </EncodingOptions>"
657 " <Normalize enabled=\""+ vtl_normalize +
"\" target=\"0\"/>"
660 " <Trim enabled=\"false\"/>"
661 " <Add enabled=\"false\">"
662 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
666 " <Trim enabled=\"false\"/>"
667 " <Add enabled=\"false\">"
668 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
673 "</ExportFormatSpecification>"
685 warning <<
_(
"Export Video: Cannot query duration of video-file, using duration from timeline instead.") <<
endmsg;
692 printf(
"audio-range -- AV offset: %lld\n", av_offset);
699 else if (
insnd_combo.get_active_row_number() == 2) {
708 printf(
"audio export-range %lld -> %lld\n", start, end);
714 if ( (start >= end) || (end < vstart) || (start > vend)) {
715 warning <<
_(
"Export Video: export-range does not include video.") <<
endmsg;
717 Gtk::Dialog::response(RESPONSE_CANCEL);
721 tsp->set_range (start, end);
722 tsp->set_name (
"mysession");
723 tsp->set_range_id (
"session");
728 warning <<
_(
"Export Video: No Master Out Ports to Connect for Audio Export") <<
endmsg;
730 Gtk::Dialog::response(RESPONSE_CANCEL);
756 if (gtk_events_pending()) {
757 gtk_main_iteration ();
759 Glib::usleep (10000);
765 ::g_unlink (
_insnd.c_str());
767 Gtk::Dialog::response(RESPONSE_CANCEL);
770 pbar.set_text (
_(
"Encoding Video..."));
783 ::g_unlink (
_insnd.c_str());
785 Gtk::Dialog::response(RESPONSE_CANCEL);
790 warning <<
_(
"Export Video: Video input file cannot be read.") <<
endmsg;
791 ::g_unlink (
_insnd.c_str());
793 Gtk::Dialog::response(RESPONSE_CANCEL);
821 ffs[
"-qscale"] =
"0";
831 ffs[
"-strict"] =
"-2";
835 ffs[
"-vcodec"] =
"libx264";
838 ffs[
"-vcodec"] =
"libvpx";
847 ffs[
"-trellis"] =
"2";
849 ffs[
"-subcmp"] =
"2";
853 ffs[
"-flags"] =
"+mv4+aic";
854 ffs[
"-trellis"] =
"2";
856 ffs[
"-subcmp"] =
"2";
862 ffs[
"-subcmp"] =
"2";
863 ffs[
"-trellis"] =
"2";
864 ffs[
"-flags"] =
"+aic+mv0+mv4";
876 if (preset ==
"dvd-PAL") {
878 ffs[
"-target"] =
"pal-dvd";
879 ffs[
"-aspect"] =
"4:3";
881 else if (preset ==
"dvd-NTSC") {
883 ffs[
"-target"] =
"ntsc-dvd";
884 ffs[
"-aspect"] =
"4:3";
891 ffs[
"-deinterlace"] =
"-y";
896 pbar.set_text (
_(
"Encoding Video.. Pass 1/2"));
900 ffs[
"-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR +
"ffmpeg2pass";
902 #ifdef PLATFORM_WINDOWS
907 }
else if (pass == 2) {
908 pbar.set_text (
_(
"Encoding Video.. Pass 2/2"));
910 ffs[
"-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR +
"ffmpeg2pass";
914 double duration_s = 0;
920 }
else if (
insnd_combo.get_active_row_number() == 2) {
926 if (av_offset < 0 ) {
927 duration_f += av_offset;
932 std::ostringstream osstream; osstream << duration_s;
933 ffs[
"-t"] = osstream.str();
948 printf(
"AV offset: %lld Vid-len: %lld Vid-end: %lld || start:%lld || end:%lld\n",
949 av_offset, vid_duration, av_offset+vid_duration, start, snend);
952 if (av_offset > start && av_offset + vid_duration < snend) {
955 }
else if (av_offset > start) {
957 }
else if (av_offset + vid_duration < snend) {
962 else if (start > av_offset) {
964 ffs[
"-ss"] = osstream.str();
971 }
else if (av_offset < 0) {
979 if (session_data->
year() > 0 ) {
980 std::ostringstream osstream; osstream << session_data->
year();
981 meta[
"year"] = osstream.str();
984 std::ostringstream osstream; osstream << session_data->
track_number();
985 meta[
"track"] = osstream.str();
988 std::ostringstream osstream; osstream << session_data->
disc_number();
989 meta[
"disc"] = osstream.str();
991 if (!session_data->
title().empty()) {meta[
"title"] = session_data->
title();}
992 if (!session_data->
artist().empty()) {meta[
"author"] = session_data->
artist();}
994 if (!session_data->
album().empty()) {meta[
"album"] = session_data->
album();}
995 if (!session_data->
genre().empty()) {meta[
"genre"] = session_data->
genre();}
996 if (!session_data->
composer().empty()) {meta[
"composer"] = session_data->
composer();}
997 if (!session_data->
comment().empty()) {meta[
"comment"] = session_data->
comment();}
998 if (!session_data->
copyright().empty()) {meta[
"copyright"] = session_data->
copyright();}
999 if (!session_data->
subtitle().empty()) {meta[
"description"] = session_data->
subtitle();}
1013 Gtk::Dialog::response(RESPONSE_CANCEL);
1021 if (ext ==
"")
return;
1100 optimizations_label.set_text(
"-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300");
1102 optimizations_label.set_text(
"-mbd 2 -cmp 2 -subcmp 2 -trellis 2 -flags +aic+mv0+mv4 -g 160");
1128 else if (p ==
"you-tube") {
1140 else if (p ==
"ogg") {
1152 else if (p ==
"webm") {
1164 else if (p ==
"dvd-mp2") {
1172 else if (p ==
"dvd-NTSC" || p ==
"dvd-PAL") {
1183 else if (p ==
"mpeg4") {
1195 else if (p ==
"mp4/h264/aac") {
1222 Gtk::Table *t = (Gtk::Table*)
preset_combo.get_parent();
1223 Gtk::Table_Helpers::TableList c = t->children();
1224 Gtk::Table_Helpers::TableList::iterator it;
1225 if (p ==
"dvd-PAL" || p ==
"dvd-NTSC") {
1226 for (it = c.begin(); it != c.end(); ++it) {
1227 int row = it->get_top_attach();
1228 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
1229 it->get_widget()->hide();
1233 for (it = c.begin(); it != c.end(); ++it) {
1234 int row = it->get_top_attach();
1235 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
1236 it->get_widget()->show();
1247 Gtk::FileChooserDialog dialog(
_(
"Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1250 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1251 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
1253 int result = dialog.run();
1255 if (result == Gtk::RESPONSE_OK) {
1256 std::string filename = dialog.get_filename();
1258 if (filename.length()) {
1267 Gtk::FileChooserDialog dialog(
_(
"Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1270 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1271 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
1273 int result = dialog.run();
1275 if (result == Gtk::RESPONSE_OK) {
1276 std::string filename = dialog.get_filename();
1278 if (filename.length()) {
Gtk::ComboBoxText video_bitrate_combo
void update_progress(ARDOUR::framecnt_t, ARDOUR::framecnt_t)
bool add_export_config(ExportTimespanPtr timespan, ExportChannelConfigPtr channel_config, ExportFormatSpecPtr format, ExportFilenamePtr filename, BroadcastInfoPtr broadcast_info)
double timecode_frames_per_second() const
framecnt_t nominal_frame_rate() const
void abort(bool error_occurred=false)
int atoi(const string &s)
Gtk::CheckButton aspect_checkbox
ARDOUR::frameoffset_t get_offset()
ExportChannelConfigPtr add_channel_config()
ExportTimespanPtr add_timespan()
TimeSelection export_range
Gtk::CheckButton scale_aspect
void aspect_checkbox_toggled()
const std::string & value() const
Gtk::CheckButton debug_checkbox
Gtk::Entry invid_path_entry
wrapper around ffmpeg and ffprobe command-line utils
volatile framecnt_t processed_frames_current_timespan
Gtk::Button * cancel_button
const std::string video_path() const
void scale_checkbox_toggled()
static ARDOUR_UI * instance()
Gtk::Button outfn_browse_button
std::string strip_file_extension(const std::string infile)
Gtk::ComboBoxText fps_combo
Gtk::CheckButton twopass_checkbox
Gtk::ComboBoxText aspect_combo
Gtk::Button transcode_button
Gtk::Label outfn_path_label
volatile framecnt_t total_frames_current_timespan
void set_duration(ARDOUR::framecnt_t d)
ARDOUR::framepos_t end_frame()
Gtk::SpinButton height_spinner
Basic export channel that reads from AudioPorts.
LIBPBD_API Transmitter warning
boost::shared_ptr< ARDOUR::ExportStatus > status
Gtk::CheckButton bframes_checkbox
gint audio_progress_display()
std::ostream & endmsg(std::ostream &ostr)
bool encode(std::string outfile, std::string inf_a, std::string inf_v, FFSettings ffs, FFSettings meta, bool map=true)
Gtk::CheckButton fps_checkbox
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
ARDOUR::frameoffset_t quantify_frames_to_apv(ARDOUR::frameoffset_t offset)
boost::shared_ptr< ExportStatus > get_export_status()
bool read_buffer(const std::string &)
Gtk::Button invid_browse_button
boost::shared_ptr< AudioPort > audio(uint32_t n) const
boost::shared_ptr< ExportHandler > get_export_handler()
sigc::connection audio_progress_connection
void fps_checkbox_toggled()
PBD::Signal2< void, ARDOUR::framecnt_t, ARDOUR::framecnt_t > Progress
void video_codec_combo_changed()
std::string get_path(ExportFormatSpecPtr format) const
const ChanCount & n_ports() const
XMLProperty * property(const char *)
bool confirm_video_outfn(std::string, std::string docroot="")
VideoTimeLine * video_timeline
std::map< std::string, std::string > FFSettings
Gtk::CheckButton meta_checkbox
Gtk::ComboBoxText audio_bitrate_combo
Gtk::Entry outfn_path_entry
void preset_combo_changed()
TranscodeFfmpeg * _transcoder
void set_leadinout(double lead_in, double lead_out)
boost::shared_ptr< Route > master_out() const
void width_value_changed()
void add_port(boost::weak_ptr< AudioPort > port)
void change_file_extension(std::string)
common functions used for video-file im/export
float _video_source_aspect_ratio
Gtk::CheckButton optimizations_checkbox
Gtk::CheckButton normalize_checkbox
volatile uint32_t total_normalize_cycles
Gtk::Label invid_path_label
void set_timespan(ExportTimespanPtr ts)
Gtk::CheckButton deinterlace_checkbox
Gtk::ComboBoxText preset_combo
XMLProperty * add_property(const char *name, const std::string &value)
void register_channel(ExportChannelPtr channel)
const std::string export_path() const
Gtk::ComboBoxText audio_samplerate_combo
Gtk::CheckButton scale_checkbox
ARDOUR::framepos_t start()
ARDOUR::framepos_t length()
Gtk::ComboBoxText audio_codec_combo
framepos_t current_end_frame() const
void set_debug(bool onoff)
void height_value_changed()
framepos_t current_start_frame() const
Gtk::ComboBoxText video_codec_combo
Gtk::Label optimizations_label
void set_avoffset(double av_offset)
XMLNode * extra_xml(const std::string &str, bool add_if_missing=false)
void set_state(const XMLNode &)
ARDOUR::framecnt_t get_duration()
ExportFilenamePtr add_filename()
PBD::Signal0< void > Finished
boost::shared_ptr< IO > output() const
void set_original_file_information()
const SessionDirectory & session_directory() const
void add_extra_xml(XMLNode &)
Gtk::SpinButton width_spinner
std::string get_file_extension(const std::string infile)
volatile uint32_t current_normalize_cycle
void apply_state(TimeSelection &tme, bool range)
volatile bool normalizing
ARDOUR::Session * _session
FFSettings default_meta_data()
void set_label(std::string value)
std::string string_compose(const std::string &fmt, const T1 &o1)
ExportFormatSpecPtr add_format()
double atof(const string &s)
ARDOUR::framecnt_t get_duration()
Gtk::ComboBoxText insnd_combo
void popup_error(const std::string &text)