Skip to content

Commit 4e92a5e

Browse files
committed
melt: print progress at the end
1 parent 2767b4b commit 4e92a5e

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

‎src/melt/melt.c‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,34 @@ static void event_handling(mlt_producer producer, mlt_consumer consumer)
420420

421421
#endif
422422

423+
void report_progress(
424+
mlt_producer producer, int progress, int *last_position, mlt_consumer consumer, int silent)
425+
{
426+
if (!silent && mlt_properties_get_int(MLT_PRODUCER_PROPERTIES(producer), "stats_off") == 0) {
427+
if (progress) {
428+
int current_position = mlt_producer_position(producer);
429+
if (current_position > *last_position) {
430+
fprintf(stderr,
431+
"Current Frame: %10d, percentage: %10d%c",
432+
current_position,
433+
100 * current_position / mlt_producer_get_playtime(producer),
434+
progress == 2 ? '\n' : '\r');
435+
*last_position = current_position;
436+
}
437+
} else {
438+
fprintf(stderr, "Current Position: %10d\r", (int) mlt_consumer_position(consumer));
439+
}
440+
fflush(stderr);
441+
}
442+
}
443+
423444
static void transport(mlt_producer producer, mlt_consumer consumer)
424445
{
425446
mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer);
426447
int silent = mlt_properties_get_int(MLT_CONSUMER_PROPERTIES(consumer), "silent");
427448
int progress = mlt_properties_get_int(MLT_CONSUMER_PROPERTIES(consumer), "progress");
428449
int is_getc = mlt_properties_get_int(MLT_CONSUMER_PROPERTIES(consumer), "melt_getc");
429450
struct timespec tm = {0, 40000000};
430-
int total_length = mlt_producer_get_playtime(producer);
431451
int last_position = 0;
432452

433453
if (mlt_properties_get_int(properties, "done") == 0 && !mlt_consumer_is_stopped(consumer)) {
@@ -473,29 +493,13 @@ static void transport(mlt_producer producer, mlt_consumer consumer)
473493
event_handling(producer, consumer);
474494
#endif
475495

476-
if (!silent && mlt_properties_get_int(properties, "stats_off") == 0) {
477-
if (progress) {
478-
int current_position = mlt_producer_position(producer);
479-
if (current_position > last_position) {
480-
fprintf(stderr,
481-
"Current Frame: %10d, percentage: %10d%c",
482-
current_position,
483-
100 * current_position / total_length,
484-
progress == 2 ? '\n' : '\r');
485-
last_position = current_position;
486-
}
487-
} else {
488-
fprintf(stderr,
489-
"Current Position: %10d\r",
490-
(int) mlt_consumer_position(consumer));
491-
}
492-
fflush(stderr);
493-
}
496+
report_progress(producer, progress, &last_position, consumer, silent);
494497

495498
if (silent || progress)
496499
nanosleep(&tm, NULL);
497500
}
498501

502+
report_progress(producer, progress, &last_position, consumer, silent);
499503
if (!silent)
500504
fprintf(stderr, "\n");
501505
}

0 commit comments

Comments
 (0)