Skip to content

Commit fa48d4a

Browse files
committed
libavfilter/vf_subtitles: also seek in the input to optimize processing
1 parent b4c13e4 commit fa48d4a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

libavfilter/vf_subtitles.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
307307
AVStream *st;
308308
AVPacket pkt;
309309
AssContext *ass = ctx->priv;
310+
int64_t timestamp;
310311

311312
/* Init libass */
312313
ret = init(ctx);
@@ -445,6 +446,16 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
445446
ass_process_codec_private(ass->track,
446447
dec_ctx->subtitle_header,
447448
dec_ctx->subtitle_header_size);
449+
450+
/* Skip the parts that won’t be used anyway */
451+
timestamp = av_rescale(ass->start_time, st->time_base.den,
452+
AV_TIME_BASE * (int64_t) st->time_base.num);
453+
ret = av_seek_frame(fmt, sid, timestamp, 0);
454+
if (ret < 0) {
455+
av_log(ctx, AV_LOG_WARNING, "Error seeking: %s (ignored)\n",
456+
av_err2str(ret));
457+
}
458+
448459
av_init_packet(&pkt);
449460
pkt.data = NULL;
450461
pkt.size = 0;

0 commit comments

Comments
 (0)