summaryrefslogtreecommitdiff
path: root/avplay.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-09-04 20:30:28 +0200
committerAnton Khirnov <anton@khirnov.net>2014-02-10 11:23:01 +0100
commitb36bc81ccaa2fc85dc4bae7dc546c71e8833573d (patch)
treed0356d471eebbaa527decf124256bebc318ca891 /avplay.c
parentf548f9f9e7a2a08c780e88dac63b9d5d2c55efb0 (diff)
avplay: add support for seeking to chapter marks
Diffstat (limited to 'avplay.c')
-rw-r--r--avplay.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/avplay.c b/avplay.c
index 432db97823..b70ee54c7b 100644
--- a/avplay.c
+++ b/avplay.c
@@ -2601,6 +2601,33 @@ static void toggle_audio_display(void)
}
}
+static void seek_chapter(VideoState *is, int incr)
+{
+ int64_t pos = get_master_clock(is) * AV_TIME_BASE;
+ int i;
+
+ if (!is->ic->nb_chapters)
+ return;
+
+ /* find the current chapter */
+ for (i = 0; i < is->ic->nb_chapters; i++) {
+ AVChapter *ch = is->ic->chapters[i];
+ if (av_compare_ts(pos, AV_TIME_BASE_Q, ch->start, ch->time_base) < 0) {
+ i--;
+ break;
+ }
+ }
+
+ i += incr;
+ i = FFMAX(i, 0);
+ if (i >= is->ic->nb_chapters)
+ return;
+
+ av_log(NULL, AV_LOG_VERBOSE, "Seeking to chapter %d.\n", i);
+ stream_seek(is, av_rescale_q(is->ic->chapters[i]->start, is->ic->chapters[i]->time_base,
+ AV_TIME_BASE_Q), 0, 0);
+}
+
/* handle an event sent by the GUI */
static void event_loop(void)
{
@@ -2646,6 +2673,12 @@ static void event_loop(void)
case SDLK_w:
toggle_audio_display();
break;
+ case SDLK_PAGEUP:
+ seek_chapter(cur_stream, 1);
+ break;
+ case SDLK_PAGEDOWN:
+ seek_chapter(cur_stream, -1);
+ break;
case SDLK_LEFT:
incr = -10.0;
goto do_seek;