X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Ftranscode_ffmpeg.cc;h=b9da8948fa390dfc8120e0bb2c8a05d8b8bab5a4;hb=2558e52e22e3fc604e68a469e9a41608f9166148;hp=3cc45d217db24b8e719441534ea79fc6fe9faf37;hpb=670c066793bb6608070923277fca2fc9dc43d4d2;p=ardour.git diff --git a/gtk2_ardour/transcode_ffmpeg.cc b/gtk2_ardour/transcode_ffmpeg.cc index 3cc45d217d..b9da8948fa 100644 --- a/gtk2_ardour/transcode_ffmpeg.cc +++ b/gtk2_ardour/transcode_ffmpeg.cc @@ -29,6 +29,7 @@ #include "transcode_ffmpeg.h" #include "utils_videotl.h" +#include "video_tool_paths.h" #include "i18n.h" @@ -40,8 +41,6 @@ TranscodeFfmpeg::TranscodeFfmpeg (std::string f) { probeok = false; ffexecok = false; - ffmpeg_exe = ""; - ffprobe_exe = ""; m_duration = 0; m_avoffset = m_lead_in = m_lead_out = 0; m_width = m_height = 0; @@ -51,24 +50,7 @@ TranscodeFfmpeg::TranscodeFfmpeg (std::string f) debug_enable = false; #endif - std::string ff_file_path; - if (find_file_in_search_path (SearchPath(Glib::getenv("PATH")), X_("ffmpeg_harvid"), ff_file_path)) { ffmpeg_exe = ff_file_path; } - else if (Glib::file_test(X_("C:\\Program Files\\harvid\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) { - ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"); - } - else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) { - ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"); - } - - if (find_file_in_search_path (SearchPath(Glib::getenv("PATH")), X_("ffprobe_harvid"), ff_file_path)) { ffprobe_exe = ff_file_path; } - else if (Glib::file_test(X_("C:\\Program Files\\harvid\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) { - ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"); - } - else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) { - ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"); - } - - if (ffmpeg_exe.empty() || ffprobe_exe.empty()) { + if (!ArdourVideoToolPaths::transcoder_exe(ffmpeg_exe, ffprobe_exe)) { warning << string_compose( _( "No ffprobe or ffmpeg executables could be found on this system.\n" @@ -112,7 +94,7 @@ TranscodeFfmpeg::probe () argp[4] = strdup("-show_streams"); argp[5] = strdup(infile.c_str()); argp[6] = 0; - ffcmd = new SystemExec(ffprobe_exe, argp); + ffcmd = new ARDOUR::SystemExec(ffprobe_exe, argp); ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffprobeparse, this, _1 ,_2)); ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this)); if (ffcmd->start(1)) { @@ -127,7 +109,7 @@ TranscodeFfmpeg::probe () * SystemExec::Terminated is emitted and ffcmd set to NULL */ int timeout = 300; // 1.5 sec while (ffcmd && --timeout > 0) { - usleep(5000); + Glib::usleep(5000); } if (timeout == 0 || ffoutput.empty()) { return false; @@ -196,7 +178,7 @@ TranscodeFfmpeg::probe () h * 3600.0 + m * 60.0 + s * 1.0 - + atoi(f) / pow(10, strlen(f)) + + atoi(f) / pow((double)10, (int)strlen(f)) )); } } else if (key == X_("duration_ts") && m_fps == 0 && timebase !=0 ) { @@ -348,6 +330,12 @@ 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_fps > 0) { + m_lead_in = rint (m_lead_in * m_fps) / m_fps; + m_lead_out = rint (m_lead_out * m_fps) / m_fps; + } + if (m_lead_in != 0 && m_lead_out != 0) { std::ostringstream osstream; argp[a++] = strdup("-vf"); @@ -401,7 +389,7 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf } #endif - ffcmd = new SystemExec(ffmpeg_exe, argp); + ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp); ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2)); ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this)); if (ffcmd->start(2)) { @@ -449,7 +437,7 @@ TranscodeFfmpeg::extract_audio (std::string outfile, ARDOUR::framecnt_t /*sample } #endif - ffcmd = new SystemExec(ffmpeg_exe, argp); + ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp); ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_a, this, _1 ,_2)); ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this)); if (ffcmd->start(2)) { @@ -509,7 +497,7 @@ TranscodeFfmpeg::transcode (std::string outfile, const int outw, const int outh, printf("\n"); } #endif - ffcmd = new SystemExec(ffmpeg_exe, argp); + ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp); ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2)); ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this)); if (ffcmd->start(2)) { @@ -524,7 +512,11 @@ TranscodeFfmpeg::cancel () { if (!ffcmd || !ffcmd->is_running()) { return;} ffcmd->write_to_stdin("q"); +#ifdef PLATFORM_WINDOWS + Sleep(1000); +#else sleep (1); +#endif if (ffcmd) { ffcmd->terminate(); } @@ -558,7 +550,7 @@ TranscodeFfmpeg::ffmpegparse_a (std::string d, size_t /* s */) h * 3600.0 + m * 60.0 + s * 1.0 - + atoi(f) / pow(10, strlen(f)) + + atoi(f) / pow((double)10, (int)strlen(f)) )); p = p * m_fps / 100.0; if (p > m_duration ) { p = m_duration; }