| @@ -237,7 +237,7 @@ static void sub2video_push_ref(InputStream *ist, int64_t pts) · 236 unmodified lines |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | | −void sub2video_update(InputStream *ist, AVSubtitle *sub) |
| 240 | +void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub) |
| 241 | 241 | { |
| 242 | 242 | AVFrame *frame = ist->sub2video.frame; |
| 243 | 243 | int8_t *dst; |
| @@ -254,7 +254,12 @@ void sub2video_update(InputStream *ist, AVSubtitle *sub) · 10 unmodified lines |
| 254 | 254 | AV_TIME_BASE_Q, ist->st->time_base); |
| 255 | 255 | num_rects = sub->num_rects; |
| 256 | 256 | } else { |
| 257 | | − pts = ist->sub2video.end_pts; |
| 257 | + /* If we are initializing the system, utilize current heartbeat |
| 258 | + PTS as the start time, and show until the following subpicture |
| 259 | + is received. Otherwise, utilize the previous subpicture's end time |
| 260 | + as the fall-back value. */ |
| 261 | + pts = ist->sub2video.initialize ? |
| 262 | + heartbeat_pts : ist->sub2video.end_pts; |
| 258 | 263 | end_pts = INT64_MAX; |
| 259 | 264 | num_rects = 0; |
| 260 | 265 | } |
| @@ -269,6 +274,7 @@ void sub2video_update(InputStream *ist, AVSubtitle *sub) · 8 unmodified lines |
| 269 | 274 | sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]); |
| 270 | 275 | sub2video_push_ref(ist, pts); |
| 271 | 276 | ist->sub2video.end_pts = end_pts; |
| 277 | + ist->sub2video.initialize = 0; |
| 272 | 278 | } |
| 273 | 279 | |
| 274 | 280 | static void sub2video_heartbeat(InputStream *ist, int64_t pts) |
| @@ -291,9 +297,11 @@ static void sub2video_heartbeat(InputStream *ist, int64_t pts) · 16 unmodified lines |
| 291 | 297 | /* do not send the heartbeat frame if the subtitle is already ahead */ |
| 292 | 298 | if (pts2 <= ist2->sub2video.last_pts) |
| 293 | 299 | continue; |
| 294 | | − if (pts2 >= ist2->sub2video.end_pts || |
| 295 | | − (!ist2->sub2video.frame->data[0] && ist2->sub2video.end_pts < INT64_MAX)) |
| 296 | | − sub2video_update(ist2, NULL); |
| 300 | + if (pts2 >= ist2->sub2video.end_pts || ist2->sub2video.initialize) |
| 301 | + /* if we have hit the end of the current displayed subpicture, |
| 302 | + or if we need to initialize the system, update the |
| 303 | + overlayed subpicture and its start/end times */ |
| 304 | + sub2video_update(ist2, pts2 + 1, NULL); |
| 297 | 305 | for (j = 0, nb_reqs = 0; j < ist2->nb_filters; j++) |
| 298 | 306 | nb_reqs += av_buffersrc_get_nb_failed_requests(ist2->filters[j]->filter); |
| 299 | 307 | if (nb_reqs) |
| @@ -307,7 +315,7 @@ static void sub2video_flush(InputStream *ist) · 7 unmodified lines |
| 307 | 315 | int ret; |
| 308 | 316 | |
| 309 | 317 | if (ist->sub2video.end_pts < INT64_MAX) |
| 310 | | − sub2video_update(ist, NULL); |
| 318 | + sub2video_update(ist, INT64_MAX, NULL); |
| 311 | 319 | for (i = 0; i < ist->nb_filters; i++) { |
| 312 | 320 | ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL); |
| 313 | 321 | if (ret != AVERROR_EOF && ret < 0) |
| @@ -2507,7 +2515,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, · 2193 unmodified lines |
| 2507 | 2515 | return ret; |
| 2508 | 2516 | |
| 2509 | 2517 | if (ist->sub2video.frame) { |
| 2510 | | − sub2video_update(ist, &subtitle); |
| 2518 | + sub2video_update(ist, INT64_MIN, &subtitle); |
| 2511 | 2519 | } else if (ist->nb_filters) { |
| 2512 | 2520 | if (!ist->sub2video.sub_queue) |
| 2513 | 2521 | ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle)); |