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