'Very long ffmpeg command due to drawtext commands for every second
I have a video of about 20 minutes length and want to show every second a different text using the drawtext filter. I used a java software to compute a very long ffmpeg command (more than 100,000 characters long). Pasting it into the PowerShell took a long time and then I got the error
Program 'ffmpeg.exe' failed to run: The filename or extension is too longAt line:1 char:1
So the command is obviously too long. Can I somehow outsource it into an external file? I'm not looking for the subtitles filter instead of the drawtext filter because I'm using special functionalities of drawtext.
Solution 1:[1]
Create temporary utf-8 text files containing the text (one file per drawtext filter instance) and specify them when calling drawtext filter with its textfile option instead of the text option. See documentation.
Alternate Approach
Break down the video into shorter segments so each ffmpeg command is within 8191-character limit. Then, use the -f concat demuxer with the -c copy muxer option to combine the output video segments.
Unfortunately, either approach requires creation of a tempdir to manage intermediate files but the latter will produce less number of them.
Solution 2:[2]
I'm posting this (yet another) alternate approach as a separate answer because it is substantially different from the previous takes.
You can shorten the command line by prepending a sendcmd filter in front of each drawtext filter. The drawtext documentation shows an example of using sendcmd to alter the text:
sendcmd=c='56.0 drawtext reinit fontsize=56\:fontcolor=green\:text=Hello\\ World'
If you also check the sendcmd documentation, it lists the filename option:
filename, f
Set the filename of the commands to be read and sent to the other filters.
with an example:
Specify a list of drawtext and hue commands in a file.
# show text in the interval 5-10 5.0-10.0 [enter] drawtext reinit 'fontfile=FreeSerif.ttf:text=hello world', [leave] drawtext reinit 'fontfile=FreeSerif.ttf:text=';A filtergraph allowing to read and process the above command list stored in a file test.cmd, can be specified with:
sendcmd=f=test.cmd,drawtext=fontfile=FreeSerif.ttf:text='',hue
So, instead of using the enable=between(start,end) option, you can use a single drawtext filter in the graph and compose a command text file to instruct it what to do.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | kesh |
