mirror of https://github.com/mpv-player/mpv
player: use virtual time for --audio-file with ordered chapters
Apparently users prefer this behavior. It was used for subtitles too, so move the code to calculate the video offset into a separate function. Seeking also needs to be fixed. Fixes #1018.
This commit is contained in:
parent
318e8da250
commit
fa7c421588
|
@ -255,7 +255,8 @@ double written_audio_pts(struct MPContext *mpctx)
|
|||
// to get the length in original units without speedup or slowdown
|
||||
a_pts -= buffered_output * mpctx->opts->playback_speed;
|
||||
|
||||
return a_pts + mpctx->video_offset;
|
||||
return a_pts +
|
||||
get_track_video_offset(mpctx, mpctx->current_track[0][STREAM_AUDIO]);
|
||||
}
|
||||
|
||||
// Return pts value corresponding to currently playing audio.
|
||||
|
|
|
@ -421,6 +421,7 @@ void mp_print_version(struct mp_log *log, int always);
|
|||
// misc.c
|
||||
double get_start_time(struct MPContext *mpctx);
|
||||
double get_main_demux_pts(struct MPContext *mpctx);
|
||||
double get_track_video_offset(struct MPContext *mpctx, struct track *track);
|
||||
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t);
|
||||
double get_play_end_pts(struct MPContext *mpctx);
|
||||
double get_relative_time(struct MPContext *mpctx);
|
||||
|
|
|
@ -113,6 +113,16 @@ double get_start_time(struct MPContext *mpctx)
|
|||
return mpctx->demuxer ? mpctx->demuxer->start_time : 0;
|
||||
}
|
||||
|
||||
// Get the offset from the given track to the video.
|
||||
double get_track_video_offset(struct MPContext *mpctx, struct track *track)
|
||||
{
|
||||
if (track && track->under_timeline)
|
||||
return mpctx->video_offset;
|
||||
if (track && track->is_external)
|
||||
return get_start_time(mpctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
float mp_get_cache_percent(struct MPContext *mpctx)
|
||||
{
|
||||
if (mpctx->demuxer) {
|
||||
|
|
|
@ -236,10 +236,11 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
|
|||
if (track->selected && track->is_external && track->demuxer) {
|
||||
double main_new_pos;
|
||||
if (seek.type == MPSEEK_ABSOLUTE) {
|
||||
main_new_pos = seek.amount - mpctx->video_offset;
|
||||
main_new_pos = seek.amount;
|
||||
} else {
|
||||
main_new_pos = get_main_demux_pts(mpctx);
|
||||
}
|
||||
main_new_pos -= get_track_video_offset(mpctx, track);
|
||||
demux_seek(track->demuxer, main_new_pos, SEEK_ABSOLUTE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,14 +106,7 @@ static void update_subtitle(struct MPContext *mpctx, int order)
|
|||
|
||||
struct osd_sub_state state;
|
||||
osd_get_sub(mpctx->osd, obj, &state);
|
||||
|
||||
state.video_offset = 0;
|
||||
if (track->under_timeline) {
|
||||
state.video_offset += mpctx->video_offset;
|
||||
} else if (track->is_external) {
|
||||
state.video_offset += get_start_time(mpctx);
|
||||
};
|
||||
|
||||
state.video_offset = get_track_video_offset(mpctx, track);
|
||||
osd_set_sub(mpctx->osd, obj, &state);
|
||||
|
||||
double refpts_s = mpctx->playback_pts - state.video_offset;
|
||||
|
|
Loading…
Reference in New Issue