Skip to content

Commit be98b35

Browse files
llyyrkasper93
authored andcommitted
player/misc: show percentage progress for --stream-dump
Also use format modifiers instead of casting and fix type for `pos`
1 parent ee0f701 commit be98b35

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

player/misc.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ int stream_dump(struct MPContext *mpctx, const char *source_filename)
278278
goto done;
279279

280280
int64_t size = stream_get_size(stream);
281+
int64_t start_pos = stream->pos;
281282

282283
FILE *dest = fopen(filename, "wb");
283284
if (!dest) {
@@ -289,9 +290,15 @@ int stream_dump(struct MPContext *mpctx, const char *source_filename)
289290

290291
while (mpctx->stop_play == KEEP_PLAYING && ok) {
291292
if (!opts->quiet && ((stream->pos / (1024 * 1024)) % 2) == 1) {
292-
uint64_t pos = stream->pos;
293-
MP_MSG(mpctx, MSGL_STATUS, "Dumping %lld/%lld...",
294-
(long long int)pos, (long long int)size);
293+
int64_t pos = stream->pos;
294+
if (size > 0 && pos >= start_pos) {
295+
double percent = 100.0 * (pos - start_pos) / (size - start_pos);
296+
MP_MSG(mpctx, MSGL_STATUS, "Dumping %" PRId64 "/%" PRId64 " (%.2f%%)...",
297+
pos, size, percent);
298+
} else {
299+
MP_MSG(mpctx, MSGL_STATUS, "Dumping %" PRId64 "/%" PRId64 "...",
300+
pos, size);
301+
}
295302
}
296303
uint8_t buf[4096];
297304
int len = stream_read(stream, buf, sizeof(buf));

0 commit comments

Comments
 (0)