summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorDevin Heitmueller <devin.heitmueller@ltnglobal.com>2023-05-05 15:09:05 -0400
committerLimin Wang <lance.lmwang@gmail.com>2023-05-11 22:06:20 +0800
commitf304c3a729b2c710de2b1bf3c1f9f1c42d17d4f1 (patch)
tree37d5c68f65a35aebad1509fffd8af7535097991a /libavfilter
parentcecf35ae3e997dd884295d692aa6829462394132 (diff)
downloadffmpeg-f304c3a729b2c710de2b1bf3c1f9f1c42d17d4f1.tar.gz
avfilter/tinterlace: Properly preserve CEA-708 closed captions
Because the interlacing filter halves the effective framerate, we need to ensure that no CEA-708 data is lost as frames are merged. Make use of the new ccfifo mechanism to ensure that caption data is properly preserved as frames pass through the filter. Thanks to Thomas Mundt for review and noticing a couple of missed codepaths for injection on output. Thanks to Lance Wang for pointing out a memory leak. Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/tinterlace.h2
-rw-r--r--libavfilter/vf_tinterlace.c11
2 files changed, 13 insertions, 0 deletions
diff --git a/libavfilter/tinterlace.h b/libavfilter/tinterlace.h
index 37b6c10c08..9f5ce7e65b 100644
--- a/libavfilter/tinterlace.h
+++ b/libavfilter/tinterlace.h
@@ -32,6 +32,7 @@
#include "libavutil/pixdesc.h"
#include "drawutils.h"
#include "avfilter.h"
+#include "ccfifo.h"
#define TINTERLACE_FLAG_VLPF 01
#define TINTERLACE_FLAG_CVLPF 2
@@ -77,6 +78,7 @@ typedef struct TInterlaceContext {
const AVPixFmtDescriptor *csp;
void (*lowpass_line)(uint8_t *dstp, ptrdiff_t width, const uint8_t *srcp,
ptrdiff_t mref, ptrdiff_t pref, int clip_max);
+ AVCCFifo *cc_fifo;
} TInterlaceContext;
void ff_tinterlace_init_x86(TInterlaceContext *interlace);
diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c
index 8b0cbbcf95..e1057ffc8e 100644
--- a/libavfilter/vf_tinterlace.c
+++ b/libavfilter/vf_tinterlace.c
@@ -203,6 +203,7 @@ static av_cold void uninit(AVFilterContext *ctx)
av_frame_free(&tinterlace->next);
av_freep(&tinterlace->black_data[0][0]);
av_freep(&tinterlace->black_data[1][0]);
+ ff_ccfifo_freep(&tinterlace->cc_fifo);
}
static int config_out_props(AVFilterLink *outlink)
@@ -291,6 +292,11 @@ static int config_out_props(AVFilterLink *outlink)
#endif
}
+ if (!(tinterlace->cc_fifo = ff_ccfifo_alloc(outlink->frame_rate, ctx))) {
+ av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
+ return AVERROR(ENOMEM);
+ }
+
av_log(ctx, AV_LOG_VERBOSE, "mode:%d filter:%s h:%d -> h:%d\n", tinterlace->mode,
(tinterlace->flags & TINTERLACE_FLAG_CVLPF) ? "complex" :
(tinterlace->flags & TINTERLACE_FLAG_VLPF) ? "linear" : "off",
@@ -375,6 +381,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
tinterlace->cur = tinterlace->next;
tinterlace->next = picref;
+ ff_ccfifo_extract(tinterlace->cc_fifo, picref);
+
cur = tinterlace->cur;
next = tinterlace->next;
/* we need at least two frames */
@@ -456,6 +464,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (!out)
return AVERROR(ENOMEM);
out->pts /= 2; // adjust pts to new framerate
+ ff_ccfifo_inject(tinterlace->cc_fifo, out);
ret = ff_filter_frame(outlink, out);
return ret;
}
@@ -505,6 +514,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
out->pts = cur->pts*2;
out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base);
+ ff_ccfifo_inject(tinterlace->cc_fifo, out);
if ((ret = ff_filter_frame(outlink, out)) < 0)
return ret;
@@ -549,6 +559,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base);
out->duration = av_rescale_q(1, av_inv_q(outlink->frame_rate), outlink->time_base);
+ ff_ccfifo_inject(tinterlace->cc_fifo, out);
ret = ff_filter_frame(outlink, out);
return ret;