History

ffmpeg: explicitly handle sub2video subpicture initialization

Each time the sub2video structure is initialized, the sub2video subpicture is initialized together with the first received heartbeat. The heartbeat's PTS is utilized as the subpicture start time. Additionally, add some documentation on the stages.

Jan Ekström committed 7 years ago

Commit 7ba3ea21 parent 39fbd063 files · +24 −9Browse files

Unified · Split

3 files
  1. fftools/ffmpeg.c +15 −7
  2. fftools/ffmpeg.h +2 −1
  3. fftools/ffmpeg_filter.c +7 −1
fftools/ffmpeg.c+15−7
@@ -237,7 +237,7 @@ static void sub2video_push_ref(InputStream *ist, int64_t pts) · 236 unmodified lines
237 }237 }
238}238}
239 239
240void sub2video_update(InputStream *ist, AVSubtitle *sub)240void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
241{241{
242 AVFrame *frame = ist->sub2video.frame;242 AVFrame *frame = ist->sub2video.frame;
243 int8_t *dst;243 int8_t *dst;
@@ -254,7 +254,12 @@ void sub2video_update(InputStream *ist, AVSubtitle *sub) · 10 unmodified lines
254 AV_TIME_BASE_Q, ist->st->time_base);254 AV_TIME_BASE_Q, ist->st->time_base);
255 num_rects = sub->num_rects;255 num_rects = sub->num_rects;
256 } else {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 end_pts = INT64_MAX;263 end_pts = INT64_MAX;
259 num_rects = 0;264 num_rects = 0;
260 }265 }
@@ -269,6 +274,7 @@ void sub2video_update(InputStream *ist, AVSubtitle *sub) · 8 unmodified lines
269 sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]);274 sub2video_copy_rect(dst, dst_linesize, frame->width, frame->height, sub->rects[i]);
270 sub2video_push_ref(ist, pts);275 sub2video_push_ref(ist, pts);
271 ist->sub2video.end_pts = end_pts;276 ist->sub2video.end_pts = end_pts;
277 ist->sub2video.initialize = 0;
272}278}
273 279
274static void sub2video_heartbeat(InputStream *ist, int64_t pts)280static 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 /* do not send the heartbeat frame if the subtitle is already ahead */297 /* do not send the heartbeat frame if the subtitle is already ahead */
292 if (pts2 <= ist2->sub2video.last_pts)298 if (pts2 <= ist2->sub2video.last_pts)
293 continue;299 continue;
294 if (pts2 >= ist2->sub2video.end_pts ||300 if (pts2 >= ist2->sub2video.end_pts || ist2->sub2video.initialize)
295 (!ist2->sub2video.frame->data[0] && ist2->sub2video.end_pts < INT64_MAX))301 /* if we have hit the end of the current displayed subpicture,
296 sub2video_update(ist2, NULL);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 for (j = 0, nb_reqs = 0; j < ist2->nb_filters; j++)305 for (j = 0, nb_reqs = 0; j < ist2->nb_filters; j++)
298 nb_reqs += av_buffersrc_get_nb_failed_requests(ist2->filters[j]->filter);306 nb_reqs += av_buffersrc_get_nb_failed_requests(ist2->filters[j]->filter);
299 if (nb_reqs)307 if (nb_reqs)
@@ -307,7 +315,7 @@ static void sub2video_flush(InputStream *ist) · 7 unmodified lines
307 int ret;315 int ret;
308 316
309 if (ist->sub2video.end_pts < INT64_MAX)317 if (ist->sub2video.end_pts < INT64_MAX)
310 sub2video_update(ist, NULL);318 sub2video_update(ist, INT64_MAX, NULL);
311 for (i = 0; i < ist->nb_filters; i++) {319 for (i = 0; i < ist->nb_filters; i++) {
312 ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL);320 ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL);
313 if (ret != AVERROR_EOF && ret < 0)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 return ret;2515 return ret;
2508 2516
2509 if (ist->sub2video.frame) {2517 if (ist->sub2video.frame) {
2510 sub2video_update(ist, &subtitle);2518 sub2video_update(ist, INT64_MIN, &subtitle);
2511 } else if (ist->nb_filters) {2519 } else if (ist->nb_filters) {
2512 if (!ist->sub2video.sub_queue)2520 if (!ist->sub2video.sub_queue)
2513 ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle));2521 ist->sub2video.sub_queue = av_fifo_alloc(8 * sizeof(AVSubtitle));
fftools/ffmpeg.h+2−1
@@ -348,6 +348,7 @@ typedef struct InputStream { · 347 unmodified lines
348 AVFifoBuffer *sub_queue; ///< queue of AVSubtitle* before filter init348 AVFifoBuffer *sub_queue; ///< queue of AVSubtitle* before filter init
349 AVFrame *frame;349 AVFrame *frame;
350 int w, h;350 int w, h;
351 unsigned int initialize; ///< marks if sub2video_update should force an initialization
351 } sub2video;352 } sub2video;
352 353
353 int dr1;354 int dr1;
@@ -645,7 +646,7 @@ int filtergraph_is_simple(FilterGraph *fg); · 291 unmodified lines
645int init_simple_filtergraph(InputStream *ist, OutputStream *ost);646int init_simple_filtergraph(InputStream *ist, OutputStream *ost);
646int init_complex_filtergraph(FilterGraph *fg);647int init_complex_filtergraph(FilterGraph *fg);
647 648
648void sub2video_update(InputStream *ist, AVSubtitle *sub);649void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub);
649 650
650int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);651int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame);
651 652
fftools/ffmpeg_filter.c+7−1
@@ -740,6 +740,12 @@ static int sub2video_prepare(InputStream *ist, InputFilter *ifilter) · 739 unmodified lines
740 return AVERROR(ENOMEM);740 return AVERROR(ENOMEM);
741 ist->sub2video.last_pts = INT64_MIN;741 ist->sub2video.last_pts = INT64_MIN;
742 ist->sub2video.end_pts = INT64_MIN;742 ist->sub2video.end_pts = INT64_MIN;
743
744 /* sub2video structure has been (re-)initialized.
745 Mark it as such so that the system will be
746 initialized with the first received heartbeat. */
747 ist->sub2video.initialize = 1;
748
743 return 0;749 return 0;
744}750}
745 751
@@ -1168,7 +1174,7 @@ int configure_filtergraph(FilterGraph *fg) · 422 unmodified lines
1168 while (av_fifo_size(ist->sub2video.sub_queue)) {1174 while (av_fifo_size(ist->sub2video.sub_queue)) {
1169 AVSubtitle tmp;1175 AVSubtitle tmp;
1170 av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL);1176 av_fifo_generic_read(ist->sub2video.sub_queue, &tmp, sizeof(tmp), NULL);
1171 sub2video_update(ist, &tmp);1177 sub2video_update(ist, INT64_MIN, &tmp);
1172 avsubtitle_free(&tmp);1178 avsubtitle_free(&tmp);
1173 }1179 }
1174 }1180 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t