[FFmpeg-cvslog] lavfi/overlay: add logic for avoiding overlaying frames with PTS > main frame PTS
Stefano Sabatini
git at videolan.org
Fri Feb 17 00:29:33 CET 2012
ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Tue Jan 10 01:21:17 2012 +0100| [7bdefc0f1281c2c18375197985fcd5109e711829] | committer: Stefano Sabatini
lavfi/overlay: add logic for avoiding overlaying frames with PTS > main frame PTS
Also add debug logging messages for helping tracking down similar
issues.
Fix trac ticket #467.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7bdefc0f1281c2c18375197985fcd5109e711829
---
libavfilter/version.h | 2 +-
libavfilter/vf_overlay.c | 40 ++++++++++++++++++++++++++++------------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 2aed76f..0435d57 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 62
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 38e8644..638da2d 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -25,6 +25,8 @@
* overlay one video on top of another
*/
+/* #define DEBUG */
+
#include "avfilter.h"
#include "libavutil/eval.h"
#include "libavutil/avstring.h"
@@ -32,6 +34,7 @@
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/mathematics.h"
+#include "libavutil/timestamp.h"
#include "internal.h"
#include "drawutils.h"
@@ -75,7 +78,7 @@ typedef struct {
uint8_t overlay_rgba_map[4];
uint8_t overlay_has_alpha;
- AVFilterBufferRef *overpicref;
+ AVFilterBufferRef *overpicref, *overpicref_next;
int main_pix_step[4]; ///< steps per pixel for each plane of the main output
int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay
@@ -146,6 +149,8 @@ static av_cold void uninit(AVFilterContext *ctx)
if (over->overpicref)
avfilter_unref_buffer(over->overpicref);
+ if (over->overpicref_next)
+ avfilter_unref_buffer(over->overpicref_next);
}
static int query_formats(AVFilterContext *ctx)
@@ -304,22 +309,31 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
AVFilterContext *ctx = inlink->dst;
OverlayContext *over = ctx->priv;
+ av_unused AVFilterLink *outlink = ctx->outputs[0];
inlink->dst->outputs[0]->out_buf = outpicref;
outpicref->pts = av_rescale_q(outpicref->pts, ctx->inputs[MAIN]->time_base,
ctx->outputs[0]->time_base);
if (!over->overpicref || over->overpicref->pts < outpicref->pts) {
- AVFilterBufferRef *old = over->overpicref;
- over->overpicref = NULL;
- avfilter_request_frame(ctx->inputs[OVERLAY]);
- if (over->overpicref) {
- if (old)
- avfilter_unref_buffer(old);
- } else
- over->overpicref = old;
+ if (!over->overpicref_next)
+ avfilter_request_frame(ctx->inputs[OVERLAY]);
+
+ if (over->overpicref && over->overpicref_next &&
+ over->overpicref_next->pts <= outpicref->pts) {
+ avfilter_unref_buffer(over->overpicref);
+ over->overpicref = over->overpicref_next;
+ over->overpicref_next = NULL;
+ }
}
+ av_dlog(ctx, "main_pts:%s main_pts_time:%s",
+ av_ts2str(outpicref->pts), av_ts2timestr(outpicref->pts, &outlink->time_base));
+ if (over->overpicref)
+ av_dlog(ctx, " over_pts:%s over_pts_time:%s",
+ av_ts2str(over->overpicref->pts), av_ts2timestr(over->overpicref->pts, &outlink->time_base));
+ av_dlog(ctx, "\n");
+
avfilter_start_frame(inlink->dst->outputs[0], outpicref);
}
@@ -328,9 +342,11 @@ static void start_frame_overlay(AVFilterLink *inlink, AVFilterBufferRef *inpicre
AVFilterContext *ctx = inlink->dst;
OverlayContext *over = ctx->priv;
- over->overpicref = inpicref;
- over->overpicref->pts = av_rescale_q(inpicref->pts, ctx->inputs[OVERLAY]->time_base,
- ctx->outputs[0]->time_base);
+ inpicref->pts = av_rescale_q(inpicref->pts, ctx->inputs[OVERLAY]->time_base,
+ ctx->outputs[0]->time_base);
+
+ if (!over->overpicref) over->overpicref = inpicref;
+ else over->overpicref_next = inpicref;
}
// divide by 255 and round to nearest
More information about the ffmpeg-cvslog
mailing list