diff options
author | wm4 <wm4@nowhere> | 2012-11-15 18:49:17 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-11-16 21:21:15 +0100 |
commit | 51503a05778290edc0bb77276b67d33ca0e10783 (patch) | |
tree | 4745d8d476e788fe0a36c1151dd28118cac0a911 /core/mplayer.c | |
parent | b4b86e9286ba175ba0da4d19e165660bed7002e4 (diff) | |
download | mpv-51503a05778290edc0bb77276b67d33ca0e10783.tar.bz2 mpv-51503a05778290edc0bb77276b67d33ca0e10783.tar.xz |
options: rename -ss and -endpos, allow relative times
Rename the -ss option to -start, and -endpos to -length. Add a -end
option. The -end option always specifies an absolute end time, as
opposed to -endpos/-length.
All these options (--start, --end, --length) now accept relative times.
Percent positions (e.g. "--start=30%") are interpreted as fractions of
the file duration. Negative times (e.g. "--start=-1:00) are interpreted
relative to the end of the file. Chapters (e.g. "--start=#3") yield the
chapter's time position.
The chapter support might be able to replace --chapter completely, but
for now I am not sure how well this works out with e.g. DVDs and BDs,
and a separate --chapter option is useful interface-wise.
Diffstat (limited to 'core/mplayer.c')
-rw-r--r-- | core/mplayer.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/core/mplayer.c b/core/mplayer.c index 2923d15374..3d38330c0a 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -165,7 +165,7 @@ static const char help_text[] = _( "Usage: mpv [options] [url|path/]filename\n" "\n" "Basic options: (complete list in the man page)\n" -" --ss=<position> seek to given (seconds or hh:mm:ss) position\n" +" --start=<time> seek to given (percent, seconds, or hh:mm:ss) position\n" " --no-audio do not play sound\n" " --no-video do not play video\n" " --fs fullscreen playback\n" @@ -208,8 +208,6 @@ static int drop_frame_cnt; // total number of dropped frames static int64_t seek_to_byte; static double step_sec; -static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 }; - // codecs: char **audio_codec_list; // override audio codec char **video_codec_list; // override video codec @@ -258,6 +256,39 @@ static float get_relative_time(struct MPContext *mpctx) return delta * 0.000001; } +static double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t, + double fallback_time) +{ + double length = get_time_length(mpctx); + switch (t.type) { + case REL_TIME_ABSOLUTE: + return t.pos; + case REL_TIME_NEGATIVE: + if (length != 0) + return FFMAX(length - t.pos, 0.0); + break; + case REL_TIME_PERCENT: + if (length != 0) + return length * (t.pos / 100.0); + break; + } + return fallback_time; +} + +static double get_play_end_pts(struct MPContext *mpctx) +{ + struct MPOpts *opts = &mpctx->opts; + if (opts->play_end.type) { + return rel_time_to_abs(mpctx, opts->play_end, MP_NOPTS_VALUE); + } else if (opts->play_length.type) { + double start = rel_time_to_abs(mpctx, opts->play_start, -1); + double length = rel_time_to_abs(mpctx, opts->play_length, -1); + if (start != -1 && length != -1) + return start + length; + } + return MP_NOPTS_VALUE; +} + static void print_stream(struct MPContext *mpctx, struct track *t, int id) { struct sh_stream *s = t->stream; @@ -1138,17 +1169,20 @@ static void print_status(struct MPContext *mpctx, double a_pos, bool at_frame) } #ifdef CONFIG_ENCODING - float position = (get_current_time(mpctx) - opts->seek_to_sec) / - (get_time_length(mpctx) - opts->seek_to_sec); - if (end_at.type == END_AT_TIME) - position = max(position, (get_current_time(mpctx) - opts->seek_to_sec) - / (end_at.pos - opts->seek_to_sec)); + double startpos = rel_time_to_abs(mpctx, opts->play_start, 0); + double endpos = rel_time_to_abs(mpctx, opts->play_end, -1); + float position = (get_current_time(mpctx) - startpos) / + (get_time_length(mpctx) - startpos); + if (endpos != -1) + position = max(position, (get_current_time(mpctx) - startpos) + / (endpos - startpos)); if (play_n_frames_mf) position = max(position, 1.0 - play_n_frames / (double) play_n_frames_mf); char lavcbuf[80]; if (encode_lavc_getstatus(mpctx->encode_lavc_ctx, lavcbuf, sizeof(lavcbuf), - position, get_current_time(mpctx) - opts->seek_to_sec) >= 0) { + position, get_current_time(mpctx) - startpos) >= 0) + { // encoding stats saddf(line, width, "%s ", lavcbuf); } else @@ -2970,7 +3004,7 @@ static void run_playloop(struct MPContext *mpctx) struct MPOpts *opts = &mpctx->opts; bool full_audio_buffers = false; bool audio_left = false, video_left = false; - double endpts = end_at.type == END_AT_TIME ? end_at.pos : MP_NOPTS_VALUE; + double endpts = get_play_end_pts(mpctx); bool end_is_chapter = false; double sleeptime = WAKEUP_PERIOD; bool was_restart = mpctx->restart_playback; @@ -3325,7 +3359,7 @@ static void run_playloop(struct MPContext *mpctx) mpctx->seek = (struct seek_params) {0}; struct seek_params sp = { .type = MPSEEK_ABSOLUTE, - .amount = opts->seek_to_sec, + .amount = rel_time_to_abs(mpctx, opts->play_start, 0), .exact = 1, }; if (seek(mpctx, sp, false) != 0) { @@ -3963,10 +3997,10 @@ goto_enable_cache: mpctx->last_chapter_seek = -2; // If there's a timeline force an absolute seek to initialize state - if (opts->seek_to_sec || mpctx->timeline) { - queue_seek(mpctx, MPSEEK_ABSOLUTE, opts->seek_to_sec, 0); + double startpos = rel_time_to_abs(mpctx, opts->play_start, -1); + if (startpos != -1 || mpctx->timeline) { + queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, 0); seek(mpctx, mpctx->seek, false); - end_at.pos += opts->seek_to_sec; } if (opts->chapterrange[0] > 0) { double pts; @@ -3977,12 +4011,6 @@ goto_enable_cache: } } - if (end_at.type == END_AT_SIZE) { - mp_tmsg(MSGT_CPLAYER, MSGL_WARN, - "Option -endpos in mpv does not yet support size units.\n"); - end_at.type = END_AT_NONE; - } - mpctx->seek = (struct seek_params){ 0 }; get_relative_time(mpctx); // reset current delta // Make sure VO knows current pause state |