Prepare central engine check and user notification
[ardour.git] / gtk2_ardour / transcode_ffmpeg.cc
index e62d9b301b4e5fd19b89fb8174ee6df0b4445825..a26c7622f5ea985bb65a3cc0e6bc434552e36166 100644 (file)
 #include "pbd/file_utils.h"
 #include "gui_thread.h"
 
+#include "ardour/filesystem_paths.h"
+
 #include "transcode_ffmpeg.h"
 #include "utils_videotl.h"
-#include "video_tool_paths.h"
 
 #include "pbd/i18n.h"
 
@@ -50,7 +51,7 @@ TranscodeFfmpeg::TranscodeFfmpeg (std::string f)
        debug_enable = false;
 #endif
 
-       if (!ArdourVideoToolPaths::transcoder_exe(ffmpeg_exe, ffprobe_exe)) {
+       if (!ARDOUR::ArdourVideoToolPaths::transcoder_exe(ffmpeg_exe, ffprobe_exe)) {
                warning << string_compose(
                                _(
                                        "ffmpeg installation was not found on this system.\n"
@@ -177,9 +178,9 @@ TranscodeFfmpeg::probe ()
                                        } else if (key == X_("codec_tag_string")) {
                                                if (!m_codec.empty()) m_codec += " ";
                                                m_codec += "(" + value + ")";
-                                       } else if (key == X_("r_sample_rate")) {
+                                       } else if (key == X_("r_frame_rate")) {
                                                PARSE_FRACTIONAL_FPS(m_fps)
-                                       } else if (key == X_("avg_sample_rate") && m_fps == 0) {
+                                       } else if (key == X_("avg_frame_rate") && m_fps == 0) {
                                                PARSE_FRACTIONAL_FPS(m_fps)
                                        } else if (key == X_("time_base")) {
                                                PARSE_FRACTIONAL_FPS(timebase)
@@ -257,7 +258,7 @@ TranscodeFfmpeg::probe ()
 
 #if 0 /* DEBUG */
        printf("FPS: %f\n", m_fps);
-       printf("Duration: %lu samples\n",(unsigned long)m_duration);
+       printf("Duration: %lu frames\n",(unsigned long)m_duration);
        printf("W/H: %ix%i\n",m_width, m_height);
        printf("aspect: %f\n",m_aspect);
        printf("codec: %s\n",m_codec.c_str());
@@ -294,38 +295,6 @@ TranscodeFfmpeg::default_meta_data ()
        return ffm;
 }
 
-char *
-TranscodeFfmpeg::format_metadata (std::string key, std::string value)
-{
-       size_t start_pos = 0;
-       std::string v1 = value;
-       while((start_pos = v1.find_first_not_of(
-                       "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789(),.\"'",
-                       start_pos)) != std::string::npos)
-       {
-               v1.replace(start_pos, 1, "_");
-               start_pos += 1;
-       }
-
-       start_pos = 0;
-       while((start_pos = v1.find("\"", start_pos)) != std::string::npos) {
-               v1.replace(start_pos, 1, "\\\"");
-               start_pos += 2;
-       }
-
-       size_t len = key.length() + v1.length() + 4;
-       char *mds = (char*) calloc(len, sizeof(char));
-#ifdef PLATFORM_WINDOWS
-       /* SystemExec::make_wargs() adds quotes around the complete argument
-        * windows uses CreateProcess() with a parameter string
-        * (and not an array list of separate arguments)
-        */
-       snprintf(mds, len, "%s=%s", key.c_str(), v1.c_str());
-#else
-       snprintf(mds, len, "%s=\"%s\"", key.c_str(), v1.c_str());
-#endif
-       return mds;
-}
 
 bool
 TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf_v, TranscodeFfmpeg::FFSettings ffs, TranscodeFfmpeg::FFSettings meta, bool map)
@@ -353,7 +322,7 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
        }
        for(TranscodeFfmpeg::FFSettings::const_iterator it = meta.begin(); it != meta.end(); ++it) {
                argp[a++] = strdup("-metadata");
-               argp[a++] = format_metadata(it->first.c_str(), it->second.c_str());
+               argp[a++] = SystemExec::format_key_value_parameter (it->first.c_str(), it->second.c_str());
        }
 
        if (m_fps > 0) {
@@ -591,14 +560,13 @@ TranscodeFfmpeg::ffmpegparse_v (std::string d, size_t /* s */)
        if (strstr(d.c_str(), "ERROR") || strstr(d.c_str(), "Error") || strstr(d.c_str(), "error")) {
                warning << "ffmpeg-error: " << d << endmsg;
        }
-       if (strncmp(d.c_str(), "sample=",6)) {
+       if (strncmp(d.c_str(), "frame=",6)) {
 #if 1 /* DEBUG */
                if (debug_enable) {
                        d.erase(d.find_last_not_of(" \t\r\n") + 1);
                  printf("ffmpeg: '%s'\n", d.c_str());
                }
 #endif
-               Progress(0, 0); /* EMIT SIGNAL */
                return;
        }
        ARDOUR::samplecnt_t f = atol(d.substr(6));