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>
32 #include <glib/gstdio.h>
34 #include "pbd/error.h"
35 #include "pbd/convert.h"
36 #include "gtkmm2ext/utils.h"
37 #include "ardour/session_directory.h"
38 #include "ardour/profile.h"
39 #include "ardour/template_utils.h"
40 #include "ardour/session.h"
41 #include "ardour_ui.h"
42 #include "gui_thread.h"
44 #include "ardour/export_handler.h"
45 #include "ardour/export_status.h"
46 #include "ardour/export_timespan.h"
47 #include "ardour/export_channel_configuration.h"
48 #include "ardour/export_format_specification.h"
49 #include "ardour/export_filename.h"
50 #include "ardour/route.h"
51 #include "ardour/session_metadata.h"
52 #include "ardour/broadcast_info.h"
56 #include "export_video_dialog.h"
57 #include "utils_videotl.h"
63 using namespace ARDOUR;
64 using namespace VideoUtils;
66 ExportVideoDialog::ExportVideoDialog (Session* s, TimeSelection &tme)
67 : ArdourDialog (_("Export Video File "))
69 , outfn_path_label (_("File:"), Gtk::ALIGN_LEFT)
70 , outfn_browse_button (_("Browse"))
71 , invid_path_label (_("Video:"), Gtk::ALIGN_LEFT)
72 , invid_browse_button (_("Browse"))
73 , transcode_button (_("Export"))
74 , abort_button (_("Abort"))
75 , scale_checkbox (_("Scale Video (W x H):"))
76 , width_adjustment (768, 128, 1920, 1, 16, 0)
77 , width_spinner (width_adjustment)
78 , height_adjustment (576, 128, 1920, 1, 16, 0)
79 , height_spinner (height_adjustment)
80 , aspect_checkbox (_("Set Aspect Ratio:"))
81 , normalize_checkbox (_("Normalize Audio"))
82 , twopass_checkbox (_("2 Pass Encoding"))
83 , optimizations_checkbox (_("Codec Optimizations:"))
84 , optimizations_label ("-")
85 , deinterlace_checkbox (_("Deinterlace"))
86 , bframes_checkbox (_("Use [2] B-frames (MPEG 2 or 4 only)"))
87 , fps_checkbox (_("Override FPS (Default is to retain FPS from the input video file):"))
88 , meta_checkbox (_("Include Session Metadata"))
89 #if 1 /* tentative debug mode */
90 , debug_checkbox (_("Debug Mode: Print ffmpeg command and output to stdout."))
95 set_name ("ExportVideoDialog");
97 set_skip_taskbar_hint (true);
98 set_resizable (false);
101 vbox = manage (new VBox);
102 VBox* options_box = manage (new VBox);
105 /* check if ffmpeg can be found */
106 transcoder = new TranscodeFfmpeg("");
107 if (!transcoder->ffexec_ok()) {
108 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));
110 vbox->pack_start (*l, false, false, 8);
111 get_vbox()->pack_start (*vbox, false, false);
112 add_button (Stock::OK, RESPONSE_CANCEL);
113 show_all_children ();
116 delete transcoder; transcoder = 0;
118 l = manage (new Label (_("<b>Output:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
119 l->set_use_markup ();
120 vbox->pack_start (*l, false, false, 4);
122 path_hbox = manage (new HBox);
123 path_hbox->pack_start (outfn_path_label, false, false, 3);
124 path_hbox->pack_start (outfn_path_entry, true, true, 3);
125 path_hbox->pack_start (outfn_browse_button, false, false, 3);
126 vbox->pack_start (*path_hbox, false, false, 2);
128 l = manage (new Label (_("<b>Input:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
129 l->set_use_markup ();
130 vbox->pack_start (*l, false, false, 4);
132 path_hbox = manage (new HBox);
133 path_hbox->pack_start (invid_path_label, false, false, 3);
134 path_hbox->pack_start (invid_path_entry, true, true, 3);
135 path_hbox->pack_start (invid_browse_button, false, false, 3);
136 vbox->pack_start (*path_hbox, false, false, 2);
138 path_hbox = manage (new HBox);
139 l = manage (new Label (_("Audio:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
140 path_hbox->pack_start (*l, false, false, 3);
141 l = manage (new Label (_("Master Bus"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
142 path_hbox->pack_start (*l, false, false, 2);
143 vbox->pack_start (*path_hbox, false, false, 2);
145 insnd_combo.set_name ("PaddedButton");
146 insnd_combo.append_text (string_compose (_("from the %1 session's start to the session's end"), PROGRAM_NAME));
148 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
149 if (av_offset < 0 ) {
150 insnd_combo.append_text (_("from 00:00:00:00 to the video's end"));
152 insnd_combo.append_text (_("from the video's start to the video's end"));
154 if (!export_range.empty()) {
155 insnd_combo.append_text (_("Selected range")); // TODO show export_range.start() -> export_range.end_frame()
157 insnd_combo.set_active(0);
159 outfn_path_entry.set_width_chars(38);
160 outfn_path_entry.set_text (_session->session_directory().export_path() + G_DIR_SEPARATOR +"export.avi");
162 XMLNode* node = _session->extra_xml (X_("Videotimeline"));
164 bool filenameset = false;
165 if (node->property(X_("OriginalVideoFile"))) {
166 std::string filename = node->property(X_("OriginalVideoFile"))->value();
167 if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
168 invid_path_entry.set_text (filename);
173 && node->property(X_("Filename"))
174 && node->property(X_("LocalFile"))
175 && node->property(X_("LocalFile"))->value() == X_("1")
177 std::string filename = node->property(X_("Filename"))->value();
178 if (filename.at(0) != G_DIR_SEPARATOR) {
179 filename = Glib::build_filename (_session->session_directory().video_path(), filename);
181 if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
182 invid_path_entry.set_text (filename);
187 invid_path_entry.set_text (X_(""));
191 l = manage (new Label (_("<b>Settings:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
192 l->set_use_markup ();
193 options_box->pack_start (*l, false, true, 4);
195 Table* t = manage (new Table (4, 12));
198 options_box->pack_start (*t, true, true, 4);
199 l = manage (new Label (_("Range:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
200 t->attach (*l, 0, 1, ty, ty+1);
201 t->attach (insnd_combo, 1, 4, ty, ty+1); ty++;
202 l = manage (new Label (_("Preset:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
203 t->attach (*l, 0, 1, ty, ty+1);
204 t->attach (preset_combo, 1, 4, ty, ty+1); ty++;
205 l = manage (new Label (_("Video Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
206 t->attach (*l, 0, 1, ty, ty+1);
207 t->attach (video_codec_combo, 1, 2, ty, ty+1);
208 l = manage (new Label (_("Video KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
209 t->attach (*l, 2, 3, ty, ty+1);
210 t->attach (video_bitrate_combo, 3, 4, ty, ty+1); ty++;
211 l = manage (new Label (_("Audio Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
212 t->attach (*l, 0, 1, ty, ty+1);
213 t->attach (audio_codec_combo, 1, 2, ty, ty+1);
214 l = manage (new Label (_("Audio KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
215 t->attach (*l, 2, 3, ty, ty+1);
216 t->attach (audio_bitrate_combo, 3, 4, ty, ty+1); ty++;
217 l = manage (new Label (_("Audio Samplerate:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
218 t->attach (*l, 0, 1, ty, ty+1);
219 t->attach (audio_samplerate_combo, 1, 2, ty, ty+1);
220 t->attach (normalize_checkbox, 2, 4, ty, ty+1); ty++;
221 t->attach (scale_checkbox, 0, 2, ty, ty+1);
222 t->attach (width_spinner, 2, 3, ty, ty+1);
223 t->attach (height_spinner, 3, 4, ty, ty+1); ty++;
224 t->attach (fps_checkbox, 0, 3, ty, ty+1);
225 t->attach (fps_combo, 3, 4, ty, ty+1); ty++;
226 t->attach (twopass_checkbox, 0, 2, ty, ty+1);
227 t->attach (aspect_checkbox, 2, 3, ty, ty+1);
228 t->attach (aspect_combo, 3, 4, ty, ty+1); ty++;
229 t->attach (bframes_checkbox, 0, 2, ty, ty+1);
230 t->attach (deinterlace_checkbox, 2, 4, ty, ty+1); ty++;
231 t->attach (meta_checkbox, 2, 4, ty, ty+1); ty++;
232 t->attach (optimizations_checkbox, 0, 1, ty, ty+1);
233 t->attach (optimizations_label, 1, 4, ty, ty+1); ty++;
234 #if 1 /* tentative debug mode */
235 t->attach (debug_checkbox, 0, 4, ty, ty+1); ty++;
238 preset_combo.set_name ("PaddedButton");
239 preset_combo.append_text("none");
240 preset_combo.append_text("dvd-mp2");
241 preset_combo.append_text("dvd-NTSC");
242 preset_combo.append_text("dvd-PAL");
243 preset_combo.append_text("flv");
244 preset_combo.append_text("mpeg4");
245 preset_combo.append_text("ogg");
246 preset_combo.append_text("you-tube");
247 preset_combo.set_active(0);
249 audio_codec_combo.set_name ("PaddedButton");
250 audio_codec_combo.append_text("ac3");
251 audio_codec_combo.append_text("aac");
252 audio_codec_combo.append_text("libmp3lame");
253 audio_codec_combo.append_text("libvorbis");
254 audio_codec_combo.append_text("mp2");
255 audio_codec_combo.append_text("pcm_s16le");
256 audio_codec_combo.set_active(2);
258 video_codec_combo.set_name ("PaddedButton");
259 video_codec_combo.append_text("flv");
260 video_codec_combo.append_text("libtheora");
261 video_codec_combo.append_text("mjpeg");
262 video_codec_combo.append_text("mpeg2video");
263 video_codec_combo.append_text("mpeg4");
264 video_codec_combo.append_text("h264");
265 video_codec_combo.append_text("vpx (webm)");
266 video_codec_combo.append_text("copy");
267 video_codec_combo.set_active(4);
269 audio_bitrate_combo.set_name ("PaddedButton");
270 audio_bitrate_combo.append_text("64k");
271 audio_bitrate_combo.append_text("128k");
272 audio_bitrate_combo.append_text("192k");
273 audio_bitrate_combo.append_text("256k");
274 audio_bitrate_combo.append_text("320k");
275 audio_bitrate_combo.set_active(2);
277 audio_samplerate_combo.set_name ("PaddedButton");
278 audio_samplerate_combo.append_text("22050");
279 audio_samplerate_combo.append_text("44100");
280 audio_samplerate_combo.append_text("48000");
281 audio_samplerate_combo.set_active(2);
283 video_bitrate_combo.set_name ("PaddedButton");
284 video_bitrate_combo.append_text("200k");
285 video_bitrate_combo.append_text("800k");
286 video_bitrate_combo.append_text("2000k");
287 video_bitrate_combo.append_text("5000k");
288 video_bitrate_combo.append_text("8000k");
289 video_bitrate_combo.append_text("retain");
290 video_bitrate_combo.set_active(3);
292 fps_combo.set_name ("PaddedButton");
293 fps_combo.append_text("23.976");
294 fps_combo.append_text("24");
295 fps_combo.append_text("24.976");
296 fps_combo.append_text("25");
297 fps_combo.append_text("29.97");
298 fps_combo.append_text("30");
299 fps_combo.append_text("59.94");
300 fps_combo.append_text("60");
301 float tcfps = _session->timecode_frames_per_second();
302 if (fabs(tcfps - 23.976) < 0.01) { fps_combo.set_active(0); }
303 else if (fabs(tcfps - 24.0 ) < 0.01) { fps_combo.set_active(1); }
304 else if (fabs(tcfps - 24.976) < 0.01) { fps_combo.set_active(2); }
305 else if (fabs(tcfps - 25.0 ) < 0.01) { fps_combo.set_active(3); }
306 else if (fabs(tcfps - 29.97 ) < 0.01) { fps_combo.set_active(4); }
307 else if (fabs(tcfps - 30.0 ) < 0.01) { fps_combo.set_active(5); }
308 else if (fabs(tcfps - 59.94 ) < 0.01) { fps_combo.set_active(6); }
309 else if (fabs(tcfps - 60.0 ) < 0.01) { fps_combo.set_active(7); }
310 else { fps_combo.set_active(5); }
312 aspect_combo.set_name ("PaddedButton");
313 aspect_combo.append_text("4:3");
314 aspect_combo.append_text("16:9");
315 aspect_combo.set_active(1);
317 optimizations_checkbox.set_sensitive(false);
318 scale_checkbox_toggled();
319 aspect_checkbox_toggled();
320 fps_checkbox_toggled();
321 video_codec_combo_changed();
323 vbox->pack_start (*options_box, false, true, 4);
324 get_vbox()->set_spacing (4);
325 get_vbox()->pack_start (*vbox, false, false);
327 progress_box = manage (new VBox);
328 progress_box->pack_start (pbar, false, false);
329 progress_box->pack_start (abort_button, false, false);
330 get_vbox()->pack_start (*progress_box, false, false);
332 scale_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::scale_checkbox_toggled));
333 aspect_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::aspect_checkbox_toggled));
334 fps_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::fps_checkbox_toggled));
335 preset_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportVideoDialog::preset_combo_changed));
336 video_codec_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportVideoDialog::video_codec_combo_changed));
337 outfn_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::open_outfn_dialog));
338 invid_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::open_invid_dialog));
339 transcode_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::launch_export));
340 abort_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::abort_clicked));
342 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
343 get_action_area()->pack_start (transcode_button, false, false);
344 show_all_children ();
345 progress_box->hide();
348 ExportVideoDialog::~ExportVideoDialog ()
350 if (transcoder) { delete transcoder; transcoder = 0;}
354 ExportVideoDialog::on_show ()
360 ExportVideoDialog::abort_clicked ()
364 transcoder->cancel();
369 ExportVideoDialog::update_progress (framecnt_t c, framecnt_t a)
371 if (a == 0 || c > a) {
372 pbar.set_pulse_step(.1);
375 double progress = (double)c / (double) a;
376 progress = progress / ((twopass ? 2.0 : 1.0) + (normalize ? 2.0 : 1.0));
377 if (normalize && twopass) progress += (firstpass ? .5 : .75);
378 else if (normalize) progress += 2.0/3.0;
379 else if (twopass) progress += (firstpass ? 1.0/3.0 : 2.0/3.0);
382 pbar.set_fraction (progress);
388 ExportVideoDialog::audio_progress_display ()
390 std::string status_text;
391 double progress = 0.0;
392 if (status->normalizing) {
393 pbar.set_text (_("Normalizing audio"));
394 progress = ((float) status->current_normalize_cycle) / status->total_normalize_cycles;
395 progress = progress / (twopass ? 4.0 : 3.0) + (twopass ? .25 : 1.0/3.0);
397 pbar.set_text (_("Exporting audio"));
398 progress = ((float) status->processed_frames_current_timespan) / status->total_frames_current_timespan;
399 progress = progress / ((twopass ? 2.0 : 1.0) + (normalize ? 2.0 : 1.0));
401 if (progress < previous_progress) {
402 // Work around gtk bug
406 previous_progress = progress;
407 pbar.set_fraction (progress);
412 ExportVideoDialog::finished ()
415 ::g_unlink(outfn_path_entry.get_text().c_str());
416 ::g_unlink (insnd.c_str());
417 Gtk::Dialog::response(RESPONSE_CANCEL);
418 } else if (twopass && firstpass) {
420 if (transcoder) { delete transcoder; transcoder = 0;}
423 if (twopass_checkbox.get_active()) {
424 std::string outfn = outfn_path_entry.get_text();
425 std::string p2log = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
426 ::g_unlink (p2log.c_str());
428 ::g_unlink (insnd.c_str());
429 Gtk::Dialog::response(RESPONSE_ACCEPT);
434 ExportVideoDialog::launch_export ()
436 std::string outfn = outfn_path_entry.get_text();
437 if (!confirm_video_outfn(outfn)) { return; }
440 cancel_button->hide();
441 transcode_button.hide();
442 pbar.set_size_request(300,-1);
443 pbar.set_text(_("Exporting Audio..."));
444 progress_box->show();
446 twopass = twopass_checkbox.get_active();
448 normalize = normalize_checkbox.get_active();
450 /* export audio track */
451 ExportTimespanPtr tsp = _session->get_export_handler()->add_timespan();
452 boost::shared_ptr<ExportChannelConfiguration> ccp = _session->get_export_handler()->add_channel_config();
453 boost::shared_ptr<ARDOUR::ExportFilename> fnp = _session->get_export_handler()->add_filename();
454 boost::shared_ptr<AudioGrapher::BroadcastInfo> b;
456 std::string vtl_samplerate = audio_samplerate_combo.get_active_text();
457 std::string vtl_normalize = normalize ? "true" : "false";
458 tree.read_buffer(std::string(
459 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
460 "<ExportFormatSpecification name=\"VTL-WAV-16\" id=\"3094591e-ccb9-4385-a93f-c9955ffeb1f0\">"
461 " <Encoding id=\"F_WAV\" type=\"T_Sndfile\" extension=\"wav\" name=\"WAV\" has-sample-format=\"true\" channel-limit=\"256\"/>"
462 " <SampleRate rate=\""+ vtl_samplerate +"\"/>"
463 " <SRCQuality quality=\"SRC_SincBest\"/>"
465 " <Option name=\"sample-format\" value=\"SF_16\"/>"
466 " <Option name=\"dithering\" value=\"D_None\"/>"
467 " <Option name=\"tag-metadata\" value=\"true\"/>"
468 " <Option name=\"tag-support\" value=\"false\"/>"
469 " <Option name=\"broadcast-info\" value=\"false\"/>"
470 " </EncodingOptions>"
472 " <Normalize enabled=\""+ vtl_normalize +"\" target=\"0\"/>"
475 " <Trim enabled=\"false\"/>"
476 " <Add enabled=\"false\">"
477 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
481 " <Trim enabled=\"false\"/>"
482 " <Add enabled=\"false\">"
483 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
488 "</ExportFormatSpecification>"
490 boost::shared_ptr<ExportFormatSpecification> fmp = _session->get_export_handler()->add_format(*tree.root());
493 framepos_t start, end;
495 if (insnd_combo.get_active_row_number() == 1) {
496 transcoder = new TranscodeFfmpeg(invid_path_entry.get_text());
497 if (transcoder->probe_ok() && transcoder->get_fps() > 0) {
498 end = transcoder->get_duration() * _session->nominal_frame_rate() / transcoder->get_fps();
500 warning << _("Export Video: Cannot query duration of video-file, using duration from timeline instead.") << endmsg;
501 end = ARDOUR_UI::instance()->video_timeline->get_duration();
503 if (transcoder) {delete transcoder; transcoder = 0;}
505 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
507 printf("audio-range -- AV offset: %lld\n", av_offset);
514 else if (insnd_combo.get_active_row_number() == 2) {
515 // TODO quantize to video-frame ?!
516 start = export_range.start();
517 end = export_range.end_frame();
520 start = _session->current_start_frame();
521 end = _session->current_end_frame();
524 printf("audio export-range %lld -> %lld\n", start, end);
527 tsp->set_range (start, end);
528 tsp->set_name ("mysession");
529 tsp->set_range_id ("session");
531 /* add master outs as default */
532 IO* master_out = _session->master_out()->output().get();
534 warning << _("Export Video: No Master Out Ports to Connect for Audio Export") << endmsg;
535 Gtk::Dialog::response(RESPONSE_CANCEL);
538 for (uint32_t n = 0; n < master_out->n_ports().n_audio(); ++n) {
539 PortExportChannel * channel = new PortExportChannel ();
540 channel->add_port (master_out->audio (n));
541 ExportChannelPtr chan_ptr (channel);
542 ccp->register_channel (chan_ptr);
546 fnp->set_timespan(tsp);
547 fnp->set_label("vtl");
548 fnp->include_label = true;
549 insnd = fnp->get_path(fmp);
551 /* do sound export */
552 _session->get_export_handler()->add_export_config (tsp, ccp, fmp, fnp, b);
553 _session->get_export_handler()->do_export();
554 status = _session->get_export_status ();
556 audio_progress_connection = Glib::signal_timeout().connect (sigc::mem_fun(*this, &ExportVideoDialog::audio_progress_display), 100);
557 previous_progress = 0.0;
558 while (status->running) {
559 if (aborted) { status->abort(); }
560 if (gtk_events_pending()) {
561 gtk_main_iteration ();
563 Glib::usleep (10000);
566 audio_progress_connection.disconnect();
568 if (status->aborted()) {
569 ::g_unlink (insnd.c_str());
570 Gtk::Dialog::response(RESPONSE_CANCEL);
573 pbar.set_text (_("Encoding Video..."));
578 ExportVideoDialog::encode_pass (int pass)
580 std::string outfn = outfn_path_entry.get_text();
581 std::string invid = invid_path_entry.get_text();
583 transcoder = new TranscodeFfmpeg(invid);
584 if (!transcoder->ffexec_ok()) {
585 /* ffmpeg binary was not found. TranscodeFfmpeg prints a warning */
586 ::g_unlink (insnd.c_str());
587 Gtk::Dialog::response(RESPONSE_CANCEL);
590 if (!transcoder->probe_ok()) {
591 /* video input file can not be read */
592 warning << _("Export Video: Video input file cannot be read.") << endmsg;
593 ::g_unlink (insnd.c_str());
594 Gtk::Dialog::response(RESPONSE_CANCEL);
598 std::string preset = preset_combo.get_active_text();
599 TranscodeFfmpeg::FFSettings ffs ; /* = transcoder->default_encoder_settings(); */
602 if (fps_checkbox.get_active()) {
603 ffs["-r"] = fps_combo.get_active_text();
606 if (scale_checkbox.get_active()) {
607 ffs["-s"] = string_compose("%1x%2", width_spinner.get_value(), height_spinner.get_value());
609 ffs["-vcodec"] = video_codec_combo.get_active_text();
610 ffs["-acodec"] = audio_codec_combo.get_active_text();
612 if (video_bitrate_combo.get_active_text() == "retain" ) {
613 ffs["-qscale"] = "0";
615 ffs["-b:v"] = video_bitrate_combo.get_active_text();
617 ffs["-b:a"] = audio_bitrate_combo.get_active_text();
619 if (audio_codec_combo.get_active_text() == "aac" ) {
620 ffs["-strict"] = "-2";
623 if (video_codec_combo.get_active_text() == "h264" ) {
624 ffs["-vcodec"] = "libx264";
626 else if (video_codec_combo.get_active_text() == "vpx (webm)" ) {
627 ffs["-vcodec"] = "libvpx";
633 if (optimizations_checkbox.get_active()) {
634 if (video_codec_combo.get_active_text() == "mpeg2video") {
636 ffs["-trellis"] = "2";
638 ffs["-subcmp"] = "2";
640 else if (video_codec_combo.get_active_text() == "mpeg4") {
642 ffs["-flags"] = "+mv4+aic";
643 ffs["-trellis"] = "2";
645 ffs["-subcmp"] = "2";
648 else if (video_codec_combo.get_active_text() == "flv") {
651 ffs["-subcmp"] = "2";
652 ffs["-trellis"] = "2";
653 ffs["-flags"] = "+aic+mv0+mv4";
658 if (bframes_checkbox.get_active() && (
659 video_codec_combo.get_active_text() == "mpeg2video"
660 || video_codec_combo.get_active_text() == "mpeg4"
665 if (preset == "dvd-PAL") {
666 ffs.clear(); /* ignore all prev settings */
667 ffs["-target"] = "pal-dvd";
668 ffs["-aspect"] = "4:3"; /* required for DVD - may be overridden below */
670 else if (preset == "dvd-NTSC") {
671 ffs.clear(); /* ignore all prev settings */
672 ffs["-target"] = "ntsc-dvd";
673 ffs["-aspect"] = "4:3"; /* required for DVD - may be overridden below */
676 if (aspect_checkbox.get_active()) {
677 ffs["-aspect"] = aspect_combo.get_active_text();
679 if (deinterlace_checkbox.get_active()) {
680 ffs["-deinterlace"] = "-y"; // we use '-y' as dummy parameter for non key/value options
684 if (pass == 1 && twopass) {
685 pbar.set_text (_("Encoding Video.. Pass 1/2"));
689 ffs["-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
690 ffs["-f"] = get_file_extension(invid).empty()?"mov":get_file_extension(invid);
696 } else if (pass == 2) {
697 pbar.set_text (_("Encoding Video.. Pass 2/2"));
699 ffs["-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
702 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
703 double duration_s = 0;
705 if (insnd_combo.get_active_row_number() == 0) {
706 /* session start to session end */
707 framecnt_t duration_f = _session->current_end_frame() - _session->current_start_frame();
708 duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
709 } else if (insnd_combo.get_active_row_number() == 2) {
711 duration_s = export_range.length() / (double)_session->nominal_frame_rate();
713 /* video start to end */
714 framecnt_t duration_f = ARDOUR_UI::instance()->video_timeline->get_duration();
715 if (av_offset < 0 ) {
716 duration_f += av_offset;
718 duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
721 std::ostringstream osstream; osstream << duration_s;
722 ffs["-t"] = osstream.str();
723 if (fps_checkbox.get_active()) {
724 transcoder->set_duration(duration_s * atof(fps_combo.get_active_text()));
726 transcoder->set_duration(duration_s * transcoder->get_fps());
729 if (insnd_combo.get_active_row_number() == 0 || insnd_combo.get_active_row_number() == 2) {
730 framepos_t start, snend;
731 const frameoffset_t vid_duration = ARDOUR_UI::instance()->video_timeline->get_duration();
732 if (insnd_combo.get_active_row_number() == 0) {
733 start = _session->current_start_frame();
734 snend = _session->current_end_frame();
736 start = export_range.start();
737 snend = export_range.end_frame();
741 printf("AV offset: %lld Vid-len: %lld Vid-end: %lld || start:%lld || end:%lld\n",
742 av_offset, vid_duration, av_offset+vid_duration, start, snend); // XXX
745 if (av_offset > start && av_offset + vid_duration < snend) {
746 transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(),
747 (snend - (av_offset + vid_duration)) / (double)_session->nominal_frame_rate());
748 } else if (av_offset > start) {
749 transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(), 0);
750 } else if (av_offset + vid_duration < snend) {
751 transcoder->set_leadinout(0, (snend - (av_offset + vid_duration)) / (double)_session->nominal_frame_rate());
752 transcoder->set_avoffset((av_offset - start) / (double)_session->nominal_frame_rate());
755 else if (start > av_offset) {
756 std::ostringstream osstream; osstream << ((start - av_offset) / (double)_session->nominal_frame_rate());
757 ffs["-ss"] = osstream.str();
761 transcoder->set_avoffset((av_offset - start) / (double)_session->nominal_frame_rate());
764 } else if (av_offset < 0) {
765 /* from 00:00:00:00 to video-end */
766 transcoder->set_avoffset(av_offset / (double)_session->nominal_frame_rate());
769 TranscodeFfmpeg::FFSettings meta = transcoder->default_meta_data();
770 if (meta_checkbox.get_active()) {
771 ARDOUR::SessionMetadata * session_data = ARDOUR::SessionMetadata::Metadata();
772 if (session_data->year() > 0 ) {
773 std::ostringstream osstream; osstream << session_data->year();
774 meta["year"] = osstream.str();
776 if (session_data->track_number() > 0 ) {
777 std::ostringstream osstream; osstream << session_data->track_number();
778 meta["track"] = osstream.str();
780 if (session_data->disc_number() > 0 ) {
781 std::ostringstream osstream; osstream << session_data->disc_number();
782 meta["disc"] = osstream.str();
784 if (!session_data->title().empty()) {meta["title"] = session_data->title();}
785 if (!session_data->artist().empty()) {meta["author"] = session_data->artist();}
786 if (!session_data->album_artist().empty()) {meta["album_artist"] = session_data->album_artist();}
787 if (!session_data->album().empty()) {meta["album"] = session_data->album();}
788 if (!session_data->genre().empty()) {meta["genre"] = session_data->genre();}
789 if (!session_data->composer().empty()) {meta["composer"] = session_data->composer();}
790 if (!session_data->comment().empty()) {meta["comment"] = session_data->comment();}
791 if (!session_data->copyright().empty()) {meta["copyright"] = session_data->copyright();}
792 if (!session_data->subtitle().empty()) {meta["description"] = session_data->subtitle();}
795 #if 1 /* tentative debug mode */
796 if (debug_checkbox.get_active()) {
797 transcoder->set_debug(true);
801 transcoder->Progress.connect(*this, invalidator (*this), boost::bind (&ExportVideoDialog::update_progress , this, _1, _2), gui_context());
802 transcoder->Finished.connect(*this, invalidator (*this), boost::bind (&ExportVideoDialog::finished, this), gui_context());
803 if (!transcoder->encode(outfn, insnd, invid, ffs, meta, map)) {
804 ARDOUR_UI::instance()->popup_error(_("Transcoding failed."));
805 Gtk::Dialog::response(RESPONSE_CANCEL);
811 ExportVideoDialog::change_file_extension (std::string ext)
813 outfn_path_entry.set_text (
814 strip_file_extension(outfn_path_entry.get_text()) + ext
819 ExportVideoDialog::scale_checkbox_toggled ()
821 width_spinner.set_sensitive(scale_checkbox.get_active());
822 height_spinner.set_sensitive(scale_checkbox.get_active());
826 ExportVideoDialog::fps_checkbox_toggled ()
828 fps_combo.set_sensitive(fps_checkbox.get_active());
832 ExportVideoDialog::aspect_checkbox_toggled ()
834 aspect_combo.set_sensitive(aspect_checkbox.get_active());
838 ExportVideoDialog::video_codec_combo_changed ()
840 if (( video_codec_combo.get_active_text() == "mpeg4"
841 ||video_codec_combo.get_active_text() == "mpeg2video"
843 preset_combo.get_active_text() == "dvd-PAL"
844 ||preset_combo.get_active_text() == "dvd-NTSC"
846 bframes_checkbox.set_sensitive(true);
847 optimizations_checkbox.set_sensitive(true);
848 if (video_codec_combo.get_active_text() == "mpeg2video") {
849 optimizations_label.set_text("-mbd rd -trellis 2 -cmp 2 -subcmp 2"); // mpeg2
850 } else if (video_codec_combo.get_active_text() == "mpeg4") {
851 optimizations_label.set_text("-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300"); // mpeg4
853 optimizations_label.set_text("-mbd 2 -cmp 2 -subcmp 2 -trellis 2 -flags +aic+mv0+mv4 -g 160"); // flv
856 bframes_checkbox.set_sensitive(false);
857 bframes_checkbox.set_active(false);
858 optimizations_checkbox.set_sensitive(false);
859 optimizations_checkbox.set_active(false);
860 optimizations_label.set_text("-");
865 ExportVideoDialog::preset_combo_changed ()
867 std::string p = preset_combo.get_active_text();
868 scale_checkbox.set_sensitive(true);
871 change_file_extension(".flv");
872 audio_codec_combo.set_active(1);
873 video_codec_combo.set_active(0);
874 audio_bitrate_combo.set_active(1);
875 video_bitrate_combo.set_active(1);
876 audio_samplerate_combo.set_active(1);
878 else if (p == "you-tube") {
879 change_file_extension(".avi");
880 audio_codec_combo.set_active(2);
881 video_codec_combo.set_active(5);
882 audio_bitrate_combo.set_active(1);
883 video_bitrate_combo.set_active(2);
884 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
885 audio_samplerate_combo.set_active(2);
887 audio_samplerate_combo.set_active(1);
890 else if (p == "ogg") {
891 change_file_extension(".ogv");
892 audio_codec_combo.set_active(3);
893 video_codec_combo.set_active(1);
894 audio_bitrate_combo.set_active(2);
895 video_bitrate_combo.set_active(2);
896 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
897 audio_samplerate_combo.set_active(2);
899 audio_samplerate_combo.set_active(1);
902 else if (p == "dvd-mp2") {
903 change_file_extension(".mpg");
904 audio_codec_combo.set_active(4);
905 video_codec_combo.set_active(3);
906 audio_bitrate_combo.set_active(3);
907 video_bitrate_combo.set_active(3);
908 audio_samplerate_combo.set_active(2);
910 else if (p == "dvd-NTSC" || p == "dvd-PAL") {
911 change_file_extension(".mpg");
912 audio_codec_combo.set_active(5);
913 video_codec_combo.set_active(3);
914 audio_bitrate_combo.set_active(3);
915 video_bitrate_combo.set_active(3);
916 audio_samplerate_combo.set_active(2);
918 scale_checkbox.set_active(false);
919 scale_checkbox.set_sensitive(false);
921 else if (p == "mpeg4") {
922 change_file_extension(".mp4");
923 audio_codec_combo.set_active(0);
924 video_codec_combo.set_active(4);
925 audio_bitrate_combo.set_active(3);
926 video_bitrate_combo.set_active(3);
927 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
928 audio_samplerate_combo.set_active(2);
930 audio_samplerate_combo.set_active(1);
935 audio_codec_combo.set_sensitive(true);
936 video_codec_combo.set_sensitive(true);
937 audio_bitrate_combo.set_sensitive(true);
938 video_bitrate_combo.set_sensitive(true);
939 audio_samplerate_combo.set_sensitive(true);
941 audio_codec_combo.set_sensitive(false);
942 video_codec_combo.set_sensitive(false);
943 audio_bitrate_combo.set_sensitive(false);
944 video_bitrate_combo.set_sensitive(false);
945 audio_samplerate_combo.set_sensitive(false);
948 Gtk::Table *t = (Gtk::Table*) preset_combo.get_parent();
949 Gtk::Table_Helpers::TableList c = t->children();
950 Gtk::Table_Helpers::TableList::iterator it;
951 if (p == "dvd-PAL" || p == "dvd-NTSC") {
952 for (it = c.begin(); it != c.end(); ++it) {
953 int row = it->get_top_attach();
954 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
955 it->get_widget()->hide();
959 for (it = c.begin(); it != c.end(); ++it) {
960 int row = it->get_top_attach();
961 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
962 it->get_widget()->show();
967 video_codec_combo_changed();
971 ExportVideoDialog::open_outfn_dialog ()
973 Gtk::FileChooserDialog dialog(_("Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
974 dialog.set_filename (outfn_path_entry.get_text());
976 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
977 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
979 int result = dialog.run();
981 if (result == Gtk::RESPONSE_OK) {
982 std::string filename = dialog.get_filename();
984 if (filename.length()) {
985 outfn_path_entry.set_text (filename);
991 ExportVideoDialog::open_invid_dialog ()
993 Gtk::FileChooserDialog dialog(_("Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
994 dialog.set_filename (invid_path_entry.get_text());
996 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
997 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
999 int result = dialog.run();
1001 if (result == Gtk::RESPONSE_OK) {
1002 std::string filename = dialog.get_filename();
1004 if (filename.length()) {
1005 invid_path_entry.set_text (filename);