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.
20 #ifdef WITH_VIDEOTIMELINE
28 #include <sys/types.h>
32 #include <sigc++/bind.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;
66 ExportVideoDialog::ExportVideoDialog (PublicEditor& ed, Session* s)
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 (_("Enable Debug Mode: Print ffmpeg Command & Output to stdout."))
95 set_name ("ExportVideoDialog");
96 set_position (Gtk::WIN_POS_MOUSE);
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 widow 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("from ardour session-start to session-end");
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 video-end");
153 insnd_combo.append_text("from video-start to video-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"));
161 if (node && node->property(X_("Filename"))) {
162 std::string filename = node->property(X_("Filename"))->value();
163 if (filename.at(0) != G_DIR_SEPARATOR) {
164 filename = Glib::build_filename (_session->session_directory().video_path(), filename);
166 invid_path_entry.set_text (filename);
169 l = manage (new Label (_("<b>Settings:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
170 l->set_use_markup ();
171 options_box->pack_start (*l, false, true, 4);
173 Table* t = manage (new Table (4, 12));
176 options_box->pack_start (*t, true, true, 4);
177 l = manage (new Label (_("Range:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
178 t->attach (*l, 0, 1, ty, ty+1);
179 t->attach (insnd_combo, 1, 4, ty, ty+1); ty++;
180 l = manage (new Label (_("Preset:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
181 t->attach (*l, 0, 1, ty, ty+1);
182 t->attach (preset_combo, 1, 4, ty, ty+1); ty++;
183 l = manage (new Label (_("Video Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
184 t->attach (*l, 0, 1, ty, ty+1);
185 t->attach (video_codec_combo, 1, 2, ty, ty+1);
186 l = manage (new Label (_("Video KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
187 t->attach (*l, 2, 3, ty, ty+1);
188 t->attach (video_bitrate_combo, 3, 4, ty, ty+1); ty++;
189 l = manage (new Label (_("Audio Codec:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
190 t->attach (*l, 0, 1, ty, ty+1);
191 t->attach (audio_codec_combo, 1, 2, ty, ty+1);
192 l = manage (new Label (_("Audio KBit/s:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
193 t->attach (*l, 2, 3, ty, ty+1);
194 t->attach (audio_bitrate_combo, 3, 4, ty, ty+1); ty++;
195 l = manage (new Label (_("Audio Samplerate:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
196 t->attach (*l, 0, 1, ty, ty+1);
197 t->attach (audio_samplerate_combo, 1, 2, ty, ty+1);
198 t->attach (normalize_checkbox, 2, 4, ty, ty+1); ty++;
199 t->attach (scale_checkbox, 0, 2, ty, ty+1);
200 t->attach (width_spinner, 2, 3, ty, ty+1);
201 t->attach (height_spinner, 3, 4, ty, ty+1); ty++;
202 t->attach (fps_checkbox, 0, 3, ty, ty+1);
203 t->attach (fps_combo, 3, 4, ty, ty+1); ty++;
204 t->attach (twopass_checkbox, 0, 2, ty, ty+1);
205 t->attach (aspect_checkbox, 2, 3, ty, ty+1);
206 t->attach (aspect_combo, 3, 4, ty, ty+1); ty++;
207 t->attach (bframes_checkbox, 0, 2, ty, ty+1);
208 t->attach (deinterlace_checkbox, 2, 4, ty, ty+1); ty++;
209 t->attach (meta_checkbox, 2, 4, ty, ty+1); ty++;
210 t->attach (optimizations_checkbox, 0, 1, ty, ty+1);
211 t->attach (optimizations_label, 1, 4, ty, ty+1); ty++;
212 #if 1 /* tentative debug mode */
213 t->attach (debug_checkbox, 0, 4, ty, ty+1); ty++;
216 preset_combo.set_name ("PaddedButton");
217 preset_combo.append_text("none");
218 preset_combo.append_text("dvd-mp2");
219 preset_combo.append_text("dvd-NTSC");
220 preset_combo.append_text("dvd-PAL");
221 preset_combo.append_text("flv");
222 preset_combo.append_text("mpeg4");
223 preset_combo.append_text("ogg");
224 preset_combo.append_text("you-tube");
225 preset_combo.set_active(0);
227 audio_codec_combo.set_name ("PaddedButton");
228 audio_codec_combo.append_text("ac3");
229 audio_codec_combo.append_text("aac");
230 audio_codec_combo.append_text("libmp3lame");
231 audio_codec_combo.append_text("libvorbis");
232 audio_codec_combo.append_text("mp2");
233 audio_codec_combo.append_text("pcm_s16le");
234 audio_codec_combo.set_active(2);
236 video_codec_combo.set_name ("PaddedButton");
237 video_codec_combo.append_text("flv");
238 video_codec_combo.append_text("libtheora");
239 video_codec_combo.append_text("mjpeg");
240 video_codec_combo.append_text("mpeg2video");
241 video_codec_combo.append_text("mpeg4");
242 video_codec_combo.append_text("x264 (baseline)");
243 video_codec_combo.append_text("x264 (hq)");
244 video_codec_combo.append_text("vpx (webm)");
245 video_codec_combo.append_text("copy");
246 video_codec_combo.set_active(4);
248 audio_bitrate_combo.set_name ("PaddedButton");
249 audio_bitrate_combo.append_text("64k");
250 audio_bitrate_combo.append_text("128k");
251 audio_bitrate_combo.append_text("192k");
252 audio_bitrate_combo.append_text("256k");
253 audio_bitrate_combo.append_text("320k");
254 audio_bitrate_combo.set_active(2);
256 audio_samplerate_combo.set_name ("PaddedButton");
257 audio_samplerate_combo.append_text("22050");
258 audio_samplerate_combo.append_text("44100");
259 audio_samplerate_combo.append_text("48000");
260 audio_samplerate_combo.set_active(2);
262 video_bitrate_combo.set_name ("PaddedButton");
263 video_bitrate_combo.append_text("200k");
264 video_bitrate_combo.append_text("800k");
265 video_bitrate_combo.append_text("2000k");
266 video_bitrate_combo.append_text("5000k");
267 video_bitrate_combo.append_text("8000k");
268 video_bitrate_combo.append_text("retain");
269 video_bitrate_combo.set_active(3);
271 fps_combo.set_name ("PaddedButton");
272 fps_combo.append_text("23.976");
273 fps_combo.append_text("24");
274 fps_combo.append_text("24.976");
275 fps_combo.append_text("25");
276 fps_combo.append_text("29.97");
277 fps_combo.append_text("30");
278 fps_combo.append_text("59.94");
279 fps_combo.append_text("60");
280 float tcfps = _session->timecode_frames_per_second();
281 if (fabs(tcfps - 23.976) < 0.01) { fps_combo.set_active(0); }
282 else if (fabs(tcfps - 24.0 ) < 0.01) { fps_combo.set_active(1); }
283 else if (fabs(tcfps - 24.976) < 0.01) { fps_combo.set_active(2); }
284 else if (fabs(tcfps - 25.0 ) < 0.01) { fps_combo.set_active(3); }
285 else if (fabs(tcfps - 29.97 ) < 0.01) { fps_combo.set_active(4); }
286 else if (fabs(tcfps - 30.0 ) < 0.01) { fps_combo.set_active(5); }
287 else if (fabs(tcfps - 59.94 ) < 0.01) { fps_combo.set_active(6); }
288 else if (fabs(tcfps - 60.0 ) < 0.01) { fps_combo.set_active(7); }
289 else { fps_combo.set_active(5); }
291 aspect_combo.set_name ("PaddedButton");
292 aspect_combo.append_text("4:3");
293 aspect_combo.append_text("16:9");
294 aspect_combo.set_active(1);
296 optimizations_checkbox.set_sensitive(false);
297 scale_checkbox_toggled();
298 aspect_checkbox_toggled();
299 fps_checkbox_toggled();
300 video_codec_combo_changed();
302 vbox->pack_start (*options_box, false, true, 4);
303 get_vbox()->set_spacing (4);
304 get_vbox()->pack_start (*vbox, false, false);
306 progress_box = manage (new VBox);
307 progress_box->pack_start (pbar, false, false);
308 progress_box->pack_start (abort_button, false, false);
309 get_vbox()->pack_start (*progress_box, false, false);
311 scale_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::scale_checkbox_toggled));
312 aspect_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::aspect_checkbox_toggled));
313 fps_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportVideoDialog::fps_checkbox_toggled));
314 preset_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportVideoDialog::preset_combo_changed));
315 video_codec_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportVideoDialog::video_codec_combo_changed));
316 outfn_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::open_outfn_dialog));
317 invid_browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::open_invid_dialog));
318 transcode_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::launch_export));
319 abort_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportVideoDialog::abort_clicked));
321 cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL);
322 get_action_area()->pack_start (transcode_button, false, false);
323 show_all_children ();
324 progress_box->hide();
327 ExportVideoDialog::~ExportVideoDialog ()
329 if (transcoder) { delete transcoder; transcoder = 0;}
333 ExportVideoDialog::on_show ()
339 ExportVideoDialog::abort_clicked ()
343 transcoder->cancel();
348 ExportVideoDialog::update_progress (framecnt_t c, framecnt_t a)
350 if (a == 0 || c > a) {
351 pbar.set_pulse_step(.1);
355 pbar.set_fraction ((double)c / (double) a);
359 ExportVideoDialog::finished ()
362 unlink(outfn_path_entry.get_text().c_str());
363 unlink (insnd.c_str());
364 warning << _("Video Export Failed or Was Aborted") << endmsg;
365 Gtk::Dialog::response(RESPONSE_CANCEL);
366 } else if (twopass) {
368 if (transcoder) { delete transcoder; transcoder = 0;}
371 if (twopass_checkbox.get_active()) {
372 std::string outfn = outfn_path_entry.get_text();
373 std::string p2log = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
374 unlink (p2log.c_str());
376 unlink (insnd.c_str());
377 Gtk::Dialog::response(RESPONSE_ACCEPT);
382 ExportVideoDialog::launch_export ()
384 std::string outfn = outfn_path_entry.get_text();
385 if (!confirm_video_outfn(outfn)) { return; }
388 cancel_button->hide();
389 transcode_button.hide();
390 pbar.set_size_request(300,-1);
391 pbar.set_text(_("Exporting Audio.."));
392 progress_box->show();
394 twopass = twopass_checkbox.get_active();
396 /* export audio track */
397 ExportTimespanPtr tsp = _session->get_export_handler()->add_timespan();
398 boost::shared_ptr<ExportChannelConfiguration> ccp = _session->get_export_handler()->add_channel_config();
399 boost::shared_ptr<ARDOUR::ExportFilename> fnp = _session->get_export_handler()->add_filename();
400 boost::shared_ptr<AudioGrapher::BroadcastInfo> b;
402 std::string vtl_samplerate = audio_samplerate_combo.get_active_text();
403 std::string vtl_normalize = normalize_checkbox.get_active()?"true":"false";
404 tree.read_buffer(std::string(
405 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
406 "<ExportFormatSpecification name=\"VTL-WAV-16\" id=\"3094591e-ccb9-4385-a93f-c9955ffeb1f0\">"
407 " <Encoding id=\"F_WAV\" type=\"T_Sndfile\" extension=\"wav\" name=\"WAV\" has-sample-format=\"true\" channel-limit=\"256\"/>"
408 " <SampleRate rate=\""+ vtl_samplerate +"\"/>"
409 " <SRCQuality quality=\"SRC_SincBest\"/>"
411 " <Option name=\"sample-format\" value=\"SF_16\"/>"
412 " <Option name=\"dithering\" value=\"D_None\"/>"
413 " <Option name=\"tag-metadata\" value=\"true\"/>"
414 " <Option name=\"tag-support\" value=\"false\"/>"
415 " <Option name=\"broadcast-info\" value=\"false\"/>"
416 " </EncodingOptions>"
418 " <Normalize enabled=\""+ vtl_normalize +"\" target=\"0\"/>"
421 " <Trim enabled=\"false\"/>"
422 " <Add enabled=\"false\">"
423 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
427 " <Trim enabled=\"false\"/>"
428 " <Add enabled=\"false\">"
429 " <Duration format=\"Timecode\" hours=\"0\" minutes=\"0\" seconds=\"0\" frames=\"0\"/>"
434 "</ExportFormatSpecification>"
436 boost::shared_ptr<ExportFormatSpecification> fmp = _session->get_export_handler()->add_format(*tree.root());
439 framepos_t start, end;
441 if (insnd_combo.get_active_row_number() == 1) {
442 transcoder = new TranscodeFfmpeg(invid_path_entry.get_text());
443 if (transcoder->probe_ok() && transcoder->get_fps() > 0) {
444 end = transcoder->get_duration() * _session->nominal_frame_rate() / transcoder->get_fps();
446 warning << _("Export Video: Cannot query duration of video-file, using duration from timeline instead.") << endmsg;
447 end = ARDOUR_UI::instance()->video_timeline->get_duration();
449 if (transcoder) {delete transcoder; transcoder = 0;}
451 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
453 printf("audio-range -- AV offset: %lld\n", av_offset);
461 start = _session->current_start_frame();
462 end = _session->current_end_frame();
465 printf("audio export-range %lld -> %lld\n", start, end);
468 tsp->set_range (start, end);
469 tsp->set_name ("mysession");
470 tsp->set_range_id ("session");
472 /* add master outs as default */
473 IO* master_out = _session->master_out()->output().get();
475 warning << _("Export Video: No Master Out Ports to Connect for Audio Export") << endmsg;
476 Gtk::Dialog::response(RESPONSE_CANCEL);
479 for (uint32_t n = 0; n < master_out->n_ports().n_audio(); ++n) {
480 PortExportChannel * channel = new PortExportChannel ();
481 channel->add_port (master_out->audio (n));
482 ExportChannelPtr chan_ptr (channel);
483 ccp->register_channel (chan_ptr);
487 fnp->set_timespan(tsp);
488 fnp->set_label("vtl");
489 fnp->include_label = true;
490 insnd = fnp->get_path(fmp);
492 /* do sound export */
493 _session->get_export_handler()->add_export_config (tsp, ccp, fmp, fnp, b);
494 _session->get_export_handler()->do_export();
495 boost::shared_ptr<ARDOUR::ExportStatus> status = _session->get_export_status ();
496 //status->running = true;
498 float previous_progress = 0.0;
499 while (status->running) {
500 if (aborted) { status->abort(); }
502 float progress = 0.0;
503 if (status->normalizing) {
504 pbar.set_text (_("Normalizing audio"));
505 progress = ((float) status->current_normalize_cycle) / status->total_normalize_cycles;
507 pbar.set_text (_("Exporting audio"));
508 progress = ((float) status->processed_frames_current_timespan) / status->total_frames_current_timespan;
510 if (progress < previous_progress) {
511 // Work around gtk bug
515 previous_progress = progress;
516 pbar.set_fraction (progress);
517 if (gtk_events_pending()) {
518 gtk_main_iteration ();
524 if (status->aborted()) {
525 unlink (insnd.c_str());
526 Gtk::Dialog::response(RESPONSE_CANCEL);
529 pbar.set_text (_("Encoding Video.."));
534 ExportVideoDialog::encode_pass (int pass)
536 std::string outfn = outfn_path_entry.get_text();
537 std::string invid = invid_path_entry.get_text();
539 transcoder = new TranscodeFfmpeg(invid);
540 if (!transcoder->ffexec_ok()) {
541 /* ffmpeg binary was not found. TranscodeFfmpeg prints a warning */
542 unlink (insnd.c_str());
543 Gtk::Dialog::response(RESPONSE_CANCEL);
546 if (!transcoder->probe_ok()) {
547 /* video input file can not be read */
548 warning << _("Export Video: Video input file cannot be read.") << endmsg;
549 unlink (insnd.c_str());
550 Gtk::Dialog::response(RESPONSE_CANCEL);
554 std::string preset = preset_combo.get_active_text();
555 FFSettings ffs ; /* = transcoder->default_encoder_settings(); */
558 if (fps_checkbox.get_active()) {
559 ffs["-r"] = fps_combo.get_active_text();
562 if (scale_checkbox.get_active()) {
563 ffs["-s"] = string_compose("%1x%2", width_spinner.get_value(), height_spinner.get_value());
565 ffs["-vcodec"] = video_codec_combo.get_active_text();
566 ffs["-acodec"] = audio_codec_combo.get_active_text();
568 if (video_bitrate_combo.get_active_text() == "retain" ) {
569 ffs["-sameq"] = "-y"; // we use '-y' as dummy parameter for non key/value options
571 ffs["-b:v"] = video_bitrate_combo.get_active_text();
573 ffs["-b:a"] = audio_bitrate_combo.get_active_text();
575 if (audio_codec_combo.get_active_text() == "aac" ) {
576 ffs["-strict"] = "-2";
579 if (video_codec_combo.get_active_text() == "x264 (hq)" ) {
580 ffs["-vcodec"] = "libx264";
581 ffs["-vprofile"] = "high";
583 else if (video_codec_combo.get_active_text() == "x264 (baseline)" ) {
584 ffs["-vcodec"] = "libx264";
585 ffs["-vpre"] = "baseline";
587 else if (video_codec_combo.get_active_text() == "vpx (webm)" ) {
588 ffs["-vcodec"] = "libvpx";
594 if (optimizations_checkbox.get_active()) {
595 if (video_codec_combo.get_active_text() == "mpeg2video") {
597 ffs["-trellis"] = "2";
599 ffs["-subcmp"] = "2";
601 else if (video_codec_combo.get_active_text() == "mpeg4") {
603 ffs["-flags"] = "+mv4+aic";
604 ffs["-trellis"] = "2";
606 ffs["-subcmp"] = "2";
609 else if (video_codec_combo.get_active_text() == "flv") {
612 ffs["-subcmp"] = "2";
613 ffs["-trellis"] = "2";
614 ffs["-flags"] = "+aic+mv0+mv4";
619 if (bframes_checkbox.get_active() && (
620 video_codec_combo.get_active_text() == "mpeg2video"
621 || video_codec_combo.get_active_text() == "mpeg4"
626 if (preset == "dvd-PAL") {
627 ffs.clear(); /* ignore all prev settings */
628 ffs["-target"] = "pal-dvd";
629 ffs["-aspect"] = "4:3"; /* required for DVD - may be overridden below */
631 else if (preset == "dvd-NTSC") {
632 ffs.clear(); /* ignore all prev settings */
633 ffs["-target"] = "ntsc-dvd";
634 ffs["-aspect"] = "4:3"; /* required for DVD - may be overridden below */
637 if (aspect_checkbox.get_active()) {
638 ffs["-aspect"] = aspect_combo.get_active_text();
640 if (deinterlace_checkbox.get_active()) {
641 ffs["-deinterlace"] = "-y"; // we use '-y' as dummy parameter for non key/value options
645 if (pass == 1 && twopass) {
646 pbar.set_text (_("Encoding Video.. Pass 1/2"));
650 ffs["-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
651 ffs["-f"] = get_file_extension(invid).empty()?"mov":get_file_extension(invid);
657 } else if (pass == 2) {
658 pbar.set_text (_("Encoding Video.. Pass 2/2"));
660 ffs["-passlogfile"] = Glib::path_get_dirname (outfn) + G_DIR_SEPARATOR + "ffmpeg2pass";
663 frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
664 double duration_s = 0;
666 if (insnd_combo.get_active_row_number() == 0) {
667 framecnt_t duration_f = _session->current_end_frame() - _session->current_start_frame();
668 duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
670 framecnt_t duration_f = ARDOUR_UI::instance()->video_timeline->get_duration();
671 if (av_offset < 0 ) {
672 duration_f += av_offset;
674 duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
677 std::ostringstream osstream; osstream << duration_s;
678 ffs["-t"] = osstream.str();
679 if (fps_checkbox.get_active()) {
680 transcoder->set_duration(duration_s * atof(fps_combo.get_active_text()));
682 transcoder->set_duration(duration_s * transcoder->get_fps());
685 if (insnd_combo.get_active_row_number() == 0) {
686 const framepos_t start = _session->current_start_frame();
687 const framepos_t snend = _session->current_end_frame();
688 const frameoffset_t vid_duration = ARDOUR_UI::instance()->video_timeline->get_duration();
691 printf("AV offset: %lld Vid-len: %lld Vid-end: %lld || start:%lld || end:%lld\n",
692 av_offset, vid_duration, av_offset+vid_duration, start, snend); // XXX
695 if (av_offset > start && av_offset + vid_duration < snend) {
696 transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(),
697 (snend - (av_offset + vid_duration)) / (double)_session->nominal_frame_rate());
698 } else if (av_offset > start) {
699 transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(), 0);
700 } else if (av_offset + vid_duration < snend) {
701 transcoder->set_leadinout(0, (snend - (av_offset + vid_duration)) / (double)_session->nominal_frame_rate());
702 transcoder->set_avoffset((av_offset - start) / (double)_session->nominal_frame_rate());
704 transcoder->set_avoffset((av_offset - start) / (double)_session->nominal_frame_rate());
706 } else if (av_offset < 0) {
707 /* from 00:00:00:00 to video-end */
708 transcoder->set_avoffset(av_offset / (double)_session->nominal_frame_rate());
711 FFSettings meta = transcoder->default_meta_data();
712 if (meta_checkbox.get_active()) {
713 ARDOUR::SessionMetadata * session_data = ARDOUR::SessionMetadata::Metadata();
714 if (session_data->year() > 0 ) {
715 std::ostringstream osstream; osstream << session_data->year();
716 meta["year"] = osstream.str();
718 if (session_data->track_number() > 0 ) {
719 std::ostringstream osstream; osstream << session_data->track_number();
720 meta["track"] = osstream.str();
722 if (session_data->disc_number() > 0 ) {
723 std::ostringstream osstream; osstream << session_data->disc_number();
724 meta["disc"] = osstream.str();
726 if (!session_data->title().empty()) {meta["title"] = session_data->title();}
727 if (!session_data->artist().empty()) {meta["author"] = session_data->artist();}
728 if (!session_data->album_artist().empty()) {meta["album_artist"] = session_data->album_artist();}
729 if (!session_data->album().empty()) {meta["album"] = session_data->album();}
730 if (!session_data->genre().empty()) {meta["genre"] = session_data->genre();}
731 if (!session_data->composer().empty()) {meta["composer"] = session_data->composer();}
732 if (!session_data->comment().empty()) {meta["comment"] = session_data->comment();}
733 if (!session_data->copyright().empty()) {meta["copyright"] = session_data->copyright();}
734 if (!session_data->subtitle().empty()) {meta["description"] = session_data->subtitle();}
737 #if 1 /* tentative debug mode */
738 if (debug_checkbox.get_active()) {
739 transcoder->set_debug(true);
743 transcoder->Progress.connect(*this, invalidator (*this), boost::bind (&ExportVideoDialog::update_progress , this, _1, _2), gui_context());
744 transcoder->Finished.connect(*this, invalidator (*this), boost::bind (&ExportVideoDialog::finished, this), gui_context());
745 if (!transcoder->encode(outfn, insnd, invid, ffs, meta, map)) {
746 ARDOUR_UI::instance()->popup_error(_("Transcoding failed."));
747 Gtk::Dialog::response(RESPONSE_CANCEL);
753 ExportVideoDialog::change_file_extension (std::string ext)
755 outfn_path_entry.set_text (
756 strip_file_extension(outfn_path_entry.get_text()) + ext
761 ExportVideoDialog::scale_checkbox_toggled ()
763 width_spinner.set_sensitive(scale_checkbox.get_active());
764 height_spinner.set_sensitive(scale_checkbox.get_active());
768 ExportVideoDialog::fps_checkbox_toggled ()
770 fps_combo.set_sensitive(fps_checkbox.get_active());
774 ExportVideoDialog::aspect_checkbox_toggled ()
776 aspect_combo.set_sensitive(aspect_checkbox.get_active());
780 ExportVideoDialog::video_codec_combo_changed ()
782 if (( video_codec_combo.get_active_text() == "mpeg4"
783 ||video_codec_combo.get_active_text() == "mpeg2video"
785 preset_combo.get_active_text() == "dvd-PAL"
786 ||preset_combo.get_active_text() == "dvd-NTSC"
788 bframes_checkbox.set_sensitive(true);
789 optimizations_checkbox.set_sensitive(true);
790 if (video_codec_combo.get_active_text() == "mpeg2video") {
791 optimizations_label.set_text("-mbd rd -trellis 2 -cmp 2 -subcmp 2"); // mpeg2
792 } else if (video_codec_combo.get_active_text() == "mpeg4") {
793 optimizations_label.set_text("-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300"); // mpeg4
795 optimizations_label.set_text("-mbd 2 -cmp 2 -subcmp 2 -trellis 2 -flags +aic+mv0+mv4 -g 160"); // flv
798 bframes_checkbox.set_sensitive(false);
799 bframes_checkbox.set_active(false);
800 optimizations_checkbox.set_sensitive(false);
801 optimizations_checkbox.set_active(false);
802 optimizations_label.set_text("-");
807 ExportVideoDialog::preset_combo_changed ()
809 std::string p = preset_combo.get_active_text();
810 scale_checkbox.set_sensitive(true);
813 change_file_extension(".flv");
814 audio_codec_combo.set_active(1);
815 video_codec_combo.set_active(0);
816 audio_bitrate_combo.set_active(1);
817 video_bitrate_combo.set_active(1);
818 audio_samplerate_combo.set_active(1);
820 else if (p == "you-tube") {
821 change_file_extension(".avi");
822 audio_codec_combo.set_active(2);
823 video_codec_combo.set_active(5);
824 audio_bitrate_combo.set_active(1);
825 video_bitrate_combo.set_active(2);
826 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
827 audio_samplerate_combo.set_active(2);
829 audio_samplerate_combo.set_active(1);
832 else if (p == "ogg") {
833 change_file_extension(".ogv");
834 audio_codec_combo.set_active(3);
835 video_codec_combo.set_active(1);
836 audio_bitrate_combo.set_active(2);
837 video_bitrate_combo.set_active(2);
838 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
839 audio_samplerate_combo.set_active(2);
841 audio_samplerate_combo.set_active(1);
844 else if (p == "dvd-mp2") {
845 change_file_extension(".mpg");
846 audio_codec_combo.set_active(4);
847 video_codec_combo.set_active(3);
848 audio_bitrate_combo.set_active(3);
849 video_bitrate_combo.set_active(3);
850 audio_samplerate_combo.set_active(2);
852 else if (p == "dvd-NTSC" || p == "dvd-PAL") {
853 change_file_extension(".mpg");
854 audio_codec_combo.set_active(5);
855 video_codec_combo.set_active(3);
856 audio_bitrate_combo.set_active(3);
857 video_bitrate_combo.set_active(3);
858 audio_samplerate_combo.set_active(2);
860 scale_checkbox.set_active(false);
861 scale_checkbox.set_sensitive(false);
863 else if (p == "mpeg4") {
864 change_file_extension(".mp4");
865 audio_codec_combo.set_active(0);
866 video_codec_combo.set_active(4);
867 audio_bitrate_combo.set_active(3);
868 video_bitrate_combo.set_active(3);
869 if (_session->nominal_frame_rate() == 48000 || _session->nominal_frame_rate() == 96000) {
870 audio_samplerate_combo.set_active(2);
872 audio_samplerate_combo.set_active(1);
877 audio_codec_combo.set_sensitive(true);
878 video_codec_combo.set_sensitive(true);
879 audio_bitrate_combo.set_sensitive(true);
880 video_bitrate_combo.set_sensitive(true);
881 audio_samplerate_combo.set_sensitive(true);
883 audio_codec_combo.set_sensitive(false);
884 video_codec_combo.set_sensitive(false);
885 audio_bitrate_combo.set_sensitive(false);
886 video_bitrate_combo.set_sensitive(false);
887 audio_samplerate_combo.set_sensitive(false);
890 Gtk::Table *t = (Gtk::Table*) preset_combo.get_parent();
891 Gtk::Table_Helpers::TableList c = t->children();
892 Gtk::Table_Helpers::TableList::iterator it;
893 if (p == "dvd-PAL" || p == "dvd-NTSC") {
894 for (it = c.begin(); it != c.end(); ++it) {
895 int row = it->get_top_attach();
896 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
897 it->get_widget()->hide();
901 for (it = c.begin(); it != c.end(); ++it) {
902 int row = it->get_top_attach();
903 if (row == 2 || row == 3 || row== 5 || row== 6 || row == 9) {
904 it->get_widget()->show();
909 video_codec_combo_changed();
913 ExportVideoDialog::open_outfn_dialog ()
915 Gtk::FileChooserDialog dialog(_("Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
916 dialog.set_filename (outfn_path_entry.get_text());
918 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
919 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
921 int result = dialog.run();
923 if (result == Gtk::RESPONSE_OK) {
924 std::string filename = dialog.get_filename();
926 if (filename.length()) {
927 outfn_path_entry.set_text (filename);
933 ExportVideoDialog::open_invid_dialog ()
935 Gtk::FileChooserDialog dialog(_("Save Exported Video File"), Gtk::FILE_CHOOSER_ACTION_SAVE);
936 dialog.set_filename (invid_path_entry.get_text());
938 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
939 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
941 int result = dialog.run();
943 if (result == Gtk::RESPONSE_OK) {
944 std::string filename = dialog.get_filename();
946 if (filename.length()) {
947 invid_path_entry.set_text (filename);
952 #endif /* WITH_VIDEOTIMELINE */