mirror of https://github.com/mpv-player/mpv
subtitles/demux: store duration instead of endpts in demux packets
This commit is contained in:
parent
e990fb2ffe
commit
8e7dae173d
11
av_sub.c
11
av_sub.c
|
@ -36,7 +36,7 @@ void reset_avsub(struct sh_sub *sh)
|
|||
* \return < 0 on error, > 0 if further processing is needed
|
||||
*/
|
||||
int decode_avsub(struct sh_sub *sh, uint8_t *data, int size,
|
||||
double pts, double endpts)
|
||||
double pts, double duration)
|
||||
{
|
||||
AVCodecContext *ctx = sh->context;
|
||||
enum CodecID cid = CODEC_ID_NONE;
|
||||
|
@ -58,8 +58,8 @@ int decode_avsub(struct sh_sub *sh, uint8_t *data, int size,
|
|||
pkt.data = data;
|
||||
pkt.size = size;
|
||||
pkt.pts = pts * 1000;
|
||||
if (pts != MP_NOPTS_VALUE && endpts != MP_NOPTS_VALUE)
|
||||
pkt.convergence_duration = (endpts - pts) * 1000;
|
||||
if (duration >= 0)
|
||||
pkt.convergence_duration = duration * 1000;
|
||||
if (!ctx) {
|
||||
AVCodec *sub_codec;
|
||||
avcodec_init();
|
||||
|
@ -79,9 +79,12 @@ int decode_avsub(struct sh_sub *sh, uint8_t *data, int size,
|
|||
return res;
|
||||
if (pts != MP_NOPTS_VALUE) {
|
||||
if (sub.end_display_time > sub.start_display_time)
|
||||
endpts = pts + sub.end_display_time / 1000.0;
|
||||
duration = (sub.end_display_time - sub.start_display_time) / 1000.0;
|
||||
pts += sub.start_display_time / 1000.0;
|
||||
}
|
||||
double endpts = MP_NOPTS_VALUE;
|
||||
if (pts != MP_NOPTS_VALUE && duration >= 0)
|
||||
endpts = pts + duration;
|
||||
if (got_sub && vo_spudec && sub.num_rects == 0)
|
||||
spudec_set_paletted(vo_spudec, NULL, 0, NULL, 0, 0, 0, 0, pts, endpts);
|
||||
if (got_sub && sub.num_rects > 0) {
|
||||
|
|
|
@ -756,11 +756,11 @@ static int demux_lavf_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){
|
|||
if(ts != AV_NOPTS_VALUE){
|
||||
dp->pts = ts * av_q2d(priv->avfc->streams[id]->time_base);
|
||||
priv->last_pts= dp->pts * AV_TIME_BASE;
|
||||
// always set endpts for subtitles, even if PKT_FLAG_KEY is not set,
|
||||
// always set duration for subtitles, even if PKT_FLAG_KEY is not set,
|
||||
// otherwise they will stay on screen to long if e.g. ASS is demuxed from mkv
|
||||
if((ds == demux->sub || (pkt.flags & PKT_FLAG_KEY)) &&
|
||||
pkt.convergence_duration > 0)
|
||||
dp->endpts = dp->pts + pkt.convergence_duration * av_q2d(priv->avfc->streams[id]->time_base);
|
||||
dp->duration = pkt.convergence_duration * av_q2d(priv->avfc->streams[id]->time_base);
|
||||
}
|
||||
dp->pos=demux->filepos;
|
||||
dp->flags= !!(pkt.flags&PKT_FLAG_KEY);
|
||||
|
|
|
@ -1884,7 +1884,7 @@ static void handle_subtitles(demuxer_t *demuxer, mkv_track_t *track,
|
|||
dp = new_demux_packet(size);
|
||||
memcpy(dp->buffer, block, size);
|
||||
dp->pts = timecode / 1000.0;
|
||||
dp->endpts = (timecode + block_duration) / 1000.0;
|
||||
dp->duration = block_duration / 1000.0;
|
||||
ds_add_packet(demuxer->sub, dp);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ enum timestamp_type {
|
|||
typedef struct demux_packet {
|
||||
int len;
|
||||
double pts;
|
||||
double endpts;
|
||||
double duration;
|
||||
double stream_pts;
|
||||
off_t pos; // position in index (AVI) or file (MPG)
|
||||
unsigned char* buffer;
|
||||
|
@ -289,7 +289,7 @@ static inline demux_packet_t* new_demux_packet(int len){
|
|||
dp->len=len;
|
||||
dp->next=NULL;
|
||||
dp->pts=MP_NOPTS_VALUE;
|
||||
dp->endpts=MP_NOPTS_VALUE;
|
||||
dp->duration = -1;
|
||||
dp->stream_pts = MP_NOPTS_VALUE;
|
||||
dp->pos=0;
|
||||
dp->flags=0;
|
||||
|
|
12
mplayer.c
12
mplayer.c
|
@ -1927,11 +1927,11 @@ void update_subtitles(struct MPContext *mpctx, double refpts,
|
|||
if (d_sub->non_interleaved && subpts > curpts + 1)
|
||||
break;
|
||||
}
|
||||
double endpts = d_sub->first->endpts + sub_offset;
|
||||
double duration = d_sub->first->duration;
|
||||
len = ds_get_packet_sub(d_sub, &packet);
|
||||
if (is_av_sub(type)) {
|
||||
#ifdef CONFIG_FFMPEG
|
||||
decode_avsub(sh_sub, packet, len, subpts, endpts);
|
||||
decode_avsub(sh_sub, packet, len, subpts, duration);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
@ -1957,14 +1957,11 @@ void update_subtitles(struct MPContext *mpctx, double refpts,
|
|||
continue;
|
||||
}
|
||||
if (sh_sub && sh_sub->active) {
|
||||
double duration = -1;
|
||||
if (endpts != MP_NOPTS_VALUE)
|
||||
duration = endpts - subpts;
|
||||
sub_decode(sh_sub, mpctx->osd, packet, len, subpts, duration);
|
||||
continue;
|
||||
}
|
||||
if (subpts != MP_NOPTS_VALUE) {
|
||||
if (endpts == MP_NOPTS_VALUE)
|
||||
if (duration < 0)
|
||||
sub_clear_text(&subs, MP_NOPTS_VALUE);
|
||||
if (type == 'a') { // ssa/ass subs without libass => convert to plaintext
|
||||
int i;
|
||||
|
@ -1977,6 +1974,9 @@ void update_subtitles(struct MPContext *mpctx, double refpts,
|
|||
len -= p - packet;
|
||||
packet = p;
|
||||
}
|
||||
double endpts = MP_NOPTS_VALUE;
|
||||
if (subpts != MP_NOPTS_VALUE && duration >= 0)
|
||||
endpts = subpts + duration;
|
||||
sub_add_text(&subs, packet, len, endpts);
|
||||
set_osd_subtitle(mpctx, &subs);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue