vtl: update video-export
* range: pre/postfix with black video-frames * fix A/V offset - decode and skip source until offset is reached * use spinning progress-bar during decode&skip * use video-stream index in stream-map * fix audio-export abort; stop freewheeling * re-indent code
This commit is contained in:
parent
922ef41995
commit
1d48fb011e
|
@ -152,15 +152,6 @@ ExportVideoDialog::ExportVideoDialog (PublicEditor& ed, Session* s)
|
|||
}
|
||||
insnd_combo.set_active(0);
|
||||
|
||||
#if 1
|
||||
// TODO probe input file - don't use VTL duration.
|
||||
framecnt_t duration_v = ARDOUR_UI::instance()->video_timeline->get_duration();
|
||||
framecnt_t duration_a = _session->current_end_frame() - _session->current_start_frame();
|
||||
if ( duration_a > duration_v ) {
|
||||
warning << _("Audio is longer than video. This file may not play correctly.") << endmsg;
|
||||
}
|
||||
#endif
|
||||
|
||||
outfn_path_entry.set_width_chars(38);
|
||||
outfn_path_entry.set_text (_session->session_directory().export_path() + G_DIR_SEPARATOR +"export.avi");
|
||||
|
||||
|
@ -405,7 +396,6 @@ ExportVideoDialog::launch_export ()
|
|||
std::string vtl_samplerate = audio_samplerate_combo.get_active_text();
|
||||
std::string vtl_normalize = normalize_checkbox.get_active()?"true":"false";
|
||||
tree.read_buffer(std::string(
|
||||
/* TODO: move this into a header file */
|
||||
"<?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\"/>"
|
||||
|
@ -444,23 +434,29 @@ ExportVideoDialog::launch_export ()
|
|||
start = end = 0;
|
||||
if (insnd_combo.get_active_row_number() == 1) {
|
||||
transcoder = new TranscodeFfmpeg(invid_path_entry.get_text());
|
||||
if (transcoder->probe_ok()) {
|
||||
if (transcoder->probe_ok() && transcoder->get_fps() > 0) {
|
||||
end = transcoder->get_duration() * _session->nominal_frame_rate() / transcoder->get_fps();
|
||||
} else {
|
||||
warning << _("Export Video: Cannot query duration of video-file, using duration from timeline instead.") << endmsg;
|
||||
end = ARDOUR_UI::instance()->video_timeline->get_duration();
|
||||
}
|
||||
if (transcoder) {delete transcoder; transcoder = 0;}
|
||||
|
||||
frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
|
||||
#if 0 /* DEBUG */
|
||||
printf("audio-range -- AV offset: %lld\n", av_offset);
|
||||
#endif
|
||||
if (av_offset > 0) {
|
||||
start += (av_offset / (double)_session->nominal_frame_rate());
|
||||
start = av_offset;
|
||||
}
|
||||
end += (av_offset / (double)_session->nominal_frame_rate());
|
||||
end += av_offset;
|
||||
}
|
||||
if (end <= 0) {
|
||||
start = _session->current_start_frame();
|
||||
end = _session->current_end_frame();
|
||||
}
|
||||
#if 0 /* DEBUG */
|
||||
printf("export-range %ld -> %ld\n", start, end);
|
||||
printf("audio export-range %lld -> %lld\n", start, end);
|
||||
#endif
|
||||
|
||||
tsp->set_range (start, end);
|
||||
|
@ -518,12 +514,12 @@ ExportVideoDialog::launch_export ()
|
|||
usleep (10000);
|
||||
}
|
||||
}
|
||||
status->finish ();
|
||||
if (status->aborted()) {
|
||||
unlink (insnd.c_str());
|
||||
Gtk::Dialog::response(RESPONSE_CANCEL);
|
||||
return;
|
||||
}
|
||||
status->finish ();
|
||||
pbar.set_text (_("Encoding Video.."));
|
||||
encode_pass(1);
|
||||
}
|
||||
|
@ -534,11 +530,6 @@ ExportVideoDialog::encode_pass (int pass)
|
|||
std::string outfn = outfn_path_entry.get_text();
|
||||
std::string invid = invid_path_entry.get_text();
|
||||
|
||||
/* TODO: optimize
|
||||
* if (insnd_combo.get_active_row_number() == 0)
|
||||
* we can skip parsing the input video-file and use
|
||||
* new TranscodeFfmpeg("");
|
||||
*/
|
||||
transcoder = new TranscodeFfmpeg(invid);
|
||||
if (!transcoder->ffexec_ok()) {
|
||||
/* ffmpeg binary was not found. TranscodeFfmpeg prints a warning */
|
||||
|
@ -546,6 +537,13 @@ ExportVideoDialog::encode_pass (int pass)
|
|||
Gtk::Dialog::response(RESPONSE_CANCEL);
|
||||
return;
|
||||
}
|
||||
if (!transcoder->probe_ok()) {
|
||||
/* video input file can not be read */
|
||||
warning << _("Export Video: Video input file cannot be read.") << endmsg;
|
||||
unlink (insnd.c_str());
|
||||
Gtk::Dialog::response(RESPONSE_CANCEL);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string preset = preset_combo.get_active_text();
|
||||
FFSettings ffs ; /* = transcoder->default_encoder_settings(); */
|
||||
|
@ -657,10 +655,19 @@ ExportVideoDialog::encode_pass (int pass)
|
|||
}
|
||||
|
||||
frameoffset_t av_offset = ARDOUR_UI::instance()->video_timeline->get_offset();
|
||||
double duration_s = 0;
|
||||
|
||||
if (insnd_combo.get_active_row_number() == 0) {
|
||||
framecnt_t duration_f = _session->current_end_frame() - _session->current_start_frame();
|
||||
double duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
|
||||
duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
|
||||
} else {
|
||||
framecnt_t duration_f = ARDOUR_UI::instance()->video_timeline->get_duration();
|
||||
if (av_offset < 0 ) {
|
||||
duration_f += av_offset;
|
||||
}
|
||||
duration_s = (double)duration_f / (double)_session->nominal_frame_rate();
|
||||
}
|
||||
|
||||
std::ostringstream osstream; osstream << duration_s;
|
||||
ffs["-t"] = osstream.str();
|
||||
if (fps_checkbox.get_active()) {
|
||||
|
@ -668,23 +675,32 @@ ExportVideoDialog::encode_pass (int pass)
|
|||
} else {
|
||||
transcoder->set_duration(duration_s * transcoder->get_fps());
|
||||
}
|
||||
} else {
|
||||
;
|
||||
// TODO use (end-start) from above
|
||||
// in case offset is negative, video will be shorter..
|
||||
// CHECK; maybe this is not needed -itsoffset may take care of it
|
||||
}
|
||||
|
||||
if (insnd_combo.get_active_row_number() == 0) {
|
||||
framepos_t start = _session->current_start_frame();
|
||||
#if 0
|
||||
double start_s = ((double)start / (double)_session->nominal_frame_rate());
|
||||
std::ostringstream osstream; osstream << start_s;
|
||||
ffs["-ss"] = osstream.str();
|
||||
const framepos_t start = _session->current_start_frame();
|
||||
const framepos_t snend = _session->current_end_frame();
|
||||
const frameoffset_t vid_duration = ARDOUR_UI::instance()->video_timeline->get_duration();
|
||||
|
||||
#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
|
||||
#endif
|
||||
av_offset -= start;
|
||||
|
||||
if (av_offset > start && av_offset + vid_duration < snend) {
|
||||
transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(),
|
||||
(snend - (av_offset + vid_duration)) / (double)_session->nominal_frame_rate());
|
||||
} else if (av_offset > start) {
|
||||
transcoder->set_leadinout((av_offset - start) / (double)_session->nominal_frame_rate(), 0);
|
||||
} else if (av_offset + vid_duration < snend) {
|
||||
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());
|
||||
} else {
|
||||
transcoder->set_avoffset((av_offset - start) / (double)_session->nominal_frame_rate());
|
||||
}
|
||||
} else if (av_offset < 0) {
|
||||
/* from 00:00:00:00 to video-end */
|
||||
transcoder->set_avoffset(av_offset / (double)_session->nominal_frame_rate());
|
||||
}
|
||||
|
||||
FFSettings meta = transcoder->default_meta_data();
|
||||
if (meta_checkbox.get_active()) {
|
||||
|
|
|
@ -42,6 +42,9 @@ TranscodeFfmpeg::TranscodeFfmpeg (std::string f)
|
|||
ffmpeg_exe = "";
|
||||
ffprobe_exe = "";
|
||||
m_duration = 0;
|
||||
m_avoffset = m_lead_in = m_lead_out = 0;
|
||||
m_width = m_height = 0;
|
||||
m_aspect = m_fps = 0;
|
||||
#if 1 /* tentative debug mode */
|
||||
debug_enable = false;
|
||||
#endif
|
||||
|
@ -147,7 +150,9 @@ TranscodeFfmpeg::probe ()
|
|||
std::string key = kv->substr(0, kvsep);
|
||||
std::string value = kv->substr(kvsep + 1);
|
||||
|
||||
if (key == X_("width")) {
|
||||
if (key == X_("index")) {
|
||||
m_videoidx = atoi(value.c_str());
|
||||
} else if (key == X_("width")) {
|
||||
m_width = atoi(value.c_str());
|
||||
} else if (key == X_("height")) {
|
||||
m_height = atoi(value.c_str());
|
||||
|
@ -231,7 +236,7 @@ TranscodeFfmpeg::probe ()
|
|||
while (ffcmd && --timeout) usleep (1000); // wait until 'ffprobe' terminated.
|
||||
if (timeout == 0) return false;
|
||||
|
||||
#if 1 /* DEBUG */
|
||||
#if 0 /* DEBUG */
|
||||
printf("FPS: %f\n", m_fps);
|
||||
printf("Duration: %lu frames\n",(unsigned long)m_duration);
|
||||
printf("W/H: %ix%i\n",m_width, m_height);
|
||||
|
@ -314,6 +319,7 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
|
|||
|
||||
argp[a++] = strdup("-i");
|
||||
argp[a++] = strdup(inf_a.c_str());
|
||||
|
||||
for(FFSettings::const_iterator it = ffs.begin(); it != ffs.end(); ++it) {
|
||||
argp[a++] = strdup(it->first.c_str());
|
||||
argp[a++] = strdup(it->second.c_str());
|
||||
|
@ -322,12 +328,36 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
|
|||
argp[a++] = strdup("-metadata");
|
||||
argp[a++] = format_metadata(it->first.c_str(), it->second.c_str());
|
||||
}
|
||||
if (m_lead_in != 0 && m_lead_out != 0) {
|
||||
std::ostringstream osstream;
|
||||
argp[a++] = strdup("-vf");
|
||||
osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in << X_(" [pre]; ");
|
||||
osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out << X_(" [post]; ");
|
||||
osstream << X_("[pre] [in] [post] concat=n=3");
|
||||
argp[a++] = strdup(osstream.str().c_str());
|
||||
} else if (m_lead_in != 0) {
|
||||
std::ostringstream osstream;
|
||||
argp[a++] = strdup("-vf");
|
||||
osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in << X_(" [pre]; ");
|
||||
osstream << X_("[pre] [in] concat=n=2");
|
||||
argp[a++] = strdup(osstream.str().c_str());
|
||||
} else if (m_lead_out != 0) {
|
||||
std::ostringstream osstream;
|
||||
argp[a++] = strdup("-vf");
|
||||
osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out << X_(" [post]; ");
|
||||
osstream << X_("[in] [post] concat=n=2");
|
||||
argp[a++] = strdup(osstream.str().c_str());
|
||||
}
|
||||
|
||||
if (map) {
|
||||
std::ostringstream osstream;
|
||||
argp[a++] = strdup("-map");
|
||||
argp[a++] = strdup("0:0");
|
||||
osstream << X_("0:") << m_videoidx;
|
||||
argp[a++] = strdup(osstream.str().c_str());
|
||||
argp[a++] = strdup("-map");
|
||||
argp[a++] = strdup("1:0");
|
||||
}
|
||||
|
||||
argp[a++] = strdup("-y");
|
||||
argp[a++] = strdup(outfile.c_str());
|
||||
argp[a] = (char *)0;
|
||||
|
@ -366,7 +396,7 @@ TranscodeFfmpeg::extract_audio (std::string outfile, ARDOUR::framecnt_t samplera
|
|||
argp[i++] = strdup(ffmpeg_exe.c_str());
|
||||
argp[i++] = strdup("-i");
|
||||
argp[i++] = strdup(infile.c_str());
|
||||
#if 0 // native samplerate -- use a3/SRC
|
||||
#if 0 /* ffmpeg write original samplerate, use a3/SRC to resample */
|
||||
argp[i++] = strdup("-ar");
|
||||
argp[i] = (char*) calloc(7,sizeof(char)); snprintf(argp[i++], 7, "%"PRId64, samplerate);
|
||||
#endif
|
||||
|
@ -523,10 +553,15 @@ TranscodeFfmpeg::ffmpegparse_v (std::string d, size_t /* s */)
|
|||
printf("ffmpeg: '%s'\n", d.c_str());
|
||||
}
|
||||
#endif
|
||||
Progress(0, 0); /* EMIT SIGNAL */
|
||||
return;
|
||||
}
|
||||
ARDOUR::framecnt_t f = atol(d.substr(6).c_str());
|
||||
if (f == 0) {
|
||||
Progress(0, 0); /* EMIT SIGNAL */
|
||||
} else {
|
||||
Progress(f, m_duration); /* EMIT SIGNAL */
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* WITH_VIDEOTIMELINE */
|
||||
|
|
|
@ -119,7 +119,9 @@ class TranscodeFfmpeg : public sigc::trackable
|
|||
*/
|
||||
void set_duration(ARDOUR::framecnt_t d) { m_duration = d; }
|
||||
|
||||
/* offset, lead-in/out are in seconds */
|
||||
void set_avoffset(double av_offset) { m_avoffset = av_offset; }
|
||||
void set_leadinout(double lead_in, double lead_out) { m_lead_in = lead_in; m_lead_out = lead_out; }
|
||||
|
||||
|
||||
#if 1 /* tentative debug mode */
|
||||
|
@ -138,7 +140,10 @@ class TranscodeFfmpeg : public sigc::trackable
|
|||
int m_height;
|
||||
std::string m_codec;
|
||||
|
||||
int m_videoidx;
|
||||
double m_avoffset;
|
||||
double m_lead_in;
|
||||
double m_lead_out;
|
||||
bool ffexecok;
|
||||
bool probeok;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user