[FFmpeg-devel] [PATCH] lavfi/drawtext: ignore final LF of textfile.

Nicolas George george at nsup.org
Mon Nov 30 20:38:10 EET 2020


A standard text file ends with a final LF.
Without this change, it is interpreted as an empty final line,
and visible with the box option.
The current behavior can be achieved by actually having
an empty line at the end of the file.

Fix trac ticket #7948.

Signed-off-by: Nicolas George <george at nsup.org>
---
 libavfilter/vf_drawtext.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index abe1ca6c35..0cc47e84a9 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -583,6 +583,8 @@ static int load_textfile(AVFilterContext *ctx)
         return err;
     }
 
+    if (textbuf_size > 0 && textbuf[textbuf_size - 1] == '\n')
+        textbuf_size--;
     if (textbuf_size > SIZE_MAX - 1 || !(tmp = av_realloc(s->text, textbuf_size + 1))) {
         av_file_unmap(textbuf, textbuf_size);
         return AVERROR(ENOMEM);
-- 
2.29.2



More information about the ffmpeg-devel mailing list