Commit 1f03564df6 for ffmpeg
commit 1f03564df64081f345bff7ebdd48a947496dfa53
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date: Wed Nov 11 21:34:06 2026 -0800
avfilter: add ff_filter_log_lines()
Logs an AVBPrint one line per av_log() call, splitting lines over 896
bytes so each call fits a 1024-byte line buffer such as -report's.
Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 70674d2c91..5e1b2d0309 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -235,6 +235,39 @@ void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
ctxi->ready = FFMAX(ctxi->ready, priority);
}
+void ff_filter_log_lines(void *ctx, int level, const AVBPrint *bp)
+{
+ const char *p, *end;
+
+ if (!bp->size)
+ return;
+
+ p = bp->str;
+ end = bp->str + FFMIN(bp->len, bp->size - 1);
+ while (p < end) {
+ /* Look no further than the next chunk, so long lines stay linear. */
+ const char *nl = memchr(p, '\n', FFMIN(end - p, FF_FILTER_LOG_LINE_MAX + 1));
+ size_t len = nl ? nl - p : end - p;
+ size_t skip = 1;
+
+ if (len > FF_FILTER_LOG_LINE_MAX) {
+ len = FF_FILTER_LOG_LINE_MAX;
+ skip = 0;
+ for (size_t i = len; i > len / 2; i--) {
+ if (p[i] == ' ') {
+ len = i;
+ break;
+ }
+ }
+ }
+ av_log(ctx, level, "%.*s\n", (int)len, p);
+ p += len + skip;
+ }
+
+ if (!av_bprint_is_complete(bp))
+ av_log(ctx, AV_LOG_WARNING, "Log output truncated, out of memory\n");
+}
+
/**
* Clear frame_blocked_in on all outputs.
* This is necessary whenever something changes on input.
diff --git a/libavfilter/filters.h b/libavfilter/filters.h
index 4b2a5564c1..96260c3554 100644
--- a/libavfilter/filters.h
+++ b/libavfilter/filters.h
@@ -509,6 +509,30 @@ static inline const FFFilter *fffilter(const AVFilter *f)
*/
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority);
+/**
+ * Longest line, in bytes, that ff_filter_log_lines() passes to a single
+ * av_log() call. It leaves room for the log prefix in fixed-size line
+ * buffers such as the 1024-byte one of ffmpeg's -report callback.
+ */
+#define FF_FILTER_LOG_LINE_MAX 896
+
+struct AVBPrint;
+
+/**
+ * Log text built in an AVBPrint with one av_log() call per line, so that
+ * output from other threads cannot land in the middle of a line and every
+ * line gets its own prefix. Lines longer than FF_FILTER_LOG_LINE_MAX bytes
+ * are split before a space if there is one near the limit; no byte is lost.
+ *
+ * If the buffer is incomplete, the text it holds is logged, followed by a
+ * warning.
+ *
+ * @param ctx logging context
+ * @param level log level of the text
+ * @param bp text to log; a missing final newline is supplied
+ */
+void ff_filter_log_lines(void *ctx, int level, const struct AVBPrint *bp);
+
/**
* Get the number of frames available on the link.
* @return the number of frames available in the link fifo.