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