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