summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRudolf Polzer <divverent@xonotic.org>2013-06-20 12:15:36 +0200
committerRudolf Polzer <divverent@xonotic.org>2013-06-20 12:15:36 +0200
commit7e88dca2db56f97bcd100c53bfd47a5d677c94cd (patch)
tree67536ca983fe2ccc7b2afb77bceac77b11bb6012 /core
parent1e58ccaaf07bd360aebe99ec29e39a2b0b7e4d99 (diff)
downloadmpv-7e88dca2db56f97bcd100c53bfd47a5d677c94cd.tar.bz2
mpv-7e88dca2db56f97bcd100c53bfd47a5d677c94cd.tar.xz
encoding: use --start for ratios, etc.
Note: this currently only works for formats without pts resets. Other formats will ignore this code.
Diffstat (limited to 'core')
-rw-r--r--core/mp_core.h2
-rw-r--r--core/mplayer.c29
2 files changed, 24 insertions, 7 deletions
diff --git a/core/mp_core.h b/core/mp_core.h
index a327e43822..98a92cbea4 100644
--- a/core/mp_core.h
+++ b/core/mp_core.h
@@ -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);
diff --git a/core/mplayer.c b/core/mplayer.c
index 17f1b83cb5..d28b5fdc4c 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -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