I want to display multiple lines with FFmpeg subtitles.

Asked 2 years ago, Updated 2 years ago, 96 views

I'm using FFmpeg drawtext to display subtitles in the video, but I'm worried about how to write the code to display multiple lines after a new line.There was a description that could be done by /r/n in the escape, but I don't know how to write the actual code.If you have any experience in implementing it, please let me know.Thank you for your cooperation.

ffmpeg

2022-09-30 21:41

1 Answers

This Drawtext|Nicolab that describes the characters is easy to file (top with the proviso in Windows).

  • textfile [string]
    Specifies the path of the text file to be drawn.Cannot be used with text.The character code must be UTF-8.This is easier for new lines

However, there seems to be no way to control the space between the lines.
It may have changed since it was a question from May 2012.

Control spacing between multiple lines with drawtext filter

You are trying to use a drawtext filter to draw multiple lines of text in a video.
However, the spacing between the lines is too narrow, and the spacing actually appears to be zero.
Does anyone know how to control line spacing with this filter?

Comments:

There are currently no such parameters. Patches are welcome.
As a workaround, you can pass the source video through two separate drawtext filters and write one line for each filter instance.

Similar to the workaround above, there seems to be a two-line specification using the [in][out] tag and comma in text instead of the file.

FFmpeg drawtext over multiple lines

A:

This answer is probably a little slow for you, but you can specify multiple draw texts in a file by using the [in] tag and using commas to list each draw text.
This allows you to use multiple lines to orient each draw text in its own placement.
In your example, the command line looks like this (place the first line in the middle of the screen and each subsequent line 25 pixels below):

ffmpeg-itest_in.avi-vf "[in]drawtext=fontsize=20:fontcolor=White:fontfile='/Windows/Fonts/arial.ttf':text='onLine1':x=(w)/2:y=(h)/2,drawtext=fontsize=20:fontcolor(h)/2)+50[out]"-y test_out.avi

Also, there is an article saying that you can simply add \r\nto text, and I think you referred to it, but it is not clear because there is a comment that \n is not working.

Make a new line with drawtext in FFmpeg
If you want to use FFmpeg's draw text (multiple line), you can use Form Feed\f^L

\nComments about not working
Drawtext complex filter-multiple line#488

If you look here at 10.53.2 Text expansion, you'll be able to do something.

  • expr,e
    This is the result of the formula evaluation.
    You must take one argument that specifies the expression to be evaluated.It accepts the same constants and functions as the x and y values. Note that you do not need to use all constants.For example, constants text_w and text_h are undefined because the text size is not known when evaluating an expression.

There seems to be another way to use subtitles instead of drawtext.

Another interpretation of subtitles or textual videos with ffmpeg
FFMPEG:Creating video using draft text along with word wrap and padding


2022-09-30 21:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.