0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

encoding: use --start for ratios, etc.

Note: this currently only works for formats without pts resets. Other
formats will ignore this code.
This commit is contained in:
Rudolf Polzer 2013-06-20 12:15:36 +02:00
parent 1e58ccaaf0
commit 7e88dca2db
2 changed files with 24 additions and 7 deletions

View File

@ -304,7 +304,7 @@ double get_time_length(struct MPContext *mpctx);
double get_start_time(struct MPContext *mpctx);
double get_current_time(struct MPContext *mpctx);
int get_percent_pos(struct MPContext *mpctx);
double get_current_pos_ratio(struct MPContext *mpctx);
double get_current_pos_ratio(struct MPContext *mpctx, bool use_range);
int get_current_chapter(struct MPContext *mpctx);
char *chapter_display_name(struct MPContext *mpctx, int chapter);
char *chapter_name(struct MPContext *mpctx, int chapter);

View File

@ -1229,8 +1229,7 @@ static void print_status(struct MPContext *mpctx)
}
#ifdef CONFIG_ENCODING
double position = get_current_pos_ratio(mpctx);
// TODO rescale this to take --start, --end, --length, --frames into account
double position = get_current_pos_ratio(mpctx, true);
char lavcbuf[80];
if (encode_lavc_getstatus(mpctx->encode_lavc_ctx, lavcbuf, sizeof(lavcbuf),
position) >= 0)
@ -1568,7 +1567,7 @@ static void add_seek_osd_messages(struct MPContext *mpctx)
{
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) {
set_osd_bar(mpctx, OSD_BAR_SEEK, "Position", 0, 1,
av_clipf(get_current_pos_ratio(mpctx), 0, 1));
av_clipf(get_current_pos_ratio(mpctx, false), 0, 1));
set_osd_bar_chapters(mpctx, OSD_BAR_SEEK);
}
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) {
@ -1609,7 +1608,7 @@ static void update_osd_msg(struct MPContext *mpctx)
add_seek_osd_messages(mpctx);
update_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1,
av_clipf(get_current_pos_ratio(mpctx), 0, 1));
av_clipf(get_current_pos_ratio(mpctx, false), 0, 1));
// Look if we have a msg
mp_osd_msg_t *msg = get_osd_msg(mpctx);
@ -3138,7 +3137,7 @@ double get_start_time(struct MPContext *mpctx)
}
// Return playback position in 0.0-1.0 ratio, or -1 if unknown.
double get_current_pos_ratio(struct MPContext *mpctx)
double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
{
struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
@ -3146,6 +3145,19 @@ double get_current_pos_ratio(struct MPContext *mpctx)
double ans = -1;
double start = get_start_time(mpctx);
double len = get_time_length(mpctx);
if (use_range) {
double startpos = rel_time_to_abs(mpctx, mpctx->opts.play_start,
MP_NOPTS_VALUE);
double endpos = get_play_end_pts(mpctx);
if (endpos == MP_NOPTS_VALUE || endpos > start + len)
endpos = start + len;
if (startpos == MP_NOPTS_VALUE || startpos < start)
startpos = start;
if (endpos < startpos)
endpos = startpos;
start = startpos;
len = endpos - startpos;
}
double pos = get_current_time(mpctx);
if (len > 0 && !demuxer->ts_resets_possible) {
ans = av_clipf((pos - start) / len, 0, 1);
@ -3156,12 +3168,17 @@ double get_current_pos_ratio(struct MPContext *mpctx)
if (len > 0)
ans = av_clipf((double)(pos - demuxer->movi_start) / len, 0, 1);
}
if (use_range) {
if (mpctx->opts.play_frames > 0)
ans = max(ans, 1.0 -
mpctx->max_frames / (double) mpctx->opts.play_frames);
}
return ans;
}
int get_percent_pos(struct MPContext *mpctx)
{
return av_clip(get_current_pos_ratio(mpctx) * 100, 0, 100);
return av_clip(get_current_pos_ratio(mpctx, false) * 100, 0, 100);
}
// -2 is no chapters, -1 is before first chapter