Is there any way to highlight some words in text written with the drawtext
filter?
I know it doesn't support it directly, so I'm looking for an alternative way to do it.
Is there any way to highlight some words in text written with the drawtext
filter?
I know it doesn't support it directly, so I'm looking for an alternative way to do it.
There is no practical method using drawtext other than making a separate box with drawbox filter which is unwieldy, not dynamic, and hard to match text coordinates.
Use ASS subtitles instead.
Example of subtitle mark-up in Aegisub:
This is {\3c&H00FFFF&\3a&H128&}highlighted{\3c\3a} text.
See ASS Tags for more info.
Box around text can be enabled in Aegisub as shown in How to set background to subtitle in ffmpeg?
Example ASS file:
[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: None
PlayResX: 640
PlayResY: 480
[Aegisub Project Garbage]
Last Style Storage: Default
Video File: ?dummy:23.976000:40000:640:480:47:163:254:
Video AR Value: 1.333333
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&HFF333333,&HFF000000,0,0,0,0,100,100,0,0,3,2,0,2,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,This is {\3c&H00FFFF&\3a&H128&}highlighted{\3c\3a} text.
ffmpeg
command using the subtitles filter for hardsubs:
ffmpeg -i input.mp4 -vf "subtitles=highlight.ass" -c:a copy output.mp4
ffmpeg
command for softsubs:
ffmpeg -i input.mp4 -i highlight.ass -map 0 -map 1 -c copy output.mkv