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