2013-03-12 17:00:09 -04:00
/*
Copyright ( C ) 2010 Paul Davis
Author : Robin Gareus < robin @ gareus . org >
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include <cstdio>
# include <string>
# include <sstream>
# include <iomanip>
# include <unistd.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
# include <sigc++/bind.h>
2015-10-05 16:10:58 -04:00
# include "pbd/gstdio_compat.h"
2013-07-15 14:29:00 -04:00
2013-03-12 17:00:09 -04:00
# include "pbd/error.h"
# include "pbd/convert.h"
2015-02-27 14:45:44 -05:00
# include "gtkmm2ext/keyboard.h"
2013-03-12 17:00:09 -04:00
# include "gtkmm2ext/utils.h"
# include "ardour/session_directory.h"
# include "ardour/profile.h"
# include "ardour/template_utils.h"
# include "ardour/session.h"
# include "ardour_ui.h"
# include "gui_thread.h"
# include "ardour/export_handler.h"
# include "ardour/export_status.h"
# include "ardour/export_timespan.h"
# include "ardour/export_channel_configuration.h"
# include "ardour/export_format_specification.h"
# include "ardour/export_filename.h"
# include "ardour/route.h"
# include "ardour/session_metadata.h"
# include "ardour/broadcast_info.h"
# include "opts.h"
# include "export_video_dialog.h"
# include "utils_videotl.h"
# include "i18n.h"
using namespace Gtk ;
using namespace std ;
using namespace PBD ;
using namespace ARDOUR ;
2013-08-03 10:54:57 -04:00
using namespace VideoUtils ;
2013-03-12 17:00:09 -04:00
2015-02-27 17:17:26 -05:00
ExportVideoDialog : : ExportVideoDialog ( )
2013-03-12 17:00:09 -04:00
: ArdourDialog ( _ ( " Export Video File " ) )
2015-02-27 20:31:08 -05:00
, _aborted ( false )
, _twopass ( false )
, _firstpass ( false )
, _normalize ( false )
, _previous_progress ( 0 )
, _transcoder ( 0 )
, _video_source_aspect_ratio ( - 1 )
, _suspend_signals ( false )
2013-04-02 18:58:19 -04:00
, outfn_path_label ( _ ( " File: " ) , Gtk : : ALIGN_LEFT )
2013-03-12 17:00:09 -04:00
, outfn_browse_button ( _ ( " Browse " ) )
2013-04-02 18:58:19 -04:00
, invid_path_label ( _ ( " Video: " ) , Gtk : : ALIGN_LEFT )
2013-03-12 17:00:09 -04:00
, invid_browse_button ( _ ( " Browse " ) )
, transcode_button ( _ ( " Export " ) )
, abort_button ( _ ( " Abort " ) )
2015-03-24 22:39:47 -04:00
, progress_box ( 0 )
2013-03-12 17:00:09 -04:00
, scale_checkbox ( _ ( " Scale Video (W x H): " ) )
2015-02-27 20:31:08 -05:00
, scale_aspect ( _ ( " Retain Aspect " ) )
2013-04-02 18:58:19 -04:00
, width_adjustment ( 768 , 128 , 1920 , 1 , 16 , 0 )
2013-03-12 17:00:09 -04:00
, width_spinner ( width_adjustment )
2013-04-02 18:58:19 -04:00
, height_adjustment ( 576 , 128 , 1920 , 1 , 16 , 0 )
2013-03-12 17:00:09 -04:00
, height_spinner ( height_adjustment )
, aspect_checkbox ( _ ( " Set Aspect Ratio: " ) )
, normalize_checkbox ( _ ( " Normalize Audio " ) )
, twopass_checkbox ( _ ( " 2 Pass Encoding " ) )
2013-04-02 18:58:19 -04:00
, optimizations_checkbox ( _ ( " Codec Optimizations: " ) )
2013-03-12 17:00:09 -04:00
, optimizations_label ( " - " )
, deinterlace_checkbox ( _ ( " Deinterlace " ) )
, bframes_checkbox ( _ ( " Use [2] B-frames (MPEG 2 or 4 only) " ) )
, fps_checkbox ( _ ( " Override FPS (Default is to retain FPS from the input video file): " ) )
, meta_checkbox ( _ ( " Include Session Metadata " ) )
# if 1 /* tentative debug mode */
2013-07-23 14:24:23 -04:00
, debug_checkbox ( _ ( " Debug Mode: Print ffmpeg command and output to stdout. " ) )
2013-03-12 17:00:09 -04:00
# endif
{
set_name ( " ExportVideoDialog " ) ;
set_modal ( true ) ;
set_skip_taskbar_hint ( true ) ;
set_resizable ( false ) ;
Gtk : : Label * l ;
vbox = manage ( new VBox ) ;
VBox * options_box = manage ( new VBox ) ;
HBox * path_hbox ;
2013-03-27 11:04:56 -04:00
/* check if ffmpeg can be found */
2015-03-23 22:28:07 -04:00
_transcoder = new TranscodeFfmpeg ( X_ ( " " ) ) ;
2015-02-27 20:31:08 -05:00
if ( ! _transcoder - > ffexec_ok ( ) ) {
2015-12-22 10:43:26 -05:00
l = manage ( new Label ( _ ( " ffmpeg installation was not found. Video Export is not possible. See the Log window for more information. " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-03-27 11:04:56 -04:00
l - > set_line_wrap ( ) ;
vbox - > pack_start ( * l , false , false , 8 ) ;
get_vbox ( ) - > pack_start ( * vbox , false , false ) ;
add_button ( Stock : : OK , RESPONSE_CANCEL ) ;
show_all_children ( ) ;
2015-03-23 20:32:32 -04:00
delete _transcoder ; _transcoder = 0 ;
2013-03-27 11:04:56 -04:00
return ;
}
2015-02-27 20:31:08 -05:00
delete _transcoder ; _transcoder = 0 ;
2013-03-12 17:00:09 -04:00
2015-02-27 16:54:23 -05:00
l = manage ( new Label ( _ ( " <b>Output:</b> (file extension defines format) " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-03-12 17:00:09 -04:00
l - > set_use_markup ( ) ;
2013-04-02 18:58:19 -04:00
vbox - > pack_start ( * l , false , false , 4 ) ;
2013-03-12 17:00:09 -04:00
path_hbox = manage ( new HBox ) ;
path_hbox - > pack_start ( outfn_path_label , false , false , 3 ) ;
path_hbox - > pack_start ( outfn_path_entry , true , true , 3 ) ;
path_hbox - > pack_start ( outfn_browse_button , false , false , 3 ) ;
2013-04-02 18:58:19 -04:00
vbox - > pack_start ( * path_hbox , false , false , 2 ) ;
2015-02-27 16:54:23 -05:00
l = manage ( new Label ( _ ( " <b>Input Video:</b> " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-04-02 18:58:19 -04:00
l - > set_use_markup ( ) ;
vbox - > pack_start ( * l , false , false , 4 ) ;
2013-03-12 17:00:09 -04:00
path_hbox = manage ( new HBox ) ;
path_hbox - > pack_start ( invid_path_label , false , false , 3 ) ;
path_hbox - > pack_start ( invid_path_entry , true , true , 3 ) ;
path_hbox - > pack_start ( invid_browse_button , false , false , 3 ) ;
2013-04-02 18:58:19 -04:00
vbox - > pack_start ( * path_hbox , false , false , 2 ) ;
2013-03-12 17:00:09 -04:00
path_hbox = manage ( new HBox ) ;
2013-04-02 18:58:19 -04:00
l = manage ( new Label ( _ ( " Audio: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
path_hbox - > pack_start ( * l , false , false , 3 ) ;
l = manage ( new Label ( _ ( " Master Bus " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
path_hbox - > pack_start ( * l , false , false , 2 ) ;
vbox - > pack_start ( * path_hbox , false , false , 2 ) ;
2013-03-12 17:00:09 -04:00
2013-06-13 20:10:31 -04:00
insnd_combo . append_text ( string_compose ( _ ( " from the %1 session's start to the session's end " ) , PROGRAM_NAME ) ) ;
2013-03-12 17:00:09 -04:00
outfn_path_entry . set_width_chars ( 38 ) ;
l = manage ( new Label ( _ ( " <b>Settings:</b> " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
l - > set_use_markup ( ) ;
options_box - > pack_start ( * l , false , true , 4 ) ;
2013-04-02 18:58:19 -04:00
Table * t = manage ( new Table ( 4 , 12 ) ) ;
2013-03-12 17:00:09 -04:00
t - > set_spacings ( 4 ) ;
2013-04-02 18:58:19 -04:00
int ty = 0 ;
2013-03-12 17:00:09 -04:00
options_box - > pack_start ( * t , true , true , 4 ) ;
2013-04-02 18:58:19 -04:00
l = manage ( new Label ( _ ( " Range: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
t - > attach ( * l , 0 , 1 , ty , ty + 1 ) ;
t - > attach ( insnd_combo , 1 , 4 , ty , ty + 1 ) ; ty + + ;
2013-03-12 17:00:09 -04:00
l = manage ( new Label ( _ ( " Preset: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-04-02 18:58:19 -04:00
t - > attach ( * l , 0 , 1 , ty , ty + 1 ) ;
t - > attach ( preset_combo , 1 , 4 , ty , ty + 1 ) ; ty + + ;
2013-03-12 17:00:09 -04:00
l = manage ( new Label ( _ ( " Video Codec: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-04-02 18:58:19 -04:00
t - > attach ( * l , 0 , 1 , ty , ty + 1 ) ;
t - > attach ( video_codec_combo , 1 , 2 , ty , ty + 1 ) ;
2013-03-12 17:00:09 -04:00
l = manage ( new Label ( _ ( " Video KBit/s: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-04-02 18:58:19 -04:00
t - > attach ( * l , 2 , 3 , ty , ty + 1 ) ;
t - > attach ( video_bitrate_combo , 3 , 4 , ty , ty + 1 ) ; ty + + ;
2013-03-12 17:00:09 -04:00
l = manage ( new Label ( _ ( " Audio Codec: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-04-02 18:58:19 -04:00
t - > attach ( * l , 0 , 1 , ty , ty + 1 ) ;
t - > attach ( audio_codec_combo , 1 , 2 , ty , ty + 1 ) ;
2013-03-12 17:00:09 -04:00
l = manage ( new Label ( _ ( " Audio KBit/s: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-04-02 18:58:19 -04:00
t - > attach ( * l , 2 , 3 , ty , ty + 1 ) ;
t - > attach ( audio_bitrate_combo , 3 , 4 , ty , ty + 1 ) ; ty + + ;
2013-03-12 17:00:09 -04:00
l = manage ( new Label ( _ ( " Audio Samplerate: " ) , Gtk : : ALIGN_LEFT , Gtk : : ALIGN_CENTER , false ) ) ;
2013-04-02 18:58:19 -04:00
t - > attach ( * l , 0 , 1 , ty , ty + 1 ) ;
t - > attach ( audio_samplerate_combo , 1 , 2 , ty , ty + 1 ) ;
t - > attach ( normalize_checkbox , 2 , 4 , ty , ty + 1 ) ; ty + + ;
2015-02-27 20:31:08 -05:00
t - > attach ( scale_checkbox , 0 , 1 , ty , ty + 1 ) ;
t - > attach ( scale_aspect , 1 , 2 , ty , ty + 1 ) ;
2013-04-02 18:58:19 -04:00
t - > attach ( width_spinner , 2 , 3 , ty , ty + 1 ) ;
t - > attach ( height_spinner , 3 , 4 , ty , ty + 1 ) ; ty + + ;
t - > attach ( fps_checkbox , 0 , 3 , ty , ty + 1 ) ;
t - > attach ( fps_combo , 3 , 4 , ty , ty + 1 ) ; ty + + ;
t - > attach ( twopass_checkbox , 0 , 2 , ty , ty + 1 ) ;
t - > attach ( aspect_checkbox , 2 , 3 , ty , ty + 1 ) ;
t - > attach ( aspect_combo , 3 , 4 , ty , ty + 1 ) ; ty + + ;
t - > attach ( bframes_checkbox , 0 , 2 , ty , ty + 1 ) ;
t - > attach ( deinterlace_checkbox , 2 , 4 , ty , ty + 1 ) ; ty + + ;
t - > attach ( meta_checkbox , 2 , 4 , ty , ty + 1 ) ; ty + + ;
t - > attach ( optimizations_checkbox , 0 , 1 , ty , ty + 1 ) ;
t - > attach ( optimizations_label , 1 , 4 , ty , ty + 1 ) ; ty + + ;
2013-03-12 17:00:09 -04:00
# if 1 /* tentative debug mode */
2013-04-02 18:58:19 -04:00
t - > attach ( debug_checkbox , 0 , 4 , ty , ty + 1 ) ; ty + + ;
2013-03-12 17:00:09 -04:00
# endif
preset_combo . append_text ( " none " ) ;
preset_combo . append_text ( " dvd-mp2 " ) ;
preset_combo . append_text ( " dvd-NTSC " ) ;
preset_combo . append_text ( " dvd-PAL " ) ;
preset_combo . append_text ( " flv " ) ;
preset_combo . append_text ( " mpeg4 " ) ;
2015-02-27 20:31:08 -05:00
preset_combo . append_text ( " mp4/h264/aac " ) ;
2013-03-12 17:00:09 -04:00
preset_combo . append_text ( " ogg " ) ;
2015-02-27 20:31:08 -05:00
preset_combo . append_text ( " webm " ) ;
2013-03-12 17:00:09 -04:00
preset_combo . append_text ( " you-tube " ) ;
2015-02-27 16:54:23 -05:00
audio_codec_combo . append_text ( _ ( " (default for format) " ) ) ;
2013-03-12 17:00:09 -04:00
audio_codec_combo . append_text ( " ac3 " ) ;
2013-03-31 13:34:05 -04:00
audio_codec_combo . append_text ( " aac " ) ;
2013-03-12 17:00:09 -04:00
audio_codec_combo . append_text ( " libmp3lame " ) ;
audio_codec_combo . append_text ( " libvorbis " ) ;
audio_codec_combo . append_text ( " mp2 " ) ;
audio_codec_combo . append_text ( " pcm_s16le " ) ;
2015-02-27 16:54:23 -05:00
video_codec_combo . append_text ( _ ( " (default for format) " ) ) ;
2013-03-12 17:00:09 -04:00
video_codec_combo . append_text ( " flv " ) ;
video_codec_combo . append_text ( " libtheora " ) ;
video_codec_combo . append_text ( " mjpeg " ) ;
video_codec_combo . append_text ( " mpeg2video " ) ;
video_codec_combo . append_text ( " mpeg4 " ) ;
2013-09-08 12:26:02 -04:00
video_codec_combo . append_text ( " h264 " ) ;
2013-03-31 13:34:05 -04:00
video_codec_combo . append_text ( " vpx (webm) " ) ;
2013-03-12 17:00:09 -04:00
video_codec_combo . append_text ( " copy " ) ;
2015-02-27 16:54:23 -05:00
audio_bitrate_combo . append_text ( _ ( " (default) " ) ) ;
2013-03-12 17:00:09 -04:00
audio_bitrate_combo . append_text ( " 64k " ) ;
audio_bitrate_combo . append_text ( " 128k " ) ;
audio_bitrate_combo . append_text ( " 192k " ) ;
audio_bitrate_combo . append_text ( " 256k " ) ;
audio_bitrate_combo . append_text ( " 320k " ) ;
audio_samplerate_combo . append_text ( " 22050 " ) ;
audio_samplerate_combo . append_text ( " 44100 " ) ;
audio_samplerate_combo . append_text ( " 48000 " ) ;
2015-02-27 16:54:23 -05:00
video_bitrate_combo . append_text ( _ ( " (default) " ) ) ;
video_bitrate_combo . append_text ( _ ( " (retain) " ) ) ;
2013-03-12 17:00:09 -04:00
video_bitrate_combo . append_text ( " 200k " ) ;
video_bitrate_combo . append_text ( " 800k " ) ;
video_bitrate_combo . append_text ( " 2000k " ) ;
video_bitrate_combo . append_text ( " 5000k " ) ;
video_bitrate_combo . append_text ( " 8000k " ) ;
fps_combo . append_text ( " 23.976 " ) ;
fps_combo . append_text ( " 24 " ) ;
fps_combo . append_text ( " 24.976 " ) ;
fps_combo . append_text ( " 25 " ) ;
fps_combo . append_text ( " 29.97 " ) ;
fps_combo . append_text ( " 30 " ) ;
fps_combo . append_text ( " 59.94 " ) ;
fps_combo . append_text ( " 60 " ) ;
aspect_combo . append_text ( " 4:3 " ) ;
aspect_combo . append_text ( " 16:9 " ) ;
2013-04-02 18:58:19 -04:00
vbox - > pack_start ( * options_box , false , true , 4 ) ;
2013-03-12 17:00:09 -04:00
get_vbox ( ) - > set_spacing ( 4 ) ;
get_vbox ( ) - > pack_start ( * vbox , false , false ) ;
progress_box = manage ( new VBox ) ;
progress_box - > pack_start ( pbar , false , false ) ;
progress_box - > pack_start ( abort_button , false , false ) ;
get_vbox ( ) - > pack_start ( * progress_box , false , false ) ;
scale_checkbox . signal_toggled ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : scale_checkbox_toggled ) ) ;
aspect_checkbox . signal_toggled ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : aspect_checkbox_toggled ) ) ;
fps_checkbox . signal_toggled ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : fps_checkbox_toggled ) ) ;
preset_combo . signal_changed ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : preset_combo_changed ) ) ;
video_codec_combo . signal_changed ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : video_codec_combo_changed ) ) ;
outfn_browse_button . signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : open_outfn_dialog ) ) ;
invid_browse_button . signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : open_invid_dialog ) ) ;
transcode_button . signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : launch_export ) ) ;
abort_button . signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : abort_clicked ) ) ;
2015-02-27 20:31:08 -05:00
invid_path_entry . signal_changed ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : set_original_file_information ) ) ;
width_spinner . signal_value_changed ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : width_value_changed ) ) ;
height_spinner . signal_value_changed ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : height_value_changed ) ) ;
2013-03-12 17:00:09 -04:00
cancel_button = add_button ( Stock : : CANCEL , RESPONSE_CANCEL ) ;
get_action_area ( ) - > pack_start ( transcode_button , false , false ) ;
show_all_children ( ) ;
progress_box - > hide ( ) ;
}
ExportVideoDialog : : ~ ExportVideoDialog ( )
{
2015-02-27 20:31:08 -05:00
if ( _transcoder ) { delete _transcoder ; _transcoder = 0 ; }
2013-03-12 17:00:09 -04:00
}
2015-02-27 20:31:08 -05:00
void
ExportVideoDialog : : set_original_file_information ( )
{
assert ( _transcoder = = 0 ) ;
std : : string infile = invid_path_entry . get_text ( ) ;
if ( scale_checkbox . get_active ( ) ) {
// user may have set custom values already, don't touch.
return ;
}
if ( infile = = " " | | ! Glib : : file_test ( infile , Glib : : FILE_TEST_EXISTS ) ) {
return ;
}
_transcoder = new TranscodeFfmpeg ( infile ) ;
if ( _transcoder - > probe_ok ( ) ) {
_video_source_aspect_ratio = - 1 ;
width_spinner . set_value ( _transcoder - > get_width ( ) ) ;
height_spinner . set_value ( _transcoder - > get_height ( ) ) ;
_video_source_aspect_ratio = _transcoder - > get_aspect ( ) ;
}
2015-02-27 17:17:26 -05:00
2015-02-27 20:31:08 -05:00
delete _transcoder ; _transcoder = 0 ;
}
2015-02-27 17:17:26 -05:00
void
ExportVideoDialog : : apply_state ( TimeSelection & tme , bool range )
{
2015-02-27 20:31:08 -05:00
_suspend_dirty = true ; // TODO really just queue 'dirty' and mark session dirty on "Export"
2015-02-27 17:17:26 -05:00
export_range = tme ;
2015-02-27 20:31:08 -05:00
_video_source_aspect_ratio = - 1 ;
2015-02-27 17:17:26 -05:00
outfn_path_entry . set_text ( _session - > session_directory ( ) . export_path ( ) + G_DIR_SEPARATOR + " export.avi " ) ;
2015-02-27 20:31:08 -05:00
// TODO remember setting for export-range.. somehow, (let explicit range override)
2015-02-27 17:17:26 -05:00
frameoffset_t av_offset = ARDOUR_UI : : instance ( ) - > video_timeline - > get_offset ( ) ;
if ( av_offset < 0 ) {
insnd_combo . append_text ( _ ( " from 00:00:00:00 to the video's end " ) ) ;
} else {
insnd_combo . append_text ( _ ( " from the video's start to the video's end " ) ) ;
}
if ( ! export_range . empty ( ) ) {
insnd_combo . append_text ( _ ( " Selected range " ) ) ; // TODO show export_range.start() -> export_range.end_frame()
}
if ( range ) {
insnd_combo . set_active ( 2 ) ;
} else {
insnd_combo . set_active ( 0 ) ;
}
2015-02-27 20:31:08 -05:00
preset_combo . set_active ( 0 ) ;
audio_codec_combo . set_active ( 0 ) ;
video_codec_combo . set_active ( 0 ) ;
audio_bitrate_combo . set_active ( 0 ) ;
audio_samplerate_combo . set_active ( 2 ) ;
video_bitrate_combo . set_active ( 0 ) ;
aspect_combo . set_active ( 1 ) ;
scale_checkbox . set_active ( false ) ;
scale_aspect . set_active ( true ) ;
aspect_checkbox . set_active ( false ) ;
normalize_checkbox . set_active ( false ) ;
twopass_checkbox . set_active ( false ) ;
optimizations_checkbox . set_active ( false ) ;
deinterlace_checkbox . set_active ( false ) ;
bframes_checkbox . set_active ( false ) ;
fps_checkbox . set_active ( false ) ;
meta_checkbox . set_active ( false ) ;
2015-02-27 17:17:26 -05:00
float tcfps = _session - > timecode_frames_per_second ( ) ;
2015-02-27 20:31:08 -05:00
LocaleGuard lg ( X_ ( " C " ) ) ;
2015-02-27 17:17:26 -05:00
XMLNode * node = _session - > extra_xml ( X_ ( " Videotimeline " ) ) ;
2015-03-23 22:28:07 -04:00
bool filenameset = false ;
2015-02-27 17:17:26 -05:00
if ( node ) {
if ( node - > property ( X_ ( " OriginalVideoFile " ) ) ) {
std : : string filename = node - > property ( X_ ( " OriginalVideoFile " ) ) - > value ( ) ;
if ( Glib : : file_test ( filename , Glib : : FILE_TEST_EXISTS ) ) {
invid_path_entry . set_text ( filename ) ;
filenameset = true ;
}
}
if ( ! filenameset
& & node - > property ( X_ ( " Filename " ) )
& & node - > property ( X_ ( " LocalFile " ) )
& & node - > property ( X_ ( " LocalFile " ) ) - > value ( ) = = X_ ( " 1 " )
)
{
std : : string filename = node - > property ( X_ ( " Filename " ) ) - > value ( ) ;
if ( filename . at ( 0 ) ! = G_DIR_SEPARATOR )
{
filename = Glib : : build_filename ( _session - > session_directory ( ) . video_path ( ) , filename ) ;
}
if ( Glib : : file_test ( filename , Glib : : FILE_TEST_EXISTS ) )
{
invid_path_entry . set_text ( filename ) ;
filenameset = true ;
}
}
2015-03-23 22:28:07 -04:00
}
if ( ! filenameset ) {
invid_path_entry . set_text ( X_ ( " " ) ) ;
2015-02-27 17:17:26 -05:00
}
node = _session - > extra_xml ( X_ ( " Videoexport " ) ) ;
if ( node ) {
2015-02-27 20:31:08 -05:00
const XMLProperty * prop ;
prop = node - > property ( X_ ( " ChangeGeometry " ) ) ;
if ( prop ) { scale_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " KeepAspect " ) ) ;
if ( prop ) { scale_aspect . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " ChangeAspect " ) ) ;
if ( prop ) { aspect_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " NormalizeAudio " ) ) ;
if ( prop ) { normalize_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " TwoPassEncode " ) ) ;
if ( prop ) { twopass_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " CodecOptimzations " ) ) ;
if ( prop ) { optimizations_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " Deinterlace " ) ) ;
if ( prop ) { deinterlace_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " BFrames " ) ) ;
if ( prop ) { bframes_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " ChangeFPS " ) ) ;
if ( prop ) { fps_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " Metadata " ) ) ;
if ( prop ) { meta_checkbox . set_active ( atoi ( prop - > value ( ) ) ? true : false ) ; }
prop = node - > property ( X_ ( " Format " ) ) ;
if ( prop & & ! prop - > value ( ) . empty ( ) ) { change_file_extension ( " . " + prop - > value ( ) ) ; }
_suspend_signals = true ;
prop = node - > property ( X_ ( " Width " ) ) ;
if ( prop ) { width_spinner . set_value ( atoi ( prop - > value ( ) ) ) ; }
prop = node - > property ( X_ ( " Height " ) ) ;
if ( prop ) { height_spinner . set_value ( atoi ( prop - > value ( ) ) ) ; }
_suspend_signals = false ;
prop = node - > property ( X_ ( " FPS " ) ) ;
if ( prop & & fps_checkbox . get_active ( ) ) { tcfps = atof ( prop - > value ( ) ) ; }
prop = node - > property ( X_ ( " Preset " ) ) ;
if ( prop ) { preset_combo . set_active_text ( prop - > value ( ) ) ; }
prop = node - > property ( X_ ( " VCodec " ) ) ;
if ( prop ) { video_codec_combo . set_active_text ( prop - > value ( ) ) ; }
prop = node - > property ( X_ ( " ACodec " ) ) ;
if ( prop ) { audio_codec_combo . set_active_text ( prop - > value ( ) ) ; }
prop = node - > property ( X_ ( " VBitrate " ) ) ;
if ( prop ) { video_bitrate_combo . set_active_text ( prop - > value ( ) ) ; }
prop = node - > property ( X_ ( " ABitrate " ) ) ;
if ( prop ) { audio_bitrate_combo . set_active_text ( prop - > value ( ) ) ; }
prop = node - > property ( X_ ( " AspectRatio " ) ) ;
if ( prop ) { aspect_combo . set_active_text ( prop - > value ( ) ) ; }
prop = node - > property ( X_ ( " SampleRate " ) ) ;
if ( prop ) { audio_samplerate_combo . set_active_text ( prop - > value ( ) ) ; }
2015-02-27 17:17:26 -05:00
}
2015-02-27 20:31:08 -05:00
if ( fabs ( tcfps - 23.976 ) < 0.01 ) { fps_combo . set_active ( 0 ) ; }
else if ( fabs ( tcfps - 24.0 ) < 0.01 ) { fps_combo . set_active ( 1 ) ; }
else if ( fabs ( tcfps - 24.976 ) < 0.01 ) { fps_combo . set_active ( 2 ) ; }
else if ( fabs ( tcfps - 25.0 ) < 0.01 ) { fps_combo . set_active ( 3 ) ; }
else if ( fabs ( tcfps - 29.97 ) < 0.01 ) { fps_combo . set_active ( 4 ) ; }
else if ( fabs ( tcfps - 30.0 ) < 0.01 ) { fps_combo . set_active ( 5 ) ; }
else if ( fabs ( tcfps - 59.94 ) < 0.01 ) { fps_combo . set_active ( 6 ) ; }
else if ( fabs ( tcfps - 60.0 ) < 0.01 ) { fps_combo . set_active ( 7 ) ; }
else { fps_combo . set_active ( 5 ) ; }
set_original_file_information ( ) ;
/* update sensitivity */
scale_checkbox_toggled ( ) ;
aspect_checkbox_toggled ( ) ;
fps_checkbox_toggled ( ) ;
video_codec_combo_changed ( ) ;
_suspend_dirty = false ;
show_all_children ( ) ;
2015-03-24 22:39:47 -04:00
if ( progress_box ) {
progress_box - > hide ( ) ;
}
2015-02-27 17:17:26 -05:00
}
XMLNode &
ExportVideoDialog : : get_state ( )
{
2015-02-27 20:31:08 -05:00
LocaleGuard lg ( X_ ( " C " ) ) ;
2015-02-27 17:17:26 -05:00
XMLNode * node = new XMLNode ( X_ ( " Videoexport " ) ) ;
2015-02-27 20:31:08 -05:00
node - > add_property ( X_ ( " ChangeGeometry " ) , scale_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " KeepAspect " ) , scale_aspect . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " ChangeAspect " ) , aspect_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " NormalizeAudio " ) , normalize_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " TwoPassEncode " ) , twopass_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " CodecOptimzations " ) , optimizations_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " Deinterlace " ) , deinterlace_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " BFrames " ) , bframes_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " ChangeFPS " ) , fps_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " Metadata " ) , meta_checkbox . get_active ( ) ? X_ ( " 1 " ) : X_ ( " 0 " ) ) ;
node - > add_property ( X_ ( " Format " ) , get_file_extension ( outfn_path_entry . get_text ( ) ) ) ;
node - > add_property ( X_ ( " Width " ) , width_spinner . get_value ( ) ) ;
node - > add_property ( X_ ( " Height " ) , height_spinner . get_value ( ) ) ;
node - > add_property ( X_ ( " Preset " ) , preset_combo . get_active_text ( ) ) ;
node - > add_property ( X_ ( " VCodec " ) , video_codec_combo . get_active_text ( ) ) ;
node - > add_property ( X_ ( " ACodec " ) , audio_codec_combo . get_active_text ( ) ) ;
node - > add_property ( X_ ( " VBitrate " ) , video_bitrate_combo . get_active_text ( ) ) ;
node - > add_property ( X_ ( " ABitrate " ) , audio_bitrate_combo . get_active_text ( ) ) ;
node - > add_property ( X_ ( " AspectRatio " ) , aspect_combo . get_active_text ( ) ) ;
node - > add_property ( X_ ( " SampleRate " ) , audio_samplerate_combo . get_active_text ( ) ) ;
node - > add_property ( X_ ( " FPS " ) , fps_combo . get_active_text ( ) ) ;
2015-02-27 17:17:26 -05:00
return * node ;
}
void
ExportVideoDialog : : set_state ( const XMLNode & )
{
}
2013-03-12 17:00:09 -04:00
void
ExportVideoDialog : : on_show ( )
{
Dialog : : on_show ( ) ;
}
void
ExportVideoDialog : : abort_clicked ( )
{
2015-02-27 20:31:08 -05:00
_aborted = true ;
if ( _transcoder ) {
_transcoder - > cancel ( ) ;
2013-03-12 17:00:09 -04:00
}
}
void
ExportVideoDialog : : update_progress ( framecnt_t c , framecnt_t a )
{
if ( a = = 0 | | c > a ) {
pbar . set_pulse_step ( .1 ) ;
pbar . pulse ( ) ;
2013-04-04 17:40:36 -04:00
} else {
double progress = ( double ) c / ( double ) a ;
2015-02-27 20:31:08 -05:00
progress = progress / ( ( _twopass ? 2.0 : 1.0 ) + ( _normalize ? 2.0 : 1.0 ) ) ;
if ( _normalize & & _twopass ) progress + = ( _firstpass ? .5 : .75 ) ;
else if ( _normalize ) progress + = 2.0 / 3.0 ;
else if ( _twopass ) progress + = ( _firstpass ? 1.0 / 3.0 : 2.0 / 3.0 ) ;
2013-04-04 17:40:36 -04:00
else progress + = .5 ;
pbar . set_fraction ( progress ) ;
2013-03-12 17:00:09 -04:00
}
}
2013-04-03 19:04:27 -04:00
gint
ExportVideoDialog : : audio_progress_display ( )
{
std : : string status_text ;
2013-04-04 17:40:36 -04:00
double progress = 0.0 ;
2013-04-03 19:04:27 -04:00
if ( status - > normalizing ) {
pbar . set_text ( _ ( " Normalizing audio " ) ) ;
progress = ( ( float ) status - > current_normalize_cycle ) / status - > total_normalize_cycles ;
2015-02-27 20:31:08 -05:00
progress = progress / ( _twopass ? 4.0 : 3.0 ) + ( _twopass ? .25 : 1.0 / 3.0 ) ;
2013-04-03 19:04:27 -04:00
} else {
pbar . set_text ( _ ( " Exporting audio " ) ) ;
progress = ( ( float ) status - > processed_frames_current_timespan ) / status - > total_frames_current_timespan ;
2015-02-27 20:31:08 -05:00
progress = progress / ( ( _twopass ? 2.0 : 1.0 ) + ( _normalize ? 2.0 : 1.0 ) ) ;
2013-04-03 19:04:27 -04:00
}
2015-02-27 20:31:08 -05:00
if ( progress < _previous_progress ) {
2013-04-03 19:04:27 -04:00
// Work around gtk bug
pbar . hide ( ) ;
pbar . show ( ) ;
}
2015-02-27 20:31:08 -05:00
_previous_progress = progress ;
2013-04-03 19:04:27 -04:00
pbar . set_fraction ( progress ) ;
return TRUE ;
}
2013-03-12 17:00:09 -04:00
void
ExportVideoDialog : : finished ( )
{
2015-02-27 20:31:08 -05:00
if ( _aborted ) {
2013-07-15 14:29:00 -04:00
: : g_unlink ( outfn_path_entry . get_text ( ) . c_str ( ) ) ;
2015-02-27 20:31:08 -05:00
: : g_unlink ( _insnd . c_str ( ) ) ;
delete _transcoder ; _transcoder = 0 ;
2013-03-12 17:00:09 -04:00
Gtk : : Dialog : : response ( RESPONSE_CANCEL ) ;
2015-02-27 20:31:08 -05:00
} else if ( _twopass & & _firstpass ) {
_firstpass = false ;
if ( _transcoder ) { delete _transcoder ; _transcoder = 0 ; }
2013-03-12 17:00:09 -04:00
encode_pass ( 2 ) ;
} else {
2013-04-02 06:27:08 -04:00
if ( twopass_checkbox . get_active ( ) ) {
2013-03-12 17:00:09 -04:00
std : : string outfn = outfn_path_entry . get_text ( ) ;
std : : string p2log = Glib : : path_get_dirname ( outfn ) + G_DIR_SEPARATOR + " ffmpeg2pass " ;
2013-07-15 14:29:00 -04:00
: : g_unlink ( p2log . c_str ( ) ) ;
2013-03-12 17:00:09 -04:00
}
2015-02-27 20:31:08 -05:00
: : g_unlink ( _insnd . c_str ( ) ) ;
delete _transcoder ; _transcoder = 0 ;
2013-03-12 17:00:09 -04:00
Gtk : : Dialog : : response ( RESPONSE_ACCEPT ) ;
}
}
void
ExportVideoDialog : : launch_export ( )
{
2015-02-27 20:31:08 -05:00
/* remember current settings.
* needed because apply_state ( ) acts on both :
* " Videotimeline " and " Video Export " extra XML
* as well as current _session settings
*/
_session - > add_extra_xml ( get_state ( ) ) ;
2013-03-12 17:00:09 -04:00
std : : string outfn = outfn_path_entry . get_text ( ) ;
2015-11-01 15:00:05 -05:00
if ( ! confirm_video_outfn ( * this , outfn ) ) { return ; }
2013-03-12 17:00:09 -04:00
vbox - > hide ( ) ;
cancel_button - > hide ( ) ;
transcode_button . hide ( ) ;
pbar . set_size_request ( 300 , - 1 ) ;
2013-06-13 20:10:31 -04:00
pbar . set_text ( _ ( " Exporting Audio... " ) ) ;
2013-03-12 17:00:09 -04:00
progress_box - > show ( ) ;
2015-02-27 20:31:08 -05:00
_aborted = false ;
_twopass = twopass_checkbox . get_active ( ) ;
_firstpass = true ;
_normalize = normalize_checkbox . get_active ( ) ;
2013-03-12 17:00:09 -04:00
/* export audio track */
ExportTimespanPtr tsp = _session - > get_export_handler ( ) - > add_timespan ( ) ;
boost : : shared_ptr < ExportChannelConfiguration > ccp = _session - > get_export_handler ( ) - > add_channel_config ( ) ;
boost : : shared_ptr < ARDOUR : : ExportFilename > fnp = _session - > get_export_handler ( ) - > add_filename ( ) ;
boost : : shared_ptr < AudioGrapher : : BroadcastInfo > b ;
2013-04-02 06:27:08 -04:00
XMLTree tree ;
2013-03-12 17:00:09 -04:00
std : : string vtl_samplerate = audio_samplerate_combo . get_active_text ( ) ;
2015-02-27 20:31:08 -05:00
std : : string vtl_normalize = _normalize ? " true " : " false " ;
2013-03-12 17:00:09 -04:00
tree . read_buffer ( std : : string (
" <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> "
" <ExportFormatSpecification name= \" VTL-WAV-16 \" id= \" 3094591e-ccb9-4385-a93f-c9955ffeb1f0 \" > "
" <Encoding id= \" F_WAV \" type= \" T_Sndfile \" extension= \" wav \" name= \" WAV \" has-sample-format= \" true \" channel-limit= \" 256 \" /> "
" <SampleRate rate= \" " + vtl_samplerate + " \" /> "
" <SRCQuality quality= \" SRC_SincBest \" /> "
" <EncodingOptions> "
" <Option name= \" sample-format \" value= \" SF_16 \" /> "
" <Option name= \" dithering \" value= \" D_None \" /> "
" <Option name= \" tag-metadata \" value= \" true \" /> "
" <Option name= \" tag-support \" value= \" false \" /> "
" <Option name= \" broadcast-info \" value= \" false \" /> "
" </EncodingOptions> "
" <Processing> "
" <Normalize enabled= \" " + vtl_normalize + " \" target= \" 0 \" /> "
" <Silence> "
" <Start> "
" <Trim enabled= \" false \" /> "
" <Add enabled= \" false \" > "
" <Duration format= \" Timecode \" hours= \" 0 \" minutes= \" 0 \" seconds= \" 0 \" frames= \" 0 \" /> "
" </Add> "
" </Start> "
" <End> "
" <Trim enabled= \" false \" /> "
" <Add enabled= \" false \" > "
" <Duration format= \" Timecode \" hours= \" 0 \" minutes= \" 0 \" seconds= \" 0 \" frames= \" 0 \" /> "
" </Add> "
" </End> "
" </Silence> "
" </Processing> "
" </ExportFormatSpecification> "
) ) ;
boost : : shared_ptr < ExportFormatSpecification > fmp = _session - > get_export_handler ( ) - > add_format ( * tree . root ( ) ) ;
/* set up range */
framepos_t start , end ;
start = end = 0 ;
if ( insnd_combo . get_active_row_number ( ) = = 1 ) {
2015-02-27 20:31:08 -05:00
_transcoder = new TranscodeFfmpeg ( invid_path_entry . get_text ( ) ) ;
if ( _transcoder - > probe_ok ( ) & & _transcoder - > get_fps ( ) > 0 ) {
end = _transcoder - > get_duration ( ) * _session - > nominal_frame_rate ( ) / _transcoder - > get_fps ( ) ;
2013-04-02 06:27:08 -04:00
} else {
warning < < _ ( " Export Video: Cannot query duration of video-file, using duration from timeline instead. " ) < < endmsg ;
end = ARDOUR_UI : : instance ( ) - > video_timeline - > get_duration ( ) ;
2013-03-12 17:00:09 -04:00
}
2015-02-27 20:31:08 -05:00
if ( _transcoder ) { delete _transcoder ; _transcoder = 0 ; }
2013-03-12 17:00:09 -04:00
frameoffset_t av_offset = ARDOUR_UI : : instance ( ) - > video_timeline - > get_offset ( ) ;
2013-04-02 06:27:08 -04:00
#if 0 /* DEBUG */
printf ( " audio-range -- AV offset: %lld \n " , av_offset ) ;
# endif
2013-03-12 17:00:09 -04:00
if ( av_offset > 0 ) {
2013-04-02 06:27:08 -04:00
start = av_offset ;
2013-03-12 17:00:09 -04:00
}
2013-04-02 06:27:08 -04:00
end + = av_offset ;
2013-03-12 17:00:09 -04:00
}
2013-09-12 16:46:11 -04:00
else if ( insnd_combo . get_active_row_number ( ) = = 2 ) {
2013-10-12 15:25:05 -04:00
start = ARDOUR_UI : : instance ( ) - > video_timeline - > quantify_frames_to_apv ( export_range . start ( ) ) ;
end = ARDOUR_UI : : instance ( ) - > video_timeline - > quantify_frames_to_apv ( export_range . end_frame ( ) ) ;
2013-09-12 16:46:11 -04:00
}
2013-03-12 17:00:09 -04:00
if ( end < = 0 ) {
start = _session - > current_start_frame ( ) ;
end = _session - > current_end_frame ( ) ;
}
#if 0 /* DEBUG */
2013-04-02 06:27:08 -04:00
printf ( " audio export-range %lld -> %lld \n " , start , end ) ;
2013-03-12 17:00:09 -04:00
# endif
2013-10-12 15:25:05 -04:00
const frameoffset_t vstart = ARDOUR_UI : : instance ( ) - > video_timeline - > get_offset ( ) ;
const frameoffset_t vend = vstart + ARDOUR_UI : : instance ( ) - > video_timeline - > get_duration ( ) ;
if ( ( start > = end ) | | ( end < vstart ) | | ( start > vend ) ) {
warning < < _ ( " Export Video: export-range does not include video. " ) < < endmsg ;
2015-02-27 20:31:08 -05:00
delete _transcoder ; _transcoder = 0 ;
2013-10-12 15:25:05 -04:00
Gtk : : Dialog : : response ( RESPONSE_CANCEL ) ;
return ;
}
2013-03-12 17:00:09 -04:00
tsp - > set_range ( start , end ) ;
tsp - > set_name ( " mysession " ) ;
tsp - > set_range_id ( " session " ) ;
/* add master outs as default */
IO * master_out = _session - > master_out ( ) - > output ( ) . get ( ) ;
if ( ! master_out ) {
warning < < _ ( " Export Video: No Master Out Ports to Connect for Audio Export " ) < < endmsg ;
2015-02-27 20:31:08 -05:00
delete _transcoder ; _transcoder = 0 ;
2013-03-12 17:00:09 -04:00
Gtk : : Dialog : : response ( RESPONSE_CANCEL ) ;
return ;
}
for ( uint32_t n = 0 ; n < master_out - > n_ports ( ) . n_audio ( ) ; + + n ) {
PortExportChannel * channel = new PortExportChannel ( ) ;
channel - > add_port ( master_out - > audio ( n ) ) ;
ExportChannelPtr chan_ptr ( channel ) ;
ccp - > register_channel ( chan_ptr ) ;
}
/* outfile */
fnp - > set_timespan ( tsp ) ;
fnp - > set_label ( " vtl " ) ;
fnp - > include_label = true ;
2015-02-27 20:31:08 -05:00
_insnd = fnp - > get_path ( fmp ) ;
2013-03-12 17:00:09 -04:00
/* do sound export */
2014-07-06 17:45:39 -04:00
fmp - > set_soundcloud_upload ( false ) ;
2013-03-12 17:00:09 -04:00
_session - > get_export_handler ( ) - > add_export_config ( tsp , ccp , fmp , fnp , b ) ;
_session - > get_export_handler ( ) - > do_export ( ) ;
2013-04-03 19:04:27 -04:00
status = _session - > get_export_status ( ) ;
2013-03-12 17:00:09 -04:00
2013-04-03 19:04:27 -04:00
audio_progress_connection = Glib : : signal_timeout ( ) . connect ( sigc : : mem_fun ( * this , & ExportVideoDialog : : audio_progress_display ) , 100 ) ;
2015-02-27 20:31:08 -05:00
_previous_progress = 0.0 ;
2013-04-02 06:27:08 -04:00
while ( status - > running ) {
2015-02-27 20:31:08 -05:00
if ( _aborted ) { status - > abort ( ) ; }
2013-04-02 06:27:08 -04:00
if ( gtk_events_pending ( ) ) {
gtk_main_iteration ( ) ;
} else {
2013-10-06 05:52:41 -04:00
Glib : : usleep ( 10000 ) ;
2013-04-02 06:27:08 -04:00
}
}
2013-04-03 19:04:27 -04:00
audio_progress_connection . disconnect ( ) ;
2013-04-02 06:27:08 -04:00
status - > finish ( ) ;
if ( status - > aborted ( ) ) {
2015-02-27 20:31:08 -05:00
: : g_unlink ( _insnd . c_str ( ) ) ;
delete _transcoder ; _transcoder = 0 ;
2013-03-12 17:00:09 -04:00
Gtk : : Dialog : : response ( RESPONSE_CANCEL ) ;
return ;
}
2013-06-13 20:10:31 -04:00
pbar . set_text ( _ ( " Encoding Video... " ) ) ;
2013-03-12 17:00:09 -04:00
encode_pass ( 1 ) ;
}
void
ExportVideoDialog : : encode_pass ( int pass )
{
std : : string outfn = outfn_path_entry . get_text ( ) ;
std : : string invid = invid_path_entry . get_text ( ) ;
2015-02-27 20:31:08 -05:00
_transcoder = new TranscodeFfmpeg ( invid ) ;
if ( ! _transcoder - > ffexec_ok ( ) ) {
2013-04-02 06:27:08 -04:00
/* ffmpeg binary was not found. TranscodeFfmpeg prints a warning */
2015-02-27 20:31:08 -05:00
: : g_unlink ( _insnd . c_str ( ) ) ;
delete _transcoder ; _transcoder = 0 ;
2013-03-12 17:00:09 -04:00
Gtk : : Dialog : : response ( RESPONSE_CANCEL ) ;
return ;
}
2015-02-27 20:31:08 -05:00
if ( ! _transcoder - > probe_ok ( ) ) {
2013-04-02 06:27:08 -04:00
/* video input file can not be read */
warning < < _ ( " Export Video: Video input file cannot be read. " ) < < endmsg ;
2015-02-27 20:31:08 -05:00
: : g_unlink ( _insnd . c_str ( ) ) ;
delete _transcoder ; _transcoder = 0 ;
Gtk : : Dialog : : response ( RESPONSE_CANCEL ) ;
return ;
2013-04-02 06:27:08 -04:00
}
2013-03-12 17:00:09 -04:00
std : : string preset = preset_combo . get_active_text ( ) ;
2013-07-14 10:34:49 -04:00
TranscodeFfmpeg : : FFSettings ffs ; /* = transcoder->default_encoder_settings(); */
2013-03-12 17:00:09 -04:00
ffs . clear ( ) ;
if ( fps_checkbox . get_active ( ) ) {
2014-07-02 14:26:13 -04:00
ffs [ " -r " ] = fps_combo . get_active_text ( ) ;
2015-02-27 20:31:08 -05:00
_transcoder - > set_fps ( atof ( fps_combo . get_active_text ( ) ) ) ;
2013-03-12 17:00:09 -04:00
}
if ( scale_checkbox . get_active ( ) ) {
ffs [ " -s " ] = string_compose ( " %1x%2 " , width_spinner . get_value ( ) , height_spinner . get_value ( ) ) ;
}
2015-02-27 16:54:23 -05:00
if ( video_codec_combo . get_active_text ( ) ! = _ ( " (default for format) " ) ) {
ffs [ " -vcodec " ] = video_codec_combo . get_active_text ( ) ;
}
if ( audio_codec_combo . get_active_text ( ) ! = _ ( " (default for format) " ) ) {
ffs [ " -acodec " ] = audio_codec_combo . get_active_text ( ) ;
}
if ( video_bitrate_combo . get_active_text ( ) = = _ ( " (default) " ) ) {
;
}
else if ( video_bitrate_combo . get_active_text ( ) = = _ ( " (retain) " ) ) {
2013-06-16 09:30:15 -04:00
ffs [ " -qscale " ] = " 0 " ;
2013-03-12 17:00:09 -04:00
} else {
ffs [ " -b:v " ] = video_bitrate_combo . get_active_text ( ) ;
}
2015-02-27 16:54:23 -05:00
if ( audio_bitrate_combo . get_active_text ( ) ! = _ ( " (default) " ) ) {
ffs [ " -b:a " ] = audio_bitrate_combo . get_active_text ( ) ;
}
2013-03-31 13:34:05 -04:00
if ( audio_codec_combo . get_active_text ( ) = = " aac " ) {
ffs [ " -strict " ] = " -2 " ;
}
2013-09-08 12:26:02 -04:00
if ( video_codec_combo . get_active_text ( ) = = " h264 " ) {
2013-03-12 17:00:09 -04:00
ffs [ " -vcodec " ] = " libx264 " ;
2013-03-31 13:34:05 -04:00
}
else if ( video_codec_combo . get_active_text ( ) = = " vpx (webm) " ) {
ffs [ " -vcodec " ] = " libvpx " ;
ffs [ " -g " ] = " 120 " ;
ffs [ " -qmin " ] = " 11 " ;
ffs [ " -qmax " ] = " 51 " ;
2013-03-12 17:00:09 -04:00
}
if ( optimizations_checkbox . get_active ( ) ) {
if ( video_codec_combo . get_active_text ( ) = = " mpeg2video " ) {
ffs [ " -mbd " ] = " rd " ;
ffs [ " -trellis " ] = " 2 " ;
ffs [ " -cmp " ] = " 2 " ;
ffs [ " -subcmp " ] = " 2 " ;
}
else if ( video_codec_combo . get_active_text ( ) = = " mpeg4 " ) {
ffs [ " -mbd " ] = " rd " ;
2013-03-31 13:34:05 -04:00
ffs [ " -flags " ] = " +mv4+aic " ;
2013-03-12 17:00:09 -04:00
ffs [ " -trellis " ] = " 2 " ;
ffs [ " -cmp " ] = " 2 " ;
ffs [ " -subcmp " ] = " 2 " ;
ffs [ " -g " ] = " 300 " ;
}
else if ( video_codec_combo . get_active_text ( ) = = " flv " ) {
ffs [ " -mbd " ] = " 2 " ;
ffs [ " -cmp " ] = " 2 " ;
ffs [ " -subcmp " ] = " 2 " ;
ffs [ " -trellis " ] = " 2 " ;
ffs [ " -flags " ] = " +aic+mv0+mv4 " ;
ffs [ " -g " ] = " 160 " ;
}
}
2013-03-31 13:34:05 -04:00
if ( bframes_checkbox . get_active ( ) & & (
video_codec_combo . get_active_text ( ) = = " mpeg2video "
| | video_codec_combo . get_active_text ( ) = = " mpeg4 "
) ) {
2013-03-12 17:00:09 -04:00
ffs [ " -bf " ] = " 2 " ;
}
if ( preset = = " dvd-PAL " ) {
ffs . clear ( ) ; /* ignore all prev settings */
ffs [ " -target " ] = " pal-dvd " ;
ffs [ " -aspect " ] = " 4:3 " ; /* required for DVD - may be overridden below */
}
else if ( preset = = " dvd-NTSC " ) {
ffs . clear ( ) ; /* ignore all prev settings */
ffs [ " -target " ] = " ntsc-dvd " ;
ffs [ " -aspect " ] = " 4:3 " ; /* required for DVD - may be overridden below */
}
if ( aspect_checkbox . get_active ( ) ) {
ffs [ " -aspect " ] = aspect_combo . get_active_text ( ) ;
}
if ( deinterlace_checkbox . get_active ( ) ) {
2013-04-02 06:27:08 -04:00
ffs [ " -deinterlace " ] = " -y " ; // we use '-y' as dummy parameter for non key/value options
2013-03-12 17:00:09 -04:00
}
bool map = true ;
2015-02-27 20:31:08 -05:00
if ( pass = = 1 & & _twopass ) {
2013-03-12 17:00:09 -04:00
pbar . set_text ( _ ( " Encoding Video.. Pass 1/2 " ) ) ;
map = false ;
ffs [ " -pass " ] = " 1 " ;
ffs [ " -an " ] = " -y " ;
ffs [ " -passlogfile " ] = Glib : : path_get_dirname ( outfn ) + G_DIR_SEPARATOR + " ffmpeg2pass " ;
ffs [ " -f " ] = get_file_extension ( invid ) . empty ( ) ? " mov " : get_file_extension ( invid ) ;
2013-10-14 12:00:28 -04:00
# ifdef PLATFORM_WINDOWS
2013-03-12 17:00:09 -04:00
outfn = " NUL " ;
# else
outfn = " /dev/null " ;
# endif
} else if ( pass = = 2 ) {
pbar . set_text ( _ ( " Encoding Video.. Pass 2/2 " ) ) ;
ffs [ " -pass " ] = " 2 " ;
ffs [ " -passlogfile " ] = Glib : : path_get_dirname ( outfn ) + G_DIR_SEPARATOR + " ffmpeg2pass " ;
}
frameoffset_t av_offset = ARDOUR_UI : : instance ( ) - > video_timeline - > get_offset ( ) ;
2013-04-02 06:27:08 -04:00
double duration_s = 0 ;
2013-03-12 17:00:09 -04:00
if ( insnd_combo . get_active_row_number ( ) = = 0 ) {
2013-09-12 16:46:11 -04:00
/* session start to session end */
2013-03-12 17:00:09 -04:00
framecnt_t duration_f = _session - > current_end_frame ( ) - _session - > current_start_frame ( ) ;
2013-04-02 06:27:08 -04:00
duration_s = ( double ) duration_f / ( double ) _session - > nominal_frame_rate ( ) ;
2013-09-12 16:46:11 -04:00
} else if ( insnd_combo . get_active_row_number ( ) = = 2 ) {
/* selected range */
duration_s = export_range . length ( ) / ( double ) _session - > nominal_frame_rate ( ) ;
2013-04-02 06:27:08 -04:00
} else {
2013-09-12 16:46:11 -04:00
/* video start to end */
2013-04-02 06:27:08 -04:00
framecnt_t duration_f = ARDOUR_UI : : instance ( ) - > video_timeline - > get_duration ( ) ;
if ( av_offset < 0 ) {
duration_f + = av_offset ;
2013-03-12 17:00:09 -04:00
}
2013-04-02 06:27:08 -04:00
duration_s = ( double ) duration_f / ( double ) _session - > nominal_frame_rate ( ) ;
}
std : : ostringstream osstream ; osstream < < duration_s ;
ffs [ " -t " ] = osstream . str ( ) ;
2015-02-27 20:31:08 -05:00
_transcoder - > set_duration ( duration_s * _transcoder - > get_fps ( ) ) ;
2013-03-12 17:00:09 -04:00
2013-09-12 16:46:11 -04:00
if ( insnd_combo . get_active_row_number ( ) = = 0 | | insnd_combo . get_active_row_number ( ) = = 2 ) {
framepos_t start , snend ;
2013-04-02 06:27:08 -04:00
const frameoffset_t vid_duration = ARDOUR_UI : : instance ( ) - > video_timeline - > get_duration ( ) ;
2013-09-12 16:46:11 -04:00
if ( insnd_combo . get_active_row_number ( ) = = 0 ) {
start = _session - > current_start_frame ( ) ;
snend = _session - > current_end_frame ( ) ;
} else {
start = export_range . start ( ) ;
snend = export_range . end_frame ( ) ;
}
2013-04-02 06:27:08 -04:00
#if 0 /* DEBUG */
printf ( " AV offset: %lld Vid-len: %lld Vid-end: %lld || start:%lld || end:%lld \n " ,
av_offset , vid_duration , av_offset + vid_duration , start , snend ) ; // XXX
2013-03-12 17:00:09 -04:00
# endif
2013-04-02 06:27:08 -04:00
if ( av_offset > start & & av_offset + vid_duration < snend ) {
2015-02-27 20:31:08 -05:00
_transcoder - > set_leadinout ( ( av_offset - start ) / ( double ) _session - > nominal_frame_rate ( ) ,
2013-04-02 06:27:08 -04:00
( snend - ( av_offset + vid_duration ) ) / ( double ) _session - > nominal_frame_rate ( ) ) ;
} else if ( av_offset > start ) {
2015-02-27 20:31:08 -05:00
_transcoder - > set_leadinout ( ( av_offset - start ) / ( double ) _session - > nominal_frame_rate ( ) , 0 ) ;
2013-04-02 06:27:08 -04:00
} else if ( av_offset + vid_duration < snend ) {
2015-02-27 20:31:08 -05:00
_transcoder - > set_leadinout ( 0 , ( snend - ( av_offset + vid_duration ) ) / ( double ) _session - > nominal_frame_rate ( ) ) ;
_transcoder - > set_avoffset ( ( av_offset - start ) / ( double ) _session - > nominal_frame_rate ( ) ) ;
2013-09-12 16:46:11 -04:00
}
#if 0
else if ( start > av_offset ) {
std : : ostringstream osstream ; osstream < < ( ( start - av_offset ) / ( double ) _session - > nominal_frame_rate ( ) ) ;
ffs [ " -ss " ] = osstream . str ( ) ;
}
# endif
else {
2015-02-27 20:31:08 -05:00
_transcoder - > set_avoffset ( ( av_offset - start ) / ( double ) _session - > nominal_frame_rate ( ) ) ;
2013-04-02 06:27:08 -04:00
}
2013-09-12 16:46:11 -04:00
2013-04-02 06:27:08 -04:00
} else if ( av_offset < 0 ) {
/* from 00:00:00:00 to video-end */
2015-02-27 20:31:08 -05:00
_transcoder - > set_avoffset ( av_offset / ( double ) _session - > nominal_frame_rate ( ) ) ;
2013-03-12 17:00:09 -04:00
}
2015-02-27 20:31:08 -05:00
TranscodeFfmpeg : : FFSettings meta = _transcoder - > default_meta_data ( ) ;
2013-03-12 17:00:09 -04:00
if ( meta_checkbox . get_active ( ) ) {
ARDOUR : : SessionMetadata * session_data = ARDOUR : : SessionMetadata : : Metadata ( ) ;
if ( session_data - > year ( ) > 0 ) {
std : : ostringstream osstream ; osstream < < session_data - > year ( ) ;
meta [ " year " ] = osstream . str ( ) ;
}
if ( session_data - > track_number ( ) > 0 ) {
std : : ostringstream osstream ; osstream < < session_data - > track_number ( ) ;
meta [ " track " ] = osstream . str ( ) ;
}
if ( session_data - > disc_number ( ) > 0 ) {
std : : ostringstream osstream ; osstream < < session_data - > disc_number ( ) ;
meta [ " disc " ] = osstream . str ( ) ;
}
2013-04-02 06:27:08 -04:00
if ( ! session_data - > title ( ) . empty ( ) ) { meta [ " title " ] = session_data - > title ( ) ; }
if ( ! session_data - > artist ( ) . empty ( ) ) { meta [ " author " ] = session_data - > artist ( ) ; }
2013-03-12 17:00:09 -04:00
if ( ! session_data - > album_artist ( ) . empty ( ) ) { meta [ " album_artist " ] = session_data - > album_artist ( ) ; }
2013-04-02 06:27:08 -04:00
if ( ! session_data - > album ( ) . empty ( ) ) { meta [ " album " ] = session_data - > album ( ) ; }
if ( ! session_data - > genre ( ) . empty ( ) ) { meta [ " genre " ] = session_data - > genre ( ) ; }
2013-03-12 17:00:09 -04:00
if ( ! session_data - > composer ( ) . empty ( ) ) { meta [ " composer " ] = session_data - > composer ( ) ; }
if ( ! session_data - > comment ( ) . empty ( ) ) { meta [ " comment " ] = session_data - > comment ( ) ; }
if ( ! session_data - > copyright ( ) . empty ( ) ) { meta [ " copyright " ] = session_data - > copyright ( ) ; }
if ( ! session_data - > subtitle ( ) . empty ( ) ) { meta [ " description " ] = session_data - > subtitle ( ) ; }
}
# if 1 /* tentative debug mode */
if ( debug_checkbox . get_active ( ) ) {
2015-02-27 20:31:08 -05:00
_transcoder - > set_debug ( true ) ;
2013-03-12 17:00:09 -04:00
}
# endif
2015-02-27 20:31:08 -05:00
_transcoder - > Progress . connect ( * this , invalidator ( * this ) , boost : : bind ( & ExportVideoDialog : : update_progress , this , _1 , _2 ) , gui_context ( ) ) ;
_transcoder - > Finished . connect ( * this , invalidator ( * this ) , boost : : bind ( & ExportVideoDialog : : finished , this ) , gui_context ( ) ) ;
if ( ! _transcoder - > encode ( outfn , _insnd , invid , ffs , meta , map ) ) {
2013-03-12 17:00:09 -04:00
ARDOUR_UI : : instance ( ) - > popup_error ( _ ( " Transcoding failed. " ) ) ;
2015-02-27 20:31:08 -05:00
delete _transcoder ; _transcoder = 0 ;
2013-03-12 17:00:09 -04:00
Gtk : : Dialog : : response ( RESPONSE_CANCEL ) ;
return ;
}
}
void
ExportVideoDialog : : change_file_extension ( std : : string ext )
{
2015-02-27 20:31:08 -05:00
if ( ext = = " " ) return ;
2013-03-12 17:00:09 -04:00
outfn_path_entry . set_text (
2013-04-02 06:27:08 -04:00
strip_file_extension ( outfn_path_entry . get_text ( ) ) + ext
2013-03-12 17:00:09 -04:00
) ;
}
2015-02-27 20:31:08 -05:00
void
ExportVideoDialog : : width_value_changed ( )
{
if ( _suspend_signals ) {
return ;
}
if ( _session & & ! _suspend_dirty ) _session - > set_dirty ( ) ;
if ( ! scale_checkbox . get_active ( ) | | ! scale_aspect . get_active ( ) ) {
return ;
}
if ( _video_source_aspect_ratio < = 0 ) {
return ;
}
_suspend_signals = true ;
height_spinner . set_value ( rintf ( width_spinner . get_value ( ) / _video_source_aspect_ratio ) ) ;
_suspend_signals = false ;
}
void
ExportVideoDialog : : height_value_changed ( )
{
if ( _suspend_signals ) {
return ;
}
if ( _session & & ! _suspend_dirty ) _session - > set_dirty ( ) ;
if ( ! scale_checkbox . get_active ( ) | | ! scale_aspect . get_active ( ) ) {
return ;
}
if ( _video_source_aspect_ratio < = 0 ) {
return ;
}
_suspend_signals = true ;
width_spinner . set_value ( rintf ( height_spinner . get_value ( ) * _video_source_aspect_ratio ) ) ;
_suspend_signals = false ;
}
2013-03-12 17:00:09 -04:00
void
ExportVideoDialog : : scale_checkbox_toggled ( )
{
2015-02-27 20:31:08 -05:00
scale_aspect . set_sensitive ( scale_checkbox . get_active ( ) ) ;
2013-03-12 17:00:09 -04:00
width_spinner . set_sensitive ( scale_checkbox . get_active ( ) ) ;
height_spinner . set_sensitive ( scale_checkbox . get_active ( ) ) ;
2015-02-27 20:31:08 -05:00
if ( _session & & ! _suspend_dirty ) _session - > set_dirty ( ) ;
2013-03-12 17:00:09 -04:00
}
void
ExportVideoDialog : : fps_checkbox_toggled ( )
{
fps_combo . set_sensitive ( fps_checkbox . get_active ( ) ) ;
2015-02-27 20:31:08 -05:00
if ( _session & & ! _suspend_dirty ) _session - > set_dirty ( ) ;
2013-03-12 17:00:09 -04:00
}
void
ExportVideoDialog : : aspect_checkbox_toggled ( )
{
aspect_combo . set_sensitive ( aspect_checkbox . get_active ( ) ) ;
2015-02-27 20:31:08 -05:00
if ( _session & & ! _suspend_dirty ) _session - > set_dirty ( ) ;
2013-03-12 17:00:09 -04:00
}
void
ExportVideoDialog : : video_codec_combo_changed ( )
{
if ( ( video_codec_combo . get_active_text ( ) = = " mpeg4 "
| | video_codec_combo . get_active_text ( ) = = " mpeg2video "
) & & ! (
preset_combo . get_active_text ( ) = = " dvd-PAL "
| | preset_combo . get_active_text ( ) = = " dvd-NTSC "
) ) {
bframes_checkbox . set_sensitive ( true ) ;
optimizations_checkbox . set_sensitive ( true ) ;
2013-04-02 06:27:08 -04:00
if ( video_codec_combo . get_active_text ( ) = = " mpeg2video " ) {
2013-03-12 17:00:09 -04:00
optimizations_label . set_text ( " -mbd rd -trellis 2 -cmp 2 -subcmp 2 " ) ; // mpeg2
} else if ( video_codec_combo . get_active_text ( ) = = " mpeg4 " ) {
2013-03-31 13:34:05 -04:00
optimizations_label . set_text ( " -mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 " ) ; // mpeg4
2013-03-12 17:00:09 -04:00
} else {
optimizations_label . set_text ( " -mbd 2 -cmp 2 -subcmp 2 -trellis 2 -flags +aic+mv0+mv4 -g 160 " ) ; // flv
}
} else {
bframes_checkbox . set_sensitive ( false ) ;
bframes_checkbox . set_active ( false ) ;
optimizations_checkbox . set_sensitive ( false ) ;
optimizations_checkbox . set_active ( false ) ;
optimizations_label . set_text ( " - " ) ;
}
2015-02-27 20:31:08 -05:00
if ( _session & & ! _suspend_dirty ) _session - > set_dirty ( ) ;
2013-03-12 17:00:09 -04:00
}
void
ExportVideoDialog : : preset_combo_changed ( )
{
std : : string p = preset_combo . get_active_text ( ) ;
scale_checkbox . set_sensitive ( true ) ;
if ( p = = " flv " ) {
change_file_extension ( " .flv " ) ;
2015-02-27 17:24:05 -05:00
audio_codec_combo . set_active ( 2 ) ;
video_codec_combo . set_active ( 1 ) ;
audio_bitrate_combo . set_active ( 2 ) ;
video_bitrate_combo . set_active ( 3 ) ;
2013-03-12 17:00:09 -04:00
audio_samplerate_combo . set_active ( 1 ) ;
}
else if ( p = = " you-tube " ) {
change_file_extension ( " .avi " ) ;
2015-02-27 17:24:05 -05:00
audio_codec_combo . set_active ( 3 ) ;
video_codec_combo . set_active ( 6 ) ;
audio_bitrate_combo . set_active ( 2 ) ;
video_bitrate_combo . set_active ( 4 ) ;
2013-03-12 17:00:09 -04:00
if ( _session - > nominal_frame_rate ( ) = = 48000 | | _session - > nominal_frame_rate ( ) = = 96000 ) {
audio_samplerate_combo . set_active ( 2 ) ;
} else {
audio_samplerate_combo . set_active ( 1 ) ;
}
}
else if ( p = = " ogg " ) {
change_file_extension ( " .ogv " ) ;
2015-02-27 17:24:05 -05:00
audio_codec_combo . set_active ( 4 ) ;
video_codec_combo . set_active ( 2 ) ;
audio_bitrate_combo . set_active ( 3 ) ;
video_bitrate_combo . set_active ( 4 ) ;
2013-03-12 17:00:09 -04:00
if ( _session - > nominal_frame_rate ( ) = = 48000 | | _session - > nominal_frame_rate ( ) = = 96000 ) {
audio_samplerate_combo . set_active ( 2 ) ;
} else {
audio_samplerate_combo . set_active ( 1 ) ;
}
}
2015-02-27 17:24:05 -05:00
else if ( p = = " webm " ) {
change_file_extension ( " .webm " ) ;
2013-03-12 17:00:09 -04:00
audio_codec_combo . set_active ( 4 ) ;
2015-02-27 17:24:05 -05:00
video_codec_combo . set_active ( 7 ) ;
2013-03-12 17:00:09 -04:00
audio_bitrate_combo . set_active ( 3 ) ;
2015-02-27 17:24:05 -05:00
video_bitrate_combo . set_active ( 4 ) ;
if ( _session - > nominal_frame_rate ( ) = = 48000 | | _session - > nominal_frame_rate ( ) = = 96000 ) {
audio_samplerate_combo . set_active ( 2 ) ;
} else {
audio_samplerate_combo . set_active ( 1 ) ;
}
}
else if ( p = = " dvd-mp2 " ) {
change_file_extension ( " .mpg " ) ;
audio_codec_combo . set_active ( 5 ) ;
video_codec_combo . set_active ( 4 ) ;
audio_bitrate_combo . set_active ( 4 ) ;
video_bitrate_combo . set_active ( 5 ) ;
2013-03-12 17:00:09 -04:00
audio_samplerate_combo . set_active ( 2 ) ;
}
else if ( p = = " dvd-NTSC " | | p = = " dvd-PAL " ) {
change_file_extension ( " .mpg " ) ;
2015-02-27 17:24:05 -05:00
audio_codec_combo . set_active ( 6 ) ;
video_codec_combo . set_active ( 4 ) ;
audio_bitrate_combo . set_active ( 4 ) ;
video_bitrate_combo . set_active ( 5 ) ;
2013-03-12 17:00:09 -04:00
audio_samplerate_combo . set_active ( 2 ) ;
2013-04-02 06:27:08 -04:00
scale_checkbox . set_active ( false ) ;
scale_checkbox . set_sensitive ( false ) ;
2013-03-12 17:00:09 -04:00
}
else if ( p = = " mpeg4 " ) {
change_file_extension ( " .mp4 " ) ;
2015-02-27 17:24:05 -05:00
audio_codec_combo . set_active ( 1 ) ;
video_codec_combo . set_active ( 5 ) ;
audio_bitrate_combo . set_active ( 4 ) ;
video_bitrate_combo . set_active ( 5 ) ;
2013-03-12 17:00:09 -04:00
if ( _session - > nominal_frame_rate ( ) = = 48000 | | _session - > nominal_frame_rate ( ) = = 96000 ) {
audio_samplerate_combo . set_active ( 2 ) ;
} else {
audio_samplerate_combo . set_active ( 1 ) ;
}
}
2015-02-27 20:31:08 -05:00
else if ( p = = " mp4/h264/aac " ) {
change_file_extension ( " .mp4 " ) ;
audio_codec_combo . set_active ( 2 ) ;
video_codec_combo . set_active ( 6 ) ;
audio_bitrate_combo . set_active ( 0 ) ;
video_bitrate_combo . set_active ( 0 ) ;
if ( _session - > nominal_frame_rate ( ) = = 48000 | | _session - > nominal_frame_rate ( ) = = 96000 ) {
audio_samplerate_combo . set_active ( 2 ) ;
} else {
audio_samplerate_combo . set_active ( 1 ) ;
}
}
2013-03-12 17:00:09 -04:00
if ( p = = " none " ) {
audio_codec_combo . set_sensitive ( true ) ;
video_codec_combo . set_sensitive ( true ) ;
audio_bitrate_combo . set_sensitive ( true ) ;
video_bitrate_combo . set_sensitive ( true ) ;
audio_samplerate_combo . set_sensitive ( true ) ;
} else {
audio_codec_combo . set_sensitive ( false ) ;
video_codec_combo . set_sensitive ( false ) ;
audio_bitrate_combo . set_sensitive ( false ) ;
video_bitrate_combo . set_sensitive ( false ) ;
audio_samplerate_combo . set_sensitive ( false ) ;
}
Gtk : : Table * t = ( Gtk : : Table * ) preset_combo . get_parent ( ) ;
Gtk : : Table_Helpers : : TableList c = t - > children ( ) ;
Gtk : : Table_Helpers : : TableList : : iterator it ;
if ( p = = " dvd-PAL " | | p = = " dvd-NTSC " ) {
for ( it = c . begin ( ) ; it ! = c . end ( ) ; + + it ) {
int row = it - > get_top_attach ( ) ;
2013-04-02 18:58:19 -04:00
if ( row = = 2 | | row = = 3 | | row = = 5 | | row = = 6 | | row = = 9 ) {
2013-04-02 06:27:08 -04:00
it - > get_widget ( ) - > hide ( ) ;
2013-03-12 17:00:09 -04:00
}
}
} else {
for ( it = c . begin ( ) ; it ! = c . end ( ) ; + + it ) {
int row = it - > get_top_attach ( ) ;
2013-04-02 18:58:19 -04:00
if ( row = = 2 | | row = = 3 | | row = = 5 | | row = = 6 | | row = = 9 ) {
2013-04-02 06:27:08 -04:00
it - > get_widget ( ) - > show ( ) ;
2013-03-12 17:00:09 -04:00
}
}
}
video_codec_combo_changed ( ) ;
}
void
ExportVideoDialog : : open_outfn_dialog ( )
{
Gtk : : FileChooserDialog dialog ( _ ( " Save Exported Video File " ) , Gtk : : FILE_CHOOSER_ACTION_SAVE ) ;
dialog . set_filename ( outfn_path_entry . get_text ( ) ) ;
dialog . add_button ( Gtk : : Stock : : CANCEL , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( Gtk : : Stock : : OK , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
std : : string filename = dialog . get_filename ( ) ;
if ( filename . length ( ) ) {
outfn_path_entry . set_text ( filename ) ;
}
}
}
void
ExportVideoDialog : : open_invid_dialog ( )
{
Gtk : : FileChooserDialog dialog ( _ ( " Save Exported Video File " ) , Gtk : : FILE_CHOOSER_ACTION_SAVE ) ;
dialog . set_filename ( invid_path_entry . get_text ( ) ) ;
dialog . add_button ( Gtk : : Stock : : CANCEL , Gtk : : RESPONSE_CANCEL ) ;
dialog . add_button ( Gtk : : Stock : : OK , Gtk : : RESPONSE_OK ) ;
int result = dialog . run ( ) ;
if ( result = = Gtk : : RESPONSE_OK ) {
std : : string filename = dialog . get_filename ( ) ;
if ( filename . length ( ) ) {
invid_path_entry . set_text ( filename ) ;
}
}
}