diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-06-14 18:08:10 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-06-19 09:48:56 +0200 |
commit | 88f80977eb571044e2bc157fe1b60ac63061eba0 (patch) | |
tree | 98f323c74afb17c7d6684a324157cbdb89657aae /fftools/ffmpeg_filter.c | |
parent | fa717baaa599b07eb647cf70a527b98b18c8236e (diff) | |
download | ffmpeg-88f80977eb571044e2bc157fe1b60ac63061eba0.tar.gz |
fftools/ffmpeg: use AVFrame to pass subtitles from decoders to filters
Allows to use the same buffering code for all media types. Will also be
important for the following commit.
Diffstat (limited to 'fftools/ffmpeg_filter.c')
-rw-r--r-- | fftools/ffmpeg_filter.c | 51 |
1 files changed, 13 insertions, 38 deletions
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 9e6883ccdd..acc8596836 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -118,9 +118,6 @@ typedef struct InputFilterPriv { } fallback; struct { - ///< queue of AVSubtitle* before filter init - AVFifo *queue; - AVFrame *frame; int64_t last_pts; @@ -749,12 +746,6 @@ void fg_free(FilterGraph **pfg) av_frame_free(&frame); av_fifo_freep2(&ifp->frame_queue); } - if (ifp->sub2video.queue) { - AVSubtitle sub; - while (av_fifo_read(ifp->sub2video.queue, &sub, 1) >= 0) - avsubtitle_free(&sub); - av_fifo_freep2(&ifp->sub2video.queue); - } av_frame_free(&ifp->sub2video.frame); av_channel_layout_uninit(&ifp->fallback.ch_layout); @@ -1593,7 +1584,11 @@ static int configure_filtergraph(FilterGraph *fg) InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); AVFrame *tmp; while (av_fifo_read(ifp->frame_queue, &tmp, 1) >= 0) { - ret = av_buffersrc_add_frame(ifp->filter, tmp); + if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) { + sub2video_update(ifp, INT64_MIN, (const AVSubtitle*)tmp->buf[0]->data); + } else { + ret = av_buffersrc_add_frame(ifp->filter, tmp); + } av_frame_free(&tmp); if (ret < 0) goto fail; @@ -1610,20 +1605,6 @@ static int configure_filtergraph(FilterGraph *fg) } } - /* process queued up subtitle packets */ - for (i = 0; i < fg->nb_inputs; i++) { - InputFilter *ifilter = fg->inputs[i]; - InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - - if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE && ifp->sub2video.queue) { - AVSubtitle tmp; - while (av_fifo_read(ifp->sub2video.queue, &tmp, 1) >= 0) { - sub2video_update(ifp, INT64_MIN, &tmp); - avsubtitle_free(&tmp); - } - } - } - return 0; fail: @@ -1797,35 +1778,29 @@ void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational t sub2video_push_ref(ifp, pts2); } -int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *subtitle) +int ifilter_sub2video(InputFilter *ifilter, const AVFrame *frame) { InputFilterPriv *ifp = ifp_from_ifilter(ifilter); int ret; if (ifilter->graph->graph) { - if (!subtitle) { + if (!frame) { if (ifp->sub2video.end_pts < INT64_MAX) sub2video_update(ifp, INT64_MAX, NULL); return av_buffersrc_add_frame(ifp->filter, NULL); } - sub2video_update(ifp, INT64_MIN, subtitle); - } else if (subtitle) { - AVSubtitle sub; + sub2video_update(ifp, INT64_MIN, (const AVSubtitle*)frame->buf[0]->data); + } else if (frame) { + AVFrame *tmp = av_frame_clone(frame); - if (!ifp->sub2video.queue) - ifp->sub2video.queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); - if (!ifp->sub2video.queue) + if (!tmp) return AVERROR(ENOMEM); - ret = copy_av_subtitle(&sub, subtitle); - if (ret < 0) - return ret; - - ret = av_fifo_write(ifp->sub2video.queue, &sub, 1); + ret = av_fifo_write(ifp->frame_queue, &tmp, 1); if (ret < 0) { - avsubtitle_free(&sub); + av_frame_free(&tmp); return ret; } } |