2 Copyright (C) 2010 Paul Davis
3 Author: Robin Gareus <robin@gareus.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <sys/types.h>
30 #include <sigc++/bind.h>
33 #include <glib/gstdio.h>
35 #include "pbd/error.h"
36 #include "pbd/convert.h"
37 #include "gtkmm2ext/utils.h"
38 #include "ardour/session_directory.h"
39 #include "ardour/profile.h"
40 #include "ardour/template_utils.h"
41 #include "ardour/session.h"
42 #include "ardour_ui.h"
43 #include "gui_thread.h"
45 #include "ardour/export_handler.h"
46 #include "ardour/export_status.h"
47 #include "ardour/export_timespan.h"
48 #include "ardour/export_channel_configuration.h"
49 #include "ardour/export_format_specification.h"
50 #include "ardour/export_filename.h"
51 #include "ardour/route.h"
52 #include "ardour/session_metadata.h"
53 #include "ardour/broadcast_info.h"
57 #include "export_video_dialog.h"
58 #include "utils_videotl.h"
64 using namespace ARDOUR;
65 using namespace VideoUtils;
67 ExportVideoDialog::ExportVideoDialog (PublicEditor& ed, Session* s)
68 : ArdourDialog (_("Export Video File "))
70 , outfn_path_label (_("File:"), Gtk::ALIGN_LEFT)
71 , outfn_browse_button (_("Browse"))
72 , invid_path_label (_("Video:"), Gtk::ALIGN_LEFT)
73 , invid_browse_button (_("Browse"))
74 , transcode_button (_("Export"))
75 , abort_button (_("Abort"))
76 , scale_checkbox (_("Scale Video (W x H):"))
77 , width_adjustment (768, 128, 1920, 1, 16, 0)
78 , width_spinner (width_adjustment)
79 , height_adjustment (576, 128, 1920, 1, 16, 0)
80 , height_spinner (height_adjustment)
81 , aspect_checkbox (_("Set Aspect Ratio:"))
82 , normalize_checkbox (_("Normalize Audio"))
83 , twopass_checkbox (_("2 Pass Encoding"))
84 , optimizations_checkbox (_("Codec Optimizations:"))
85 , optimizations_label ("-")
86 , deinterlace_checkbox (_("Deinterlace"))
87 , bframes_checkbox (_("Use [2] B-frames (MPEG 2 or 4 only)"))
88 , fps_checkbox (_("Override FPS (Default is to retain FPS from the input video file):"))
89 , meta_checkbox (_("Include Session Metadata"))
90 #if 1 /* tentative debug mode */
91 , debug_checkbox (_("Debug Mode: Print ffmpeg command and output to stdout."))
96 set_name ("ExportVideoDialog");
98 set_skip_taskbar_hint (true);
99 set_resizable (false);
102 vbox = manage (new VBox);
103 VBox* options_box = manage (new VBox);
106 /* check if ffmpeg can be found */
107 transcoder = new TranscodeFfmpeg("");
108 if (!transcoder->ffexec_ok()) {
109 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));
111 vbox->pack_start (*l, false, false, 8);
112 get_vbox()->pack_start (*vbox, false, false);
113 add_button (Stock::OK, RESPONSE_CANCEL);
114 show_all_children ();
117 delete transcoder; transcoder = 0;
119 l = manage (new Label (_("<b>Output:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
120 l->set_use_markup ();
121 vbox->pack_start (*l, false, false, 4);
123 path_hbox = manage (new HBox);
124 path_hbox->pack_start (outfn_path_label, false, false, 3);
125 path_hbox->pack_start (outfn_path_entry, true, true, 3);
126 path_hbox->pack_start (outfn_browse_button, false, false, 3);
127 vbox->pack_start (*path_hbox, false, false, 2);
129 l = manage (new Label (_("<b>Input:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
130 l->set_use_markup ();
131 vbox->pack_start (*l, false, false, 4);
133 path_hbox = manage (new HBox);
134 path_hbox->pack_start (invid_path_label, false, false, 3);
135 path_hbox->pack_start (invid_path_entry, true, true, 3);
136 path_hbox->pack_start (invid_browse_button, false, false, 3);
137 vbox->pack_start (*path_hbox, false, false, 2);
139 path_hbox = manage (new HBox);
140 l = manage (new Label (_("Audio:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
141 path_hbox->pack_start (*l, false, false, 3);
142 l = manage (new Label (_("Master Bus"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
143 path_hbox->pack_start (*l, false, false, 2);
144 vbox->pack_start (*path_hbox, false, false, 2);
146 insnd_combo.set_name ("PaddedButton");
147 insnd_combo.append_text (string_compose (_("from the %1 session's start to the session's end"), PROGRAM_NAME));
149 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
150 if (av_offset < 0 ) {
151 insnd_combo.append_text (_("from 00:00:00:00 to the video's end"));
153 insnd_combo.append_text (_("from the video's start to the video's end"));
155 insnd_combo.set_active(0);
157 outfn_path_entry.set_width_chars(38);
158 outfn_path_entry.set_text (_session->session_directory().export_path() + G_DIR_SEPARATOR +"export.avi");
160 XMLNode* node = _session->extra_xml (X_("Videotimeline"));
162 bool filenameset = false;
163 if (node->property(X_("OriginalVideoFile"))) {
164 std::string filename = node->property(X_("OriginalVideoFile"))->value();
165 if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
166 invid_path_entry.set_text (filename);
171 && node->property(X_("Filename"))
172 && node->property(X_("LocalFile"))
173 && node->property(X_("LocalFile"))->value() == X_("1")
175 std::string filename = node->property(X_("Filename"))->value();
176 if (filename.at(0) != G_DIR_SEPARATOR) {
177 filename = Glib::build_filename (_session->session_directory().video_path(), filename);
179 if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
180 invid_path_entry.set_text (filename);
185 invid_path_entry.set_text (X_(""));
189 l = manage (new Label (_("<b>Settings:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
190 l->set_use_markup ();
191 options_box->pack_start (*l, false, true, 4);
193 Table* t = manage (new Table (4, 12));
196 options_box->pack_start (*t, true, true, 4);
197 l = manage (new Label (_("Range:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
198 t->attach (*l, 0, 1, ty, ty+1);
199 t->attach (insnd_combo, 1, 4, ty, ty+1); ty++;
200 l = manage (new Label (_("Preset:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
201 t->attach (*l, 0, 1, ty, ty+1);
202 t->attach (preset_combo, 1, 4, ty, ty+1); ty++;
203 l = manage (new Label (_("Video Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
204 t->attach (*l, 0, 1, ty, ty+1);
205 t->attach (video_codec_combo, 1, 2, ty, ty+1);
206 l = manage (new Label (_("Video KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
207 t->attach (*l, 2, 3, ty, ty+1);
208 t->attach (video_bitrate_combo, 3, 4, ty, ty+1); ty++;
209 l = manage (new Label (_("Audio Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
210 t->attach (*l, 0, 1, ty, ty+1);
211 t->attach (audio_codec_combo, 1, 2, ty, ty+1);
212 l = manage (new Label (_("Audio KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
213 t->attach (*l, 2, 3, ty, ty+1);
214 t->attach (audio_bitrate_combo, 3, 4, ty, ty+1); ty++;
215 l = manage (new Label (_("Audio Samplerate:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
216 t->attach (*l, 0, 1, ty, ty+1);
217 t->attach (audio_samplerate_combo, 1, 2, ty, ty+1);
218 t->attach (normalize_checkbox, 2, 4, ty, ty+1); ty++;
219 t->attach (scale_checkbox, 0, 2, ty, ty+1);
220 t->attach (width_spinner, 2, 3, ty, ty+1);
221 t->attach (height_spinner, 3, 4, ty, ty+1); ty++;
222 t->attach (fps_checkbox, 0, 3, ty, ty+1);
223 t->attach (fps_combo, 3, 4, ty, ty+1); ty++;
224 t->attach (twopass_checkbox, 0, 2, ty, ty+1);
225 t->attach (aspect_checkbox, 2, 3, ty, ty+1);
226 t->attach (aspect_combo, 3, 4, ty, ty+1); ty++;
227 t->attach (bframes_checkbox, 0, 2, ty, ty+1);
228 t->attach (deinterlace_checkbox, 2, 4, ty, ty+1); ty++;
229 t->attach (meta_checkbox, 2, 4, ty, ty+1); ty++;
230 t->attach (optimizations_checkbox, 0, 1, ty, ty+1);
231 t->attach (optimizations_label, 1, 4, ty, ty+1); ty++;
232 #if 1 /* tentative debug mode */
233 t->attach (debug_checkbox, 0, 4, ty, ty+1); ty++;
236 preset_combo.set_name ("PaddedButton");
237 preset_combo.append_text("none");
238 preset_combo.append_text("dvd-mp2");
239 preset_combo.append_text("dvd-NTSC");
240 preset_combo.append_text("dvd-PAL");
241 preset_combo.append_text("flv");
242 preset_combo.append_text("mpeg4");
243 preset_combo.append_text("ogg");
244 preset_combo.append_text("you-tube");
245 preset_combo.set_active(0);
247 audio_codec_combo.set_name ("PaddedButton");
248 audio_codec_combo.append_text("ac3");
249 audio_codec_combo.append_text("aac");
250 audio_codec_combo.append_text("libmp3lame");
251 audio_codec_combo.append_text("libvorbis");
252 audio_codec_combo.append_text("mp2");
253 audio_codec_combo.append_text("pcm_s16le");
254 audio_codec_combo.set_active(2);
256 video_codec_combo.set_name ("PaddedButton");
257 video_codec_combo.append_text("flv");
258 video_codec_combo.append_text("libtheora");
259 video_codec_combo.append_text("mjpeg");
260 video_codec_combo.append_text("mpeg2video");
261 video_codec_combo.append_text("mpeg4");
262 video_codec_combo.append_text("h264");
263 video_codec_combo.append_text("vpx (webm)");
264 video_codec_combo.append_text("copy");
265 video_codec_combo.set_active(4);
267 audio_bitrate_combo.set_name ("PaddedButton");
268 audio_bitrate_combo.append_text("64k");
269 audio_bitrate_combo.append_text("128k");
270 audio_bitrate_combo.append_text("192k");
271 audio_bitrate_combo.append_text("256k");
272 audio_bitrate_combo.append_text("320k");
273 audio_bitrate_combo.set_active(2);
275 audio_samplerate_combo.set_name ("PaddedButton");
276 audio_samplerate_combo.append_text("22050");
277 audio_samplerate_combo.append_text("44100");
278 audio_samplerate_combo.append_text("48000");
279 audio_samplerate_combo.set_active(2);
281 video_bitrate_combo.set_name ("PaddedButton");
282 video_bitrate_combo.append_text("200k");
283 video_bitrate_combo.append_text("800k");
284 video_bitrate_combo.append_text("2000k");
285 video_bitrate_combo.append_text("5000k");
286 video_bitrate_combo.append_text("8000k");
287 video_bitrate_combo.append_text("retain");
288 video_bitrate_combo.set_active(3);
290 fps_combo.set_name ("PaddedButton");
291 fps_combo.append_text("23.976");
292 fps_combo.append_text("24");
293 fps_combo.append_text("24.976");
294 fps_combo.append_text("25");
295 fps_combo.append_text("29.97");
296 fps_combo.append_text("30");
297 fps_combo.append_text("59.94");
298 fps_combo.append_text("60");
299 float tcfps = _session->timecode_frames_per_second();
300 if (fabs(tcfps - 23.976) < 0.01) { fps_combo.set_active(0); }
301 else if (fabs(tcfps - 24.0 ) < 0.01) { fps_combo.set_active(1); }
302 else if (fabs(tcfps - 24.976) < 0.01) { fps_combo.set_active(2); }
303 else if (fabs(tcfps - 25.0 ) < 0.01) { fps_combo.set_active(3); }
304 else if (fabs(tcfps - 29.97 ) < 0.01) { fps_combo.set_active(4); }
305 else if (fabs(tcfps - 30.0 ) < 0.01) { fps_combo.set_active(5); }
306 else if (fabs(tcfps - 59.94 ) < 0.01) { fps_combo.set_active(6); }
307 else if (fabs(tcfps - 60.0 ) < 0.01) { fps_combo.set_active(7); }
308 else { fps_combo.set_active(5); }
310 aspect_combo.set_name ("PaddedButton");
311 aspect_combo.append_text("4:3");
312 aspect_combo.append_text("16:9");
313 aspect_combo.set_active(1);
315 optimizations_checkbox.set_sensitive(false);
316 scale_checkbox_toggled();
317 aspect_checkbox_toggled();
318 fps_checkbox_toggled();
319 video_codec_combo_changed();
321 vbox->pack_start (*options_box, false, true, 4);
322 get_vbox()->set_spacing (4);
323 get_vbox()->pack_start (*vbox, false, false);
325 progress_box = manage (new VBox);
326 progress_box->pack_start (pbar, false, false);
327 progress_box->pack_start (abort_button, false, false);
328 get_vbox()->pack_start (*progress_box, false, false);
330 scale_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::scale_checkbox_toggled));
331 aspect_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::aspect_checkbox_toggled));
332 fps_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::fps_checkbox_toggled));
333 preset_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportVideoDialog::preset_combo_changed));
334 video_codec_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportVideoDialog::video_codec_combo_changed));
335 outfn_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::open_outfn_dialog));
336 invid_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::open_invid_dialog));
337 transcode_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::launch_export));
338 abort_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::abort_clicked));
340 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
341 get_action_area()->pack_start (transcode_button, false, false);
342 show_all_children ();
343 progress_box->hide();
346 ExportVideoDialog::~ExportVideoDialog ()
348 if (transcoder) { delete transcoder; transcoder = 0;}
352 ExportVideoDialog::on_show ()
358 ExportVideoDialog::abort_clicked ()
362 transcoder->cancel();
367 ExportVideoDialog::update_progress (framecnt_t c, framecnt_t a)
369 if (a == 0 || c > a) {
370 pbar.set_pulse_step(.1);
373 double progress = (double)c / (double) a;
374 progress = progress / ((twopass ? 2.0 : 1.0) + (normalize ? 2.0 : 1.0));
375 if (normalize && twopass) progress += (firstpass ? .5 : .75);
376 else if (normalize) progress += 2.0/3.0;
377 else if (twopass) progress += (firstpass ? 1.0/3.0 : 2.0/3.0);
380 pbar.set_fraction (progress);
386 ExportVideoDialog::audio_progress_display ()
388 std::string status_text;
389 double progress = 0.0;
390 if (status->normalizing) {
391 pbar.set_text (_("Normalizing audio"));
392 progress = ((float) status->current_normalize_cycle) / status->total_normalize_cycles;
393 progress = progress / (twopass ? 4.0 : 3.0) + (twopass ? .25 : 1.0/3.0);
395 pbar.set_text (_("Exporting audio"));
396 progress = ((float) status->processed_frames_current_timespan) / status->total_frames_current_timespan;
397 progress = progress / ((twopass ? 2.0 : 1.0) + (normalize ? 2.0 : 1.0));
399 if (progress < previous_progress) {
400 // Work around gtk bug
404 previous_progress = progress;
405 pbar.set_fraction (progress);
410 ExportVideoDialog::finished ()
413 ::g_unlink(outfn_path_entry.get_text().c_str());
414 ::g_unlink (insnd.c_str());
415 Gtk::Dialog::response(RESPONSE_CANCEL);
416 } else if (twopass && firstpass) {
418 if (transcoder) { delete transcoder; transcoder = 0;}
421 if (twopass_checkbox.get_active()) {
422 std::string outfn = outfn_path_entry.get_text();
423 std::string p2log = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
424 ::g_unlink (p2log.c_str());
426 ::g_unlink (insnd.c_str());
427 Gtk::Dialog::response(RESPONSE_ACCEPT);
432 ExportVideoDialog::launch_export ()
434 std::string outfn = outfn_path_entry.get_text();
435 if (!confirm_video_outfn(outfn)) { return; }
438 cancel_button->hide();
439 transcode_button.hide();
440 pbar.set_size_request(300,-1);
441 pbar.set_text(_("Exporting Audio..."));
442 progress_box->show();
444 twopass = twopass_checkbox.get_active();
446 normalize = normalize_checkbox.get_active();
448 /* export audio track */
449 ExportTimespanPtr tsp = _session->get_export_handler()->add_timespan();
450 boost::shared_ptr<ExportChannelConfiguration> ccp = _session->get_export_handler()->add_channel_config();
451 boost::shared_ptr<ARDOUR::ExportFilename> fnp = _session->get_export_handler()->add_filename();
452 boost::shared_ptr<AudioGrapher::BroadcastInfo> b;
454 std::string vtl_samplerate = audio_samplerate_combo.get_active_text();
455 std::string vtl_normalize = normalize ? "true" : "false";
456 tree.read_buffer(std::string(
457 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
458 "<ExportFormatSpecification name=\"VTL-WAV-16\" id=\"3094591e-ccb9-4385-a93f-c9955ffeb1f0\">"
459 " <Encoding id=\"F_WAV\" type=\"T_Sndfile\" extension=\"wav\" name=\"WAV\" has-sample-format=\"true\" channel-limit=\"256\"/>"
460 " <SampleRate rate=\""+ vtl_samplerate +"\"/>"
461 " <SRCQuality quality=\"SRC_SincBest\"/>"
463 " <Option name=\"sample-format\" value=\"SF_16\"/>"
464 " <Option name=\"dithering\" value=\"D_None\"/>"
465 " <Option name=\"tag-metadata\" value=\"true\"/>"
466 " <Option name=\"tag-support\" value=\"false\"/>"
467 " <Option name=\"broadcast-info\" value=\"false\"/>"
468 " </EncodingOptions>"
470 " <Normalize enabled=\""+ vtl_normalize +"\" target=\"0\"/>"
473 " <Trim enabled=\"false\"/>"
474 " <Add enabled=\"false\">"
475 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
479 " <Trim enabled=\"false\"/>"
480 " <Add enabled=\"false\">"
481 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
486 "</ExportFormatSpecification>"
488 boost::shared_ptr<ExportFormatSpecification> fmp = _session->get_export_handler()->add_format(*tree.root());
491 framepos_t start, end;
493 if (insnd_combo.get_active_row_number() == 1) {
494 transcoder = new TranscodeFfmpeg(invid_path_entry.get_text());
495 if (transcoder->probe_ok() && transcoder->get_fps() > 0) {
496 end = transcoder->get_duration() * _session->nominal_frame_rate() / transcoder->get_fps();
498 warning << _("Export Video: Cannot query duration of video-file, using duration from timeline instead.") << endmsg;
499 end = ARDOUR_UI::instance()->video_timeline->get_duration();
501 if (transcoder) {delete transcoder; transcoder = 0;}
503 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
505 printf("audio-range -- AV offset: %lld\n", av_offset);
513 start = _session->current_start_frame();
514 end = _session->current_end_frame();
517 printf("audio export-range %lld -> %lld\n", start, end);
520 tsp->set_range (start, end);
521 tsp->set_name ("mysession");
522 tsp->set_range_id ("session");
524 /* add master outs as default */
525 IO* master_out = _session->master_out()->output().get();
527 warning << _("Export Video: No Master Out Ports to Connect for Audio Export") << endmsg;
528 Gtk::Dialog::response(RESPONSE_CANCEL);
531 for (uint32_t n = 0; n < master_out->n_ports().n_audio(); ++n) {
532 PortExportChannel * channel = new PortExportChannel ();
533 channel->add_port (master_out->audio (n));
534 ExportChannelPtr chan_ptr (channel);
535 ccp->register_channel (chan_ptr);
539 fnp->set_timespan(tsp);
540 fnp->set_label("vtl");
541 fnp->include_label = true;
542 insnd = fnp->get_path(fmp);
544 /* do sound export */
545 _session->get_export_handler()->add_export_config (tsp, ccp, fmp, fnp, b);
546 _session->get_export_handler()->do_export();
547 status = _session->get_export_status ();
549 audio_progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportVideoDialog::audio_progress_display), 100);
550 previous_progress = 0.0;
551 while (status->running) {
552 if (aborted) { status->abort(); }
553 if (gtk_events_pending()) {
554 gtk_main_iteration ();
559 audio_progress_connection.disconnect();
561 if (status->aborted()) {
562 ::g_unlink (insnd.c_str());
563 Gtk::Dialog::response(RESPONSE_CANCEL);
566 pbar.set_text (_("Encoding Video..."));
571 ExportVideoDialog::encode_pass (int pass)
573 std::string outfn = outfn_path_entry.get_text();
574 std::string invid = invid_path_entry.get_text();
576 transcoder = new TranscodeFfmpeg(invid);
577 if (!transcoder->ffexec_ok()) {
578 /* ffmpeg binary was not found. TranscodeFfmpeg prints a warning */
579 ::g_unlink (insnd.c_str());
580 Gtk::Dialog::response(RESPONSE_CANCEL);
583 if (!transcoder->probe_ok()) {
584 /* video input file can not be read */
585 warning << _("Export Video: Video input file cannot be read.") << endmsg;
586 ::g_unlink (insnd.c_str());
587 Gtk::Dialog::response(RESPONSE_CANCEL);
591 std::string preset = preset_combo.get_active_text();
592 TranscodeFfmpeg::FFSettings ffs ; /* = transcoder->default_encoder_settings(); */
595 if (fps_checkbox.get_active()) {
596 ffs["-r"] = fps_combo.get_active_text();
599 if (scale_checkbox.get_active()) {
600 ffs["-s"] = string_compose("%1x%2", width_spinner.get_value(), height_spinner.get_value());
602 ffs["-vcodec"] = video_codec_combo.get_active_text();
603 ffs["-acodec"] = audio_codec_combo.get_active_text();
605 if (video_bitrate_combo.get_active_text() == "retain" ) {
606 ffs["-qscale"] = "0";
608 ffs["-b:v"] = video_bitrate_combo.get_active_text();
610 ffs["-b:a"] = audio_bitrate_combo.get_active_text();
612 if (audio_codec_combo.get_active_text() == "aac" ) {
613 ffs["-strict"] = "-2";
616 if (video_codec_combo.get_active_text() == "h264" ) {
617 ffs["-vcodec"] = "libx264";
619 else if (video_codec_combo.get_active_text() == "vpx (webm)" ) {
620 ffs["-vcodec"] = "libvpx";
626 if (optimizations_checkbox.get_active()) {
627 if (video_codec_combo.get_active_text() == "mpeg2video") {
629 ffs["-trellis"] = "2";
631 ffs["-subcmp"] = "2";
633 else if (video_codec_combo.get_active_text() == "mpeg4") {
635 ffs["-flags"] = "+mv4+aic";
636 ffs["-trellis"] = "2";
638 ffs["-subcmp"] = "2";
641 else if (video_codec_combo.get_active_text() == "flv") {
644 ffs["-subcmp"] = "2";
645 ffs["-trellis"] = "2";
646 ffs["-flags"] = "+aic+mv0+mv4";
651 if (bframes_checkbox.get_active() && (
652 video_codec_combo.get_active_text() == "mpeg2video"
653 || video_codec_combo.get_active_text() == "mpeg4"
658 if (preset == "dvd-PAL") {
659 ffs.clear(); /* ignore all prev settings */
660 ffs["-target"] = "pal-dvd";
661 ffs["-aspect"] = "4:3"; /* required for DVD - may be overridden below */
663 else if (preset == "dvd-NTSC") {
664 ffs.clear(); /* ignore all prev settings */
665 ffs["-target"] = "ntsc-dvd";
666 ffs["-aspect"] = "4:3"; /* required for DVD - may be overridden below */
669 if (aspect_checkbox.get_active()) {
670 ffs["-aspect"] = aspect_combo.get_active_text();
672 if (deinterlace_checkbox.get_active()) {
673 ffs["-deinterlace"] = "-y"; // we use '-y' as dummy parameter for non key/value options
677 if (pass == 1 && twopass) {
678 pbar.set_text (_("Encoding Video.. Pass 1/2"));
682 ffs["-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
683 ffs["-f"] = get_file_extension(invid).empty()?"mov":get_file_extension(invid);
689 } else if (pass == 2) {
690 pbar.set_text (_("Encoding Video.. Pass 2/2"));
692 ffs["-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
695 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
696 double duration_s = 0;
698 if (insnd_combo.get_active_row_number() == 0) {
699 framecnt_t duration_f = _session->current_end_frame() - _session->current_start_frame();
700 duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
702 framecnt_t duration_f = ARDOUR_UI::instance()->video_timeline->get_duration();
703 if (av_offset < 0 ) {
704 duration_f += av_offset;
706 duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
709 std::ostringstream osstream; osstream << duration_s;
710 ffs["-t"] = osstream.str();
711 if (fps_checkbox.get_active()) {
712 transcoder->set_duration(duration_s * atof(fps_combo.get_active_text()));
714 transcoder->set_duration(duration_s * transcoder->get_fps());
717 if (insnd_combo.get_active_row_number() == 0) {
718 const framepos_t start = _session->current_start_frame();
719 const framepos_t snend = _session->current_end_frame();
720 const frameoffset_t vid_duration = ARDOUR_UI::instance()->video_timeline->get_duration();
723 printf("AV offset: %lld Vid-len: %lld Vid-end: %lld || start:%lld || end:%lld\n",
724 av_offset, vid_duration, av_offset+vid_duration, start, snend); // XXX
727 if (av_offset > start && av_offset + vid_duration < snend) {
728 transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(),
729 (snend - (av_offset + vid_duration)) / (double)_session->nominal_frame_rate());
730 } else if (av_offset > start) {
731 transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(), 0);
732 } else if (av_offset + vid_duration < snend) {
733 transcoder->set_leadinout(0, (snend - (av_offset + vid_duration)) / (double)_session->nominal_frame_rate());
734 transcoder->set_avoffset((av_offset - start) / (double)_session->nominal_frame_rate());
736 transcoder->set_avoffset((av_offset - start) / (double)_session->nominal_frame_rate());
738 } else if (av_offset < 0) {
739 /* from 00:00:00:00 to video-end */
740 transcoder->set_avoffset(av_offset / (double)_session->nominal_frame_rate());
743 TranscodeFfmpeg::FFSettings meta = transcoder->default_meta_data();
744 if (meta_checkbox.get_active()) {
745 ARDOUR::SessionMetadata * session_data = ARDOUR::SessionMetadata::Metadata();
746 if (session_data->year() > 0 ) {
747 std::ostringstream osstream; osstream << session_data->year();
748 meta["year"] = osstream.str();
750 if (session_data->track_number() > 0 ) {
751 std::ostringstream osstream; osstream << session_data->track_number();
752 meta["track"] = osstream.str();
754 if (session_data->disc_number() > 0 ) {
755 std::ostringstream osstream; osstream << session_data->disc_number();
756 meta["disc"] = osstream.str();
758 if (!session_data->title().empty()) {meta["title"] = session_data->title();}
759 if (!session_data->artist().empty()) {meta["author"] = session_data->artist();}
760 if (!session_data->album_artist().empty()) {meta["album_artist"] = session_data->album_artist();}
761 if (!session_data->album().empty()) {meta["album"] = session_data->album();}
762 if (!session_data->genre().empty()) {meta["genre"] = session_data->genre();}
763 if (!session_data->composer().empty()) {meta["composer"] = session_data->composer();}
764 if (!session_data->comment().empty()) {meta["comment"] = session_data->comment();}
765 if (!session_data->copyright().empty()) {meta["copyright"] = session_data->copyright();}
766 if (!session_data->subtitle().empty()) {meta["description"] = session_data->subtitle();}
769 #if 1 /* tentative debug mode */
770 if (debug_checkbox.get_active()) {
771 transcoder->set_debug(true);
775 transcoder->Progress.connect(*this, invalidator (*this), boost::bind (&ExportVideoDialog::update_progress , this, _1, _2), gui_context());
776 transcoder->Finished.connect(*this, invalidator (*this), boost::bind (&ExportVideoDialog::finished, this), gui_context());
777 if (!transcoder->encode(outfn, insnd, invid, ffs, meta, map)) {
778 ARDOUR_UI::instance()->popup_error(_("Transcoding failed."));
779 Gtk::Dialog::response(RESPONSE_CANCEL);
785 ExportVideoDialog::change_file_extension (std::string ext)
787 outfn_path_entry.set_text (
788 strip_file_extension(outfn_path_entry.get_text()) + ext
793 ExportVideoDialog::scale_checkbox_toggled ()
795 width_spinner.set_sensitive(scale_checkbox.get_active());
796 height_spinner.set_sensitive(scale_checkbox.get_active());
800 ExportVideoDialog::fps_checkbox_toggled ()
802 fps_combo.set_sensitive(fps_checkbox.get_active());
806 ExportVideoDialog::aspect_checkbox_toggled ()
808 aspect_combo.set_sensitive(aspect_checkbox.get_active());
812 ExportVideoDialog::video_codec_combo_changed ()
814 if (( video_codec_combo.get_active_text() == "mpeg4"
815 ||video_codec_combo.get_active_text() == "mpeg2video"
817 preset_combo.get_active_text() == "dvd-PAL"
818 ||preset_combo.get_active_text() == "dvd-NTSC"
820 bframes_checkbox.set_sensitive(true);
821 optimizations_checkbox.set_sensitive(true);
822 if (video_codec_combo.get_active_text() == "mpeg2video") {
823 optimizations_label.set_text("-mbd rd -trellis 2 -cmp 2 -subcmp 2"); // mpeg2
824 } else if (video_codec_combo.get_active_text() == "mpeg4") {
825 optimizations_label.set_text("-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300"); // mpeg4
827 optimizations_label.set_text("-mbd 2 -cmp 2 -subcmp 2 -trellis 2 -flags +aic+mv0+mv4 -g 160"); // flv
830 bframes_checkbox.set_sensitive(false);
831 bframes_checkbox.set_active(false);
832 optimizations_checkbox.set_sensitive(false);
833 optimizations_checkbox.set_active(false);
834 optimizations_label.set_text("-");
839 ExportVideoDialog::preset_combo_changed ()
841 std::string p = preset_combo.get_active_text();
842 scale_checkbox.set_sensitive(true);
845 change_file_extension(".flv");
846 audio_codec_combo.set_active(1);
847 video_codec_combo.set_active(0);
848 audio_bitrate_combo.set_active(1);
849 video_bitrate_combo.set_active(1);
850 audio_samplerate_combo.set_active(1);
852 else if (p == "you-tube") {
853 change_file_extension(".avi");
854 audio_codec_combo.set_active(2);
855 video_codec_combo.set_active(5);
856 audio_bitrate_combo.set_active(1);
857 video_bitrate_combo.set_active(2);
858 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
859 audio_samplerate_combo.set_active(2);
861 audio_samplerate_combo.set_active(1);
864 else if (p == "ogg") {
865 change_file_extension(".ogv");
866 audio_codec_combo.set_active(3);
867 video_codec_combo.set_active(1);
868 audio_bitrate_combo.set_active(2);
869 video_bitrate_combo.set_active(2);
870 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
871 audio_samplerate_combo.set_active(2);
873 audio_samplerate_combo.set_active(1);
876 else if (p == "dvd-mp2") {
877 change_file_extension(".mpg");
878 audio_codec_combo.set_active(4);
879 video_codec_combo.set_active(3);
880 audio_bitrate_combo.set_active(3);
881 video_bitrate_combo.set_active(3);
882 audio_samplerate_combo.set_active(2);
884 else if (p == "dvd-NTSC" || p == "dvd-PAL") {
885 change_file_extension(".mpg");
886 audio_codec_combo.set_active(5);
887 video_codec_combo.set_active(3);
888 audio_bitrate_combo.set_active(3);
889 video_bitrate_combo.set_active(3);
890 audio_samplerate_combo.set_active(2);
892 scale_checkbox.set_active(false);
893 scale_checkbox.set_sensitive(false);
895 else if (p == "mpeg4") {
896 change_file_extension(".mp4");
897 audio_codec_combo.set_active(0);
898 video_codec_combo.set_active(4);
899 audio_bitrate_combo.set_active(3);
900 video_bitrate_combo.set_active(3);
901 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
902 audio_samplerate_combo.set_active(2);
904 audio_samplerate_combo.set_active(1);
909 audio_codec_combo.set_sensitive(true);
910 video_codec_combo.set_sensitive(true);
911 audio_bitrate_combo.set_sensitive(true);
912 video_bitrate_combo.set_sensitive(true);
913 audio_samplerate_combo.set_sensitive(true);
915 audio_codec_combo.set_sensitive(false);
916 video_codec_combo.set_sensitive(false);
917 audio_bitrate_combo.set_sensitive(false);
918 video_bitrate_combo.set_sensitive(false);
919 audio_samplerate_combo.set_sensitive(false);
922 Gtk::Table *t = (Gtk::Table*) preset_combo.get_parent();
923 Gtk::Table_Helpers::TableList c = t->children();
924 Gtk::Table_Helpers::TableList::iterator it;
925 if (p == "dvd-PAL" || p == "dvd-NTSC") {
926 for (it = c.begin(); it != c.end(); ++it) {
927 int row = it->get_top_attach();
928 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
929 it->get_widget()->hide();
933 for (it = c.begin(); it != c.end(); ++it) {
934 int row = it->get_top_attach();
935 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
936 it->get_widget()->show();
941 video_codec_combo_changed();
945 ExportVideoDialog::open_outfn_dialog ()
947 Gtk::FileChooserDialog dialog(_("Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
948 dialog.set_filename (outfn_path_entry.get_text());
950 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
951 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
953 int result = dialog.run();
955 if (result == Gtk::RESPONSE_OK) {
956 std::string filename = dialog.get_filename();
958 if (filename.length()) {
959 outfn_path_entry.set_text (filename);
965 ExportVideoDialog::open_invid_dialog ()
967 Gtk::FileChooserDialog dialog(_("Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
968 dialog.set_filename (invid_path_entry.get_text());
970 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
971 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
973 int result = dialog.run();
975 if (result == Gtk::RESPONSE_OK) {
976 std::string filename = dialog.get_filename();
978 if (filename.length()) {
979 invid_path_entry.set_text (filename);