Preferences/Config changes for image-surface settings
[ardour.git] / gtk2_ardour / transcode_ffmpeg.cc
index 3b3239c2efa19c01899a595936d1ad2d87dd6c0a..5188bff7ac1e171ea29aae3b3e23c71f6d87e30a 100644 (file)
@@ -1,22 +1,23 @@
 /*
-    Copyright (C) 2010-2013 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 02139, USA.
-
-*/
+ * Copyright (C) 2013-2014 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #include <stdio.h>
 #include <string.h>
 #include <sstream>
@@ -98,7 +99,7 @@ TranscodeFfmpeg::probe ()
        ffcmd = new ARDOUR::SystemExec(ffprobe_exe, argp);
        ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffprobeparse, this, _1 ,_2));
        ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
-       if (ffcmd->start(1)) {
+       if (ffcmd->start (SystemExec::IgnoreAndClose)) {
                ffexit();
                return false;
        }
@@ -295,38 +296,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)
@@ -354,7 +323,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) {
@@ -418,7 +387,7 @@ TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf
        ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
        ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
        ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
-       if (ffcmd->start(2)) {
+       if (ffcmd->start (SystemExec::MergeWithStdin)) {
                ffexit();
                return false;
        }
@@ -466,7 +435,7 @@ TranscodeFfmpeg::extract_audio (std::string outfile, ARDOUR::samplecnt_t /*sampl
        ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
        ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_a, this, _1 ,_2));
        ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
-       if (ffcmd->start(2)) {
+       if (ffcmd->start (SystemExec::MergeWithStdin)) {
                ffexit();
                return false;
        }
@@ -526,7 +495,7 @@ TranscodeFfmpeg::transcode (std::string outfile, const int outw, const int outh,
        ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
        ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
        ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
-       if (ffcmd->start(2)) {
+       if (ffcmd->start (SystemExec::MergeWithStdin)) {
                ffexit();
                return false;
        }