Rename PBD::find_file_in_search_path to just PBD::find_file
[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 "transcode_ffmpeg.h"
31 #include "utils_videotl.h"
32
33 #include "i18n.h"
34
35 using namespace PBD;
36 using namespace VideoUtils;
37
38 TranscodeFfmpeg::TranscodeFfmpeg (std::string f)
39         : infile(f)
40 {
41         probeok = false;
42         ffexecok = false;
43         ffmpeg_exe = "";
44         ffprobe_exe = "";
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         std::string ff_file_path;
55         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffmpeg_harvid"), ff_file_path)) { ffmpeg_exe = ff_file_path; }
56         else if (Glib::file_test(X_("C:\\Program Files\\harvid\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
57                 ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
58         }
59         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe"), Glib::FILE_TEST_EXISTS)) {
60                 ffmpeg_exe = X_("C:\\Program Files\\ffmpeg\\ffmpeg.exe");
61         }
62
63         if (find_file (Searchpath(Glib::getenv("PATH")), X_("ffprobe_harvid"), ff_file_path)) { ffprobe_exe = ff_file_path; }
64         else if (Glib::file_test(X_("C:\\Program Files\\harvid\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
65                 ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
66         }
67         else if (Glib::file_test(X_("C:\\Program Files\\ffmpeg\\ffprobe.exe"), Glib::FILE_TEST_EXISTS)) {
68                 ffprobe_exe = X_("C:\\Program Files\\ffmpeg\\ffprobe.exe");
69         }
70
71         if (ffmpeg_exe.empty() || ffprobe_exe.empty()) {
72                 warning << string_compose(
73                                 _(
74                                         "No ffprobe or ffmpeg executables could be found on this system.\n"
75                                         "Video import and export is not possible until you install those tools.\n"
76                                         "%1 requires ffmpeg and ffprobe from ffmpeg.org - version 1.1 or newer.\n"
77                                         "\n"
78                                         "The tools are included with the %1 releases from ardour.org "
79                                         "and also available with the video-server at http://x42.github.com/harvid/\n"
80                                         "\n"
81                                         "Important: the files need to be installed in $PATH and named ffmpeg_harvid and ffprobe_harvid.\n"
82                                         "If you already have a suitable ffmpeg installation on your system, we recommend creating "
83                                         "symbolic links from ffmpeg to ffmpeg_harvid and from ffprobe to ffprobe_harvid.\n"
84                                         "\n"
85                                         "see also http://manual.ardour.org/video-timeline/setup/"
86                                  ), PROGRAM_NAME) << endmsg;
87                 return;
88         }
89         ffexecok = true;
90
91         if (infile.empty() || !probe()) {
92                 return;
93         }
94         probeok = true;
95 }
96
97 TranscodeFfmpeg::~TranscodeFfmpeg ()
98 {
99   ;
100 }
101
102 bool
103 TranscodeFfmpeg::probe ()
104 {
105         ffoutput = "";
106         char **argp;
107         argp=(char**) calloc(7,sizeof(char*));
108         argp[0] = strdup(ffprobe_exe.c_str());
109         argp[1] = strdup("-print_format");
110         argp[2] = strdup("csv=nk=0");
111         argp[3] = strdup("-show_format");
112         argp[4] = strdup("-show_streams");
113         argp[5] = strdup(infile.c_str());
114         argp[6] = 0;
115         ffcmd = new ARDOUR::SystemExec(ffprobe_exe, argp);
116         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffprobeparse, this, _1 ,_2));
117         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
118         if (ffcmd->start(1)) {
119                 ffexit();
120                 return false;
121         }
122
123         /* wait for ffprobe process to exit */
124         ffcmd->wait();
125
126         /* wait for interposer thread to copy all data.
127          * SystemExec::Terminated is emitted and ffcmd set to NULL */
128         int timeout = 300; // 1.5 sec
129         while (ffcmd && --timeout > 0) {
130                 Glib::usleep(5000);
131         }
132         if (timeout == 0 || ffoutput.empty()) {
133                 return false;
134         }
135
136         /* parse */
137
138         std::vector<std::vector<std::string> > lines;
139         ParseCSV(ffoutput, lines);
140         double timebase = 0;
141         m_width = m_height = 0;
142         m_fps = m_aspect = 0;
143         m_duration = 0;
144         m_sar.clear();
145         m_codec.clear();
146         m_audio.clear();
147
148 #define PARSE_FRACTIONAL_FPS(VAR) \
149         { \
150                 std::string::size_type pos; \
151                 VAR = atof(value); \
152                 pos = value.find_first_of('/'); \
153                 if (pos != std::string::npos) { \
154                         VAR = atof(value.substr(0, pos)) / atof(value.substr(pos+1)); \
155                 } \
156         }
157
158         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
159                 if (i->at(0) == X_("format")) {
160                         /* format,filename,#streams,format-name,format-long-name,start-time,duration,size,bitrate */
161                 } else
162                 if (i->at(0) == X_("stream")) {
163                         if (i->at(5) == X_("codec_type=video") && m_width == 0) {
164
165                                 for (std::vector<std::string>::iterator kv = i->begin(); kv != i->end(); ++kv) {
166                                         const size_t kvsep = kv->find('=');
167                                         if(kvsep == std::string::npos) continue;
168                                         std::string key = kv->substr(0, kvsep);
169                                         std::string value = kv->substr(kvsep + 1);
170
171                                         if (key == X_("index")) {
172                                                 m_videoidx = atoi(value);
173                                         } else if (key == X_("width")) {
174                                                 m_width = atoi(value);
175                                         } else if (key == X_("height")) {
176                                                 m_height = atoi(value);
177                                         } else if (key == X_("codec_name")) {
178                                                 if (!m_codec.empty()) m_codec += " ";
179                                                 m_codec += value;
180                                         } else if (key == X_("codec_long_name")) {
181                                                 if (!m_codec.empty()) m_codec += " ";
182                                                 m_codec += "[" + value + "]";
183                                         } else if (key == X_("codec_tag_string")) {
184                                                 if (!m_codec.empty()) m_codec += " ";
185                                                 m_codec += "(" + value + ")";
186                                         } else if (key == X_("r_frame_rate")) {
187                                                 PARSE_FRACTIONAL_FPS(m_fps)
188                                         } else if (key == X_("avg_frame_rate") && m_fps == 0) {
189                                                 PARSE_FRACTIONAL_FPS(m_fps)
190                                         } else if (key == X_("time_base")) {
191                                                 PARSE_FRACTIONAL_FPS(timebase)
192                                         } else if (key == X_("timecode") && m_duration == 0) {
193                                                 int h,m,s; char f[7];
194                                                 if (sscanf(i->at(16).c_str(), "%d:%d:%d:%s",&h,&m,&s,f) == 4) {
195                                                         m_duration = (ARDOUR::framecnt_t) floor(m_fps * (
196                                                                         h * 3600.0
197                                                                 + m * 60.0
198                                                                 + s * 1.0
199                                                                 + atoi(f) / pow((double)10, (int)strlen(f))
200                                                         ));
201                                                 }
202                                         } else if (key == X_("duration_ts") && m_fps == 0 && timebase !=0 ) {
203                                                 m_duration = atof(value) * m_fps * timebase;
204                                         } else if (key == X_("duration") && m_fps != 0 && m_duration == 0) {
205                                                 m_duration = atof(value) * m_fps;
206                                         } else if (key == X_("sample_aspect_ratio")) {
207                                                 std::string::size_type pos;
208                                                 pos = value.find_first_of(':');
209                                                 if (pos != std::string::npos && atof(value.substr(pos+1)) != 0) {
210                                                         m_sar = value;
211                                                         m_sar.replace(pos, 1, "/");
212                                                 }
213                                         } else if (key == X_("display_aspect_ratio")) {
214                                                 std::string::size_type pos;
215                                                 pos = value.find_first_of(':');
216                                                 if (pos != std::string::npos && atof(value.substr(pos+1)) != 0) {
217                                                         m_aspect = atof(value.substr(0, pos)) / atof(value.substr(pos+1));
218                                                 }
219                                         }
220                                 }
221
222                                 if (m_aspect == 0) {
223                                         m_aspect = (double)m_width / (double)m_height;
224                                 }
225
226                         } else if (i->at(5) == X_("codec_type=audio")) { /* new ffprobe */
227                                 FFAudioStream as;
228                                 for (std::vector<std::string>::iterator kv = i->begin(); kv != i->end(); ++kv) {
229                                         const size_t kvsep = kv->find('=');
230                                         if(kvsep == std::string::npos) continue;
231                                         std::string key = kv->substr(0, kvsep);
232                                         std::string value = kv->substr(kvsep + 1);
233
234                                         if (key == X_("channels")) {
235                                                 as.channels   = atoi(value);
236                                         } else if (key == X_("index")) {
237                                                 as.stream_id  = value;
238                                         } else if (key == X_("codec_long_name")) {
239                                                 if (!as.name.empty()) as.name += " ";
240                                                 as.name += value;
241                                         } else if (key == X_("codec_name")) {
242                                                 if (!as.name.empty()) as.name += " ";
243                                                 as.name += value;
244                                         } else if (key == X_("sample_fmt")) {
245                                                 if (!as.name.empty()) as.name += " ";
246                                                 as.name += "FMT:" + value;
247                                         } else if (key == X_("sample_rate")) {
248                                                 if (!as.name.empty()) as.name += " ";
249                                                 as.name += "SR:" + value;
250                                         }
251
252                                 }
253                                 m_audio.push_back(as);
254                         }
255                 }
256         }
257         /* end parse */
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 ardour";
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         snprintf(mds, len, "%s=\"%s\"", key.c_str(), v1.c_str());
320         return mds;
321 }
322
323 bool
324 TranscodeFfmpeg::encode (std::string outfile, std::string inf_a, std::string inf_v, TranscodeFfmpeg::FFSettings ffs, TranscodeFfmpeg::FFSettings meta, bool map)
325 {
326 #define MAX_FFMPEG_ENCODER_ARGS (100)
327         char **argp;
328         int a=0;
329
330         argp=(char**) calloc(MAX_FFMPEG_ENCODER_ARGS,sizeof(char*));
331         argp[a++] = strdup(ffmpeg_exe.c_str());
332         if (m_avoffset < 0 || m_avoffset > 0) {
333                 std::ostringstream osstream; osstream << m_avoffset;
334                 argp[a++] = strdup("-itsoffset");
335                 argp[a++] = strdup(osstream.str().c_str());
336         }
337         argp[a++] = strdup("-i");
338         argp[a++] = strdup(inf_v.c_str());
339
340         argp[a++] = strdup("-i");
341         argp[a++] = strdup(inf_a.c_str());
342
343         for(TranscodeFfmpeg::FFSettings::const_iterator it = ffs.begin(); it != ffs.end(); ++it) {
344                 argp[a++] = strdup(it->first.c_str());
345                 argp[a++] = strdup(it->second.c_str());
346         }
347         for(TranscodeFfmpeg::FFSettings::const_iterator it = meta.begin(); it != meta.end(); ++it) {
348                 argp[a++] = strdup("-metadata");
349                 argp[a++] = format_metadata(it->first.c_str(), it->second.c_str());
350         }
351         if (m_lead_in != 0 && m_lead_out != 0) {
352                 std::ostringstream osstream;
353                 argp[a++] = strdup("-vf");
354                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in;
355                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
356                 osstream << X_(" [pre]; ");
357                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out;
358                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
359                 osstream << X_(" [post]; ");
360                 osstream << X_("[pre] [in] [post] concat=n=3");
361                 argp[a++] = strdup(osstream.str().c_str());
362         } else if (m_lead_in != 0) {
363                 std::ostringstream osstream;
364                 argp[a++] = strdup("-vf");
365                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_in;
366                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
367                 osstream << X_(" [pre]; ");
368                 osstream << X_("[pre] [in] concat=n=2");
369                 argp[a++] = strdup(osstream.str().c_str());
370         } else if (m_lead_out != 0) {
371                 std::ostringstream osstream;
372                 argp[a++] = strdup("-vf");
373                 osstream << X_("color=c=black:s=") << m_width << X_("x") << m_height << X_(":d=") << m_lead_out;
374                 if (!m_sar.empty()) osstream << X_(":sar=") << m_sar;
375                 osstream << X_(" [post]; ");
376                 osstream << X_("[in] [post] concat=n=2");
377                 argp[a++] = strdup(osstream.str().c_str());
378         }
379
380         if (map) {
381                 std::ostringstream osstream;
382                 argp[a++] = strdup("-map");
383                 osstream << X_("0:") << m_videoidx;
384                 argp[a++] = strdup(osstream.str().c_str());
385                 argp[a++] = strdup("-map");
386                 argp[a++] = strdup("1:0");
387         }
388
389         argp[a++] = strdup("-y");
390         argp[a++] = strdup(outfile.c_str());
391         argp[a] = (char *)0;
392         assert(a<MAX_FFMPEG_ENCODER_ARGS);
393         /* Note: these are free()d in ~SystemExec */
394 #if 1 /* DEBUG */
395         if (debug_enable) { /* tentative debug mode */
396         printf("EXPORT ENCODE:\n");
397         for (int i=0; i< a; ++i) {
398           printf("%s ", argp[i]);
399         }
400         printf("\n");
401         }
402 #endif
403
404         ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
405         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
406         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
407         if (ffcmd->start(2)) {
408                 ffexit();
409                 return false;
410         }
411         return true;
412 }
413
414 bool
415 TranscodeFfmpeg::extract_audio (std::string outfile, ARDOUR::framecnt_t /*samplerate*/, unsigned int stream)
416 {
417         if (!probeok) return false;
418   if (stream >= m_audio.size()) return false;
419
420         char **argp;
421         int i = 0;
422
423         argp=(char**) calloc(15,sizeof(char*));
424         argp[i++] = strdup(ffmpeg_exe.c_str());
425         argp[i++] = strdup("-i");
426         argp[i++] = strdup(infile.c_str());
427 #if 0 /* ffmpeg write original samplerate, use a3/SRC to resample */
428         argp[i++] = strdup("-ar");
429         argp[i] = (char*) calloc(7,sizeof(char)); snprintf(argp[i++], 7, "%"PRId64, samplerate);
430 #endif
431         argp[i++] = strdup("-ac");
432         argp[i] = (char*) calloc(3,sizeof(char)); snprintf(argp[i++], 3, "%i", m_audio.at(stream).channels);
433         argp[i++] = strdup("-map");
434         argp[i] = (char*) calloc(8,sizeof(char)); snprintf(argp[i++], 8, "0:%s", m_audio.at(stream).stream_id.c_str());
435         argp[i++] = strdup("-vn");
436         argp[i++] = strdup("-acodec");
437         argp[i++] = strdup("pcm_f32le");
438         argp[i++] = strdup("-y");
439         argp[i++] = strdup(outfile.c_str());
440         argp[i++] = (char *)0;
441         /* Note: argp is free()d in ~SystemExec */
442 #if 1 /* DEBUG */
443         if (debug_enable) { /* tentative debug mode */
444         printf("EXTRACT AUDIO:\n");
445         for (int i=0; i< 14; ++i) {
446           printf("%s ", argp[i]);
447         }
448         printf("\n");
449         }
450 #endif
451
452         ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
453         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_a, this, _1 ,_2));
454         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
455         if (ffcmd->start(2)) {
456                 ffexit();
457                 return false;
458         }
459         return true;
460 }
461
462
463 bool
464 TranscodeFfmpeg::transcode (std::string outfile, const int outw, const int outh, const int kbitps)
465 {
466         if (!probeok) return false;
467
468         char **argp;
469         int bitrate = kbitps;
470         int width = outw;
471         int height = outh;
472
473         if (width < 1 || width > m_width) { width = m_width; } /* don't allow upscaling */
474         if (height < 1 || height > m_height) { height = floor(width / m_aspect); }
475
476         if (bitrate == 0) {
477                 const double bitperpixel = .7; /* avg quality */
478                 bitrate = floor(m_fps * width * height * bitperpixel / 10000.0);
479         } else {
480                 bitrate = bitrate / 10;
481         }
482         if (bitrate < 10)  bitrate = 10;
483         if (bitrate > 1000) bitrate = 1000;
484
485         argp=(char**) calloc(16,sizeof(char*));
486         argp[0] = strdup(ffmpeg_exe.c_str());
487         argp[1] = strdup("-i");
488         argp[2] = strdup(infile.c_str());
489         argp[3] = strdup("-b:v");
490         argp[4] = (char*) calloc(7,sizeof(char)); snprintf(argp[4], 7, "%i0k", bitrate);
491         argp[5] = strdup("-s");
492         argp[6] = (char*) calloc(10,sizeof(char)); snprintf(argp[6], 10, "%ix%i", width, height);
493         argp[7] = strdup("-y");
494         argp[8] = strdup("-vcodec");
495         argp[9] = strdup("mjpeg");
496         argp[10] = strdup("-an");
497         argp[11] = strdup("-intra");
498         argp[12] = strdup("-g");
499         argp[13] = strdup("1");
500         argp[14] = strdup(outfile.c_str());
501         argp[15] = (char *)0;
502         /* Note: these are free()d in ~SystemExec */
503 #if 1 /* DEBUG */
504         if (debug_enable) { /* tentative debug mode */
505         printf("TRANSCODE VIDEO:\n");
506         for (int i=0; i< 15; ++i) {
507           printf("%s ", argp[i]);
508         }
509         printf("\n");
510         }
511 #endif
512         ffcmd = new ARDOUR::SystemExec(ffmpeg_exe, argp);
513         ffcmd->ReadStdout.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffmpegparse_v, this, _1 ,_2));
514         ffcmd->Terminated.connect_same_thread (*this, boost::bind (&TranscodeFfmpeg::ffexit, this));
515         if (ffcmd->start(2)) {
516                 ffexit();
517                 return false;
518         }
519         return true;
520 }
521
522 void
523 TranscodeFfmpeg::cancel ()
524 {
525         if (!ffcmd || !ffcmd->is_running()) { return;}
526         ffcmd->write_to_stdin("q");
527 #ifdef PLATFORM_WINDOWS
528         Sleep(1000);
529 #else
530         sleep (1);
531 #endif
532         if (ffcmd) {
533           ffcmd->terminate();
534         }
535 }
536
537 void
538 TranscodeFfmpeg::ffexit ()
539 {
540         delete ffcmd;
541         ffcmd=0;
542         Finished(); /* EMIT SIGNAL */
543 }
544
545 void
546 TranscodeFfmpeg::ffprobeparse (std::string d, size_t /* s */)
547 {
548         ffoutput+=d;
549 }
550
551 void
552 TranscodeFfmpeg::ffmpegparse_a (std::string d, size_t /* s */)
553 {
554         const char *t;
555         int h,m,s; char f[7];
556         ARDOUR::framecnt_t p = -1;
557
558         if (!(t=strstr(d.c_str(), "time="))) { return; }
559
560         if (sscanf(t+5, "%d:%d:%d.%s",&h,&m,&s,f) == 4) {
561                 p = (ARDOUR::framecnt_t) floor( 100.0 * (
562                       h * 3600.0
563                     + m * 60.0
564                     + s * 1.0
565                     + atoi(f) / pow((double)10, (int)strlen(f))
566                 ));
567                 p = p * m_fps / 100.0;
568                 if (p > m_duration ) { p = m_duration; }
569                 Progress(p, m_duration); /* EMIT SIGNAL */
570         } else {
571                 Progress(0, 0); /* EMIT SIGNAL */
572         }
573 }
574
575 void
576 TranscodeFfmpeg::ffmpegparse_v (std::string d, size_t /* s */)
577 {
578         if (strstr(d.c_str(), "ERROR") || strstr(d.c_str(), "Error") || strstr(d.c_str(), "error")) {
579                 warning << "ffmpeg-error: " << d << endmsg;
580         }
581         if (strncmp(d.c_str(), "frame=",6)) {
582 #if 1 /* DEBUG */
583                 if (debug_enable) {
584                         d.erase(d.find_last_not_of(" \t\r\n") + 1);
585                   printf("ffmpeg: '%s'\n", d.c_str());
586                 }
587 #endif
588                 Progress(0, 0); /* EMIT SIGNAL */
589                 return;
590         }
591         ARDOUR::framecnt_t f = atol(d.substr(6));
592         if (f == 0) {
593                 Progress(0, 0); /* EMIT SIGNAL */
594         } else {
595                 Progress(f, m_duration); /* EMIT SIGNAL */
596         }
597 }