FFMPEG/MP3 encoder quality select GUI
[ardour.git] / gtk2_ardour / transcode_ffmpeg.cc
1 /*
2     Copyright (C) 2010-2013 Paul Davis
3     Author: Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20 #include <stdio.h>
21 #include <string.h>
22 #include <sstream>
23 #include <sys/types.h>
24
25 #include "pbd/error.h"
26 #include "pbd/convert.h"
27 #include "pbd/file_utils.h"
28 #include "gui_thread.h"
29
30 #include "ardour/filesystem_paths.h"
31
32 #include "transcode_ffmpeg.h"
33 #include "utils_videotl.h"
34
35 #include "pbd/i18n.h"
36
37 using namespace PBD;
38 using namespace VideoUtils;
39
40 TranscodeFfmpeg::TranscodeFfmpeg (std::string f)
41         : infile(f)
42 {
43         probeok = false;
44         ffexecok = false;
45         m_duration = 0;
46         m_avoffset = m_lead_in = m_lead_out = 0;
47         m_width = m_height = 0;
48         m_aspect = m_fps = 0;
49         m_sar = "";
50 #if 1 /* tentative debug mode */
51         debug_enable = false;
52 #endif
53
54         if (!ARDOUR::ArdourVideoToolPaths::transcoder_exe(ffmpeg_exe, ffprobe_exe)) {
55                 warning << string_compose(
56                                 _(
57                                         "ffmpeg installation was not found on this system.\n"
58                                         "%1 requires ffmpeg and ffprobe from ffmpeg.org - version 1.1 or newer.\n"
59                                         "Video import and export is not possible until you install tools.\n"
60                                         "\n"
61                                         "The tools are included with the %1 releases from ardour.org "
62                                         "and also available with the video-server at http://x42.github.com/harvid/\n"
63                                         "\n"
64                                         "Important: the files need to be installed in $PATH and named ffmpeg_harvid and ffprobe_harvid.\n"
65                                         "If you already have a suitable ffmpeg installation on your system, we recommend creating "
66                                         "symbolic links from ffmpeg to ffmpeg_harvid and from ffprobe to ffprobe_harvid.\n"
67                                         "\n"
68                                         "see also http://manual.ardour.org/video-timeline/setup/"
69                                  ), PROGRAM_NAME) << endmsg;
70                 return;
71         }
72         ffexecok = true;
73
74         if (infile.empty() || !probe()) {
75                 return;
76         }
77         probeok = true;
78 }
79
80 TranscodeFfmpeg::~TranscodeFfmpeg ()
81 {
82   ;
83 }
84
85 bool
86 TranscodeFfmpeg::probe ()
87 {
88         ffoutput = "";
89         char **argp;
90         argp=(char**) calloc(7,sizeof(char*));
91         argp[0] = strdup(ffprobe_exe.c_str());
92         argp[1] = strdup("-print_format");
93         argp[2] = strdup("csv=nk=0");
94         argp[3] = strdup("-show_format");
95         argp[4] = strdup("-show_streams");
96         argp[5] = strdup(infile.c_str());
97         argp[6] = 0;
98         ffcmd = new ARDOUR::SystemExec(ffprobe_exe, argp);
99         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffprobeparse, this, _1 ,_2));
100         ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
101         if (ffcmd->start(1)) {
102                 ffexit();
103                 return false;
104         }
105
106         /* wait for ffprobe process to exit */
107         ffcmd->wait();
108
109         /* wait for interposer thread to copy all data.
110          * SystemExec::Terminated is emitted and ffcmd set to NULL */
111         int timeout = 300; // 1.5 sec
112         while (ffcmd && --timeout > 0) {
113                 Glib::usleep(5000);
114                 ARDOUR::GUIIdle();
115         }
116         if (timeout == 0 || ffoutput.empty()) {
117                 return false;
118         }
119
120         /* parse */
121
122         std::vector<std::vector<std::string> > lines;
123         ParseCSV(ffoutput, lines);
124         double timebase = 0;
125         m_width = m_height = 0;
126         m_fps = m_aspect = 0;
127         m_duration = 0;
128         m_sar.clear();
129         m_codec.clear();
130         m_audio.clear();
131
132 #define PARSE_FRACTIONAL_FPS(VAR) \
133         { \
134                 std::string::size_type pos; \
135                 VAR = atof(value); \
136                 pos = value.find_first_of('/'); \
137                 if (pos != std::string::npos) { \
138                         VAR = atof(value.substr(0, pos)) / atof(value.substr(pos+1)); \
139                 } \
140         }
141
142         std::string duration_from_format;
143
144         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
145                 if (i->at(0) == X_("format")) {
146                         /* format,filename,#streams,format-name,format-long-name,start-time,duration,size,bitrate */
147                         for (std::vector<std::string>::iterator kv = i->begin(); kv != i->end(); ++kv) {
148                                 const size_t kvsep = kv->find('=');
149                                 if(kvsep == std::string::npos) continue;
150                                 std::string key = kv->substr(0, kvsep);
151                                 std::string value = kv->substr(kvsep + 1);
152                                 if (key == X_("duration")) {
153                                         duration_from_format = value;
154                                 }
155                         }
156                 } else
157                 if (i->at(0) == X_("stream")) {
158                         if (i->at(5) == X_("codec_type=video") && m_width == 0) {
159
160                                 for (std::vector<std::string>::iterator kv = i->begin(); kv != i->end(); ++kv) {
161                                         const size_t kvsep = kv->find('=');
162                                         if(kvsep == std::string::npos) continue;
163                                         std::string key = kv->substr(0, kvsep);
164                                         std::string value = kv->substr(kvsep + 1);
165
166                                         if (key == X_("index")) {
167                                                 m_videoidx = atoi(value);
168                                         } else if (key == X_("width")) {
169                                                 m_width = atoi(value);
170                                         } else if (key == X_("height")) {
171                                                 m_height = atoi(value);
172                                         } else if (key == X_("codec_name")) {
173                                                 if (!m_codec.empty()) m_codec += " ";
174                                                 m_codec += value;
175                                         } else if (key == X_("codec_long_name")) {
176                                                 if (!m_codec.empty()) m_codec += " ";
177                                                 m_codec += "[" + value + "]";
178                                         } else if (key == X_("codec_tag_string")) {
179                                                 if (!m_codec.empty()) m_codec += " ";
180                                                 m_codec += "(" + value + ")";
181                                         } else if (key == X_("r_frame_rate")) {
182                                                 PARSE_FRACTIONAL_FPS(m_fps)
183                                         } else if (key == X_("avg_frame_rate") && m_fps == 0) {
184                                                 PARSE_FRACTIONAL_FPS(m_fps)
185                                         } else if (key == X_("time_base")) {
186                                                 PARSE_FRACTIONAL_FPS(timebase)
187                                         } else if (key == X_("timecode") && m_duration == 0 && m_fps > 0) {
188                                                 int h,m,s; char f[32];
189                                                 if (sscanf(i->at(16).c_str(), "%d:%d:%d:%32s",&h,&m,&s,f) == 4) {
190                                                         m_duration = (ARDOUR::samplecnt_t) floor(m_fps * (
191                                                                         h * 3600.0
192                                                                 + m * 60.0
193                                                                 + s * 1.0
194                                                                 + atoi(f) / pow((double)10, (int)strlen(f))
195                                                         ));
196                                                 }
197                                         } else if (key == X_("duration_ts") && m_fps == 0 && timebase !=0 ) {
198                                                 m_duration = atof(value) * m_fps * timebase;
199                                         } else if (key == X_("duration") && m_fps != 0 && m_duration == 0) {
200                                                 m_duration = atof(value) * m_fps;
201                                         } else if (key == X_("sample_aspect_ratio")) {
202                                                 std::string::size_type pos;
203                                                 pos = value.find_first_of(':');
204                                                 if (pos != std::string::npos && atof(value.substr(pos+1)) != 0) {
205                                                         m_sar = value;
206                                                         m_sar.replace(pos, 1, "/");
207                                                 }
208                                         } else if (key == X_("display_aspect_ratio")) {
209                                                 std::string::size_type pos;
210                                                 pos = value.find_first_of(':');
211                                                 if (pos != std::string::npos && atof(value.substr(pos+1)) != 0) {
212                                                         m_aspect = atof(value.substr(0, pos)) / atof(value.substr(pos+1));
213                                                 }
214                                         }
215                                 }
216
217                                 if (m_aspect == 0) {
218                                         m_aspect = (double)m_width / (double)m_height;
219                                 }
220
221                         } else if (i->at(5) == X_("codec_type=audio")) { /* new ffprobe */
222                                 FFAudioStream as;
223                                 for (std::vector<std::string>::iterator kv = i->begin(); kv != i->end(); ++kv) {
224                                         const size_t kvsep = kv->find('=');
225                                         if(kvsep == std::string::npos) continue;
226                                         std::string key = kv->substr(0, kvsep);
227                                         std::string value = kv->substr(kvsep + 1);
228
229                                         if (key == X_("channels")) {
230                                                 as.channels   = atoi(value);
231                                         } else if (key == X_("index")) {
232                                                 as.stream_id  = value;
233                                         } else if (key == X_("codec_long_name")) {
234                                                 if (!as.name.empty()) as.name += " ";
235                                                 as.name += value;
236                                         } else if (key == X_("codec_name")) {
237                                                 if (!as.name.empty()) as.name += " ";
238                                                 as.name += value;
239                                         } else if (key == X_("sample_fmt")) {
240                                                 if (!as.name.empty()) as.name += " ";
241                                                 as.name += "FMT:" + value;
242                                         } else if (key == X_("sample_rate")) {
243                                                 if (!as.name.empty()) as.name += " ";
244                                                 as.name += "SR:" + value;
245                                         }
246
247                                 }
248                                 m_audio.push_back(as);
249                         }
250                 }
251         }
252         /* end parse */
253
254         if (m_duration == 0 && !duration_from_format.empty() && m_fps > 0) {
255                 warning << "using video-duration from format (container)." << endmsg;
256                 m_duration = atof(duration_from_format) * m_fps;
257         }
258
259 #if 0 /* DEBUG */
260         printf("FPS: %f\n", m_fps);
261         printf("Duration: %lu frames\n",(unsigned long)m_duration);
262         printf("W/H: %ix%i\n",m_width, m_height);
263         printf("aspect: %f\n",m_aspect);
264         printf("codec: %s\n",m_codec.c_str());
265         if (m_audio.size() > 0) {
266                 for (AudioStreams::iterator it = m_audio.begin(); it < m_audio.end(); ++it) {
267                         printf("audio: %s - %i channels\n",(*it).stream_id.c_str(), (*it).channels);
268                 }
269         } else {
270           printf("audio: no audio streams in file.\n");
271         }
272 #endif
273
274         return true;
275 }
276
277 TranscodeFfmpeg::FFSettings
278 TranscodeFfmpeg::default_encoder_settings ()
279 {
280         TranscodeFfmpeg::FFSettings ffs;
281         ffs.clear();
282         ffs["-vcodec"] = "mpeg4";
283         ffs["-acodec"] = "ac3";
284         ffs["-b:v"] = "5000k";
285         ffs["-b:a"] = "160k";
286         return ffs;
287 }
288
289 TranscodeFfmpeg::FFSettings
290 TranscodeFfmpeg::default_meta_data ()
291 {
292         TranscodeFfmpeg::FFSettings ffm;
293         ffm.clear();
294         ffm["comment"] = "Created with " PROGRAM_NAME;
295         return ffm;
296 }
297
298 char *
299 TranscodeFfmpeg::format_metadata (std::string key, std::string value)
300 {
301         size_t start_pos = 0;
302         std::string v1 = value;
303         while((start_pos = v1.find_first_not_of(
304                         "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789(),.\"'",
305                         start_pos)) != std::string::npos)
306         {
307                 v1.replace(start_pos, 1, "_");
308                 start_pos += 1;
309         }
310
311         start_pos = 0;
312         while((start_pos = v1.find("\"", start_pos)) != std::string::npos) {
313                 v1.replace(start_pos, 1, "\\\"");
314                 start_pos += 2;
315         }
316
317         size_t len = key.length() + v1.length() + 4;
318         char *mds = (char*) calloc(len, sizeof(char));
319 #ifdef PLATFORM_WINDOWS
320         /* SystemExec::make_wargs() adds quotes around the complete argument
321          * windows uses CreateProcess() with a parameter string
322          * (and not an array list of separate arguments)
323          */
324         snprintf(mds, len, "%s=%s", key.c_str(), v1.c_str());
325 #else
326         snprintf(mds, len, "%s=\"%s\"", key.c_str(), v1.c_str());
327 #endif
328         return mds;
329 }
330
331 bool
332 TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf_v, TranscodeFfmpeg::FFSettings ffs, TranscodeFfmpeg::FFSettings meta, bool map)
333 {
334 #define MAX_FFMPEG_ENCODER_ARGS (100)
335         char **argp;
336         int a=0;
337
338         argp=(char**) calloc(MAX_FFMPEG_ENCODER_ARGS,sizeof(char*));
339         argp[a++] = strdup(ffmpeg_exe.c_str());
340         if (m_avoffset < 0 || m_avoffset > 0) {
341                 std::ostringstream osstream; osstream << m_avoffset;
342                 argp[a++] = strdup("-itsoffset");
343                 argp[a++] = strdup(osstream.str().c_str());
344         }
345         argp[a++] = strdup("-i");
346         argp[a++] = strdup(inf_v.c_str());
347
348         argp[a++] = strdup("-i");
349         argp[a++] = strdup(inf_a.c_str());
350
351         for(TranscodeFfmpeg::FFSettings::const_iterator it = ffs.begin(); it != ffs.end(); ++it) {
352                 argp[a++] = strdup(it->first.c_str());
353                 argp[a++] = strdup(it->second.c_str());
354         }
355         for(TranscodeFfmpeg::FFSettings::const_iterator it = meta.begin(); it != meta.end(); ++it) {
356                 argp[a++] = strdup("-metadata");
357                 argp[a++] = format_metadata(it->first.c_str(), it->second.c_str());
358         }
359
360         if (m_fps > 0) {
361                 m_lead_in  = rint (m_lead_in * m_fps) / m_fps;
362                 m_lead_out = rint (m_lead_out * m_fps) / m_fps;
363         }
364
365         if (m_lead_in != 0 && m_lead_out != 0) {
366                 std::ostringstream osstream;
367                 argp[a++] = strdup("-vf");
368                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in;
369                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
370                 osstream << X_(" [pre]; ");
371                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out;
372                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
373                 osstream << X_(" [post]; ");
374                 osstream << X_("[pre] [in] [post] concat=n=3");
375                 argp[a++] = strdup(osstream.str().c_str());
376         } else if (m_lead_in != 0) {
377                 std::ostringstream osstream;
378                 argp[a++] = strdup("-vf");
379                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in;
380                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
381                 osstream << X_(" [pre]; ");
382                 osstream << X_("[pre] [in] concat=n=2");
383                 argp[a++] = strdup(osstream.str().c_str());
384         } else if (m_lead_out != 0) {
385                 std::ostringstream osstream;
386                 argp[a++] = strdup("-vf");
387                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out;
388                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
389                 osstream << X_(" [post]; ");
390                 osstream << X_("[in] [post] concat=n=2");
391                 argp[a++] = strdup(osstream.str().c_str());
392         }
393
394         if (map) {
395                 std::ostringstream osstream;
396                 argp[a++] = strdup("-map");
397                 osstream << X_("0:") << m_videoidx;
398                 argp[a++] = strdup(osstream.str().c_str());
399                 argp[a++] = strdup("-map");
400                 argp[a++] = strdup("1:0");
401         }
402
403         argp[a++] = strdup("-y");
404         argp[a++] = strdup(outfile.c_str());
405         argp[a] = (char *)0;
406         assert(a<MAX_FFMPEG_ENCODER_ARGS);
407         /* Note: these are free()d in ~SystemExec */
408 #if 1 /* DEBUG */
409         if (debug_enable) { /* tentative debug mode */
410         printf("EXPORT ENCODE:\n");
411         for (int i=0; i< a; ++i) {
412           printf("%s ", argp[i]);
413         }
414         printf("\n");
415         }
416 #endif
417
418         ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
419         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
420         ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
421         if (ffcmd->start(2)) {
422                 ffexit();
423                 return false;
424         }
425         return true;
426 }
427
428 bool
429 TranscodeFfmpeg::extract_audio (std::string outfile, ARDOUR::samplecnt_t /*samplerate*/, unsigned int stream)
430 {
431         if (!probeok) return false;
432   if (stream >= m_audio.size()) return false;
433
434         char **argp;
435         int i = 0;
436
437         argp=(char**) calloc(15,sizeof(char*));
438         argp[i++] = strdup(ffmpeg_exe.c_str());
439         argp[i++] = strdup("-i");
440         argp[i++] = strdup(infile.c_str());
441 #if 0 /* ffmpeg write original samplerate, use a3/SRC to resample */
442         argp[i++] = strdup("-ar");
443         argp[i] = (char*) calloc(7,sizeof(char)); snprintf(argp[i++], 7, "%"PRId64, samplerate);
444 #endif
445         argp[i++] = strdup("-ac");
446         argp[i] = (char*) calloc(3,sizeof(char)); snprintf(argp[i++], 3, "%i", m_audio.at(stream).channels);
447         argp[i++] = strdup("-map");
448         argp[i] = (char*) calloc(8,sizeof(char)); snprintf(argp[i++], 8, "0:%s", m_audio.at(stream).stream_id.c_str());
449         argp[i++] = strdup("-vn");
450         argp[i++] = strdup("-acodec");
451         argp[i++] = strdup("pcm_f32le");
452         argp[i++] = strdup("-y");
453         argp[i++] = strdup(outfile.c_str());
454         argp[i++] = (char *)0;
455         /* Note: argp is free()d in ~SystemExec */
456 #if 1 /* DEBUG */
457         if (debug_enable) { /* tentative debug mode */
458         printf("EXTRACT AUDIO:\n");
459         for (int i=0; i< 14; ++i) {
460           printf("%s ", argp[i]);
461         }
462         printf("\n");
463         }
464 #endif
465
466         ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
467         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_a, this, _1 ,_2));
468         ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
469         if (ffcmd->start(2)) {
470                 ffexit();
471                 return false;
472         }
473         return true;
474 }
475
476
477 bool
478 TranscodeFfmpeg::transcode (std::string outfile, const int outw, const int outh, const int kbitps)
479 {
480         if (!probeok) return false;
481
482         char **argp;
483         int bitrate = kbitps;
484         int width = outw;
485         int height = outh;
486
487         if (width < 1 || width > m_width) { width = m_width; } /* don't allow upscaling */
488         if (height < 1 || height > m_height) { height = floor(width / m_aspect); }
489
490         if (bitrate == 0) {
491                 const double bitperpixel = .7; /* avg quality */
492                 bitrate = floor(m_fps * width * height * bitperpixel / 10000.0);
493         } else {
494                 bitrate = bitrate / 10;
495         }
496         if (bitrate < 10)  bitrate = 10;
497         if (bitrate > 1000) bitrate = 1000;
498
499         argp=(char**) calloc(16,sizeof(char*));
500         argp[0] = strdup(ffmpeg_exe.c_str());
501         argp[1] = strdup("-i");
502         argp[2] = strdup(infile.c_str());
503         argp[3] = strdup("-b:v");
504         argp[4] = (char*) calloc(7,sizeof(char)); snprintf(argp[4], 7, "%i0k", bitrate);
505         argp[5] = strdup("-s");
506         argp[6] = (char*) calloc(10,sizeof(char)); snprintf(argp[6], 10, "%ix%i", width, height);
507         argp[7] = strdup("-y");
508         argp[8] = strdup("-vcodec");
509         argp[9] = strdup("mjpeg");
510         argp[10] = strdup("-an");
511         argp[11] = strdup("-intra");
512         argp[12] = strdup("-g");
513         argp[13] = strdup("1");
514         argp[14] = strdup(outfile.c_str());
515         argp[15] = (char *)0;
516         /* Note: these are free()d in ~SystemExec */
517 #if 1 /* DEBUG */
518         if (debug_enable) { /* tentative debug mode */
519         printf("TRANSCODE VIDEO:\n");
520         for (int i=0; i< 15; ++i) {
521           printf("%s ", argp[i]);
522         }
523         printf("\n");
524         }
525 #endif
526         ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
527         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
528         ffcmd->Terminated.connect (*this, invalidator (*this), boost::bind (&TranscodeFfmpeg::ffexit, this), gui_context());
529         if (ffcmd->start(2)) {
530                 ffexit();
531                 return false;
532         }
533         return true;
534 }
535
536 void
537 TranscodeFfmpeg::cancel ()
538 {
539         if (!ffcmd || !ffcmd->is_running()) { return;}
540         ffcmd->write_to_stdin("q");
541 #ifdef PLATFORM_WINDOWS
542         Sleep(1000);
543 #else
544         sleep (1);
545 #endif
546         if (ffcmd) {
547           ffcmd->terminate();
548         }
549 }
550
551 void
552 TranscodeFfmpeg::ffexit ()
553 {
554         delete ffcmd;
555         ffcmd=0;
556         Finished(); /* EMIT SIGNAL */
557 }
558
559 void
560 TranscodeFfmpeg::ffprobeparse (std::string d, size_t /* s */)
561 {
562         ffoutput+=d;
563 }
564
565 void
566 TranscodeFfmpeg::ffmpegparse_a (std::string d, size_t /* s */)
567 {
568         const char *t;
569         int h,m,s; char f[7];
570         ARDOUR::samplecnt_t p = -1;
571
572         if (!(t=strstr(d.c_str(), "time="))) { return; }
573
574         if (sscanf(t+5, "%d:%d:%d.%s",&h,&m,&s,f) == 4) {
575                 p = (ARDOUR::samplecnt_t) floor( 100.0 * (
576                       h * 3600.0
577                     + m * 60.0
578                     + s * 1.0
579                     + atoi(f) / pow((double)10, (int)strlen(f))
580                 ));
581                 p = p * m_fps / 100.0;
582                 if (p > m_duration ) { p = m_duration; }
583                 Progress(p, m_duration); /* EMIT SIGNAL */
584         } else {
585                 Progress(0, 0); /* EMIT SIGNAL */
586         }
587 }
588
589 void
590 TranscodeFfmpeg::ffmpegparse_v (std::string d, size_t /* s */)
591 {
592         if (strstr(d.c_str(), "ERROR") || strstr(d.c_str(), "Error") || strstr(d.c_str(), "error")) {
593                 warning << "ffmpeg-error: " << d << endmsg;
594         }
595         if (strncmp(d.c_str(), "frame=",6)) {
596 #if 1 /* DEBUG */
597                 if (debug_enable) {
598                         d.erase(d.find_last_not_of(" \t\r\n") + 1);
599                   printf("ffmpeg: '%s'\n", d.c_str());
600                 }
601 #endif
602                 return;
603         }
604         ARDOUR::samplecnt_t f = atol(d.substr(6));
605         if (f == 0) {
606                 Progress(0, 0); /* EMIT SIGNAL */
607         } else {
608                 Progress(f, m_duration); /* EMIT SIGNAL */
609         }
610 }