Last active
December 1, 2024 00:18
-
-
Save ricekab/549f75a53086867e0db9090719d146cf to your computer and use it in GitHub Desktop.
ffmpeg overlay + drawtext simple examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Add overlay over entire video. No extra text | |
ffmpeg -i examplecut.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay" -c:a copy output.mp4 | |
2. Add overlay over for 10 seconds in the middle (5s - 15s in this example) | |
ffmpeg -i examplecut.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=enable='between(t,5,15)'" -c:a copy output2.mp4 | |
2b. Add overlay starting from X time until the end (X=5 in this example) | |
ffmpeg -i examplecutshort.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=enable='gte(t,5)'" -c:a copy output2b.mp4 | |
3. Add text on top of the overlay | |
ffmpeg -i examplecutshort.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay,drawtext=fontsize=30:text=ricekab playername:x=(w-text_w)/4:y=(text_h+30)" -c:a copy output3.mp4 | |
Multiple drawtexts can be used in sequence. Font options etc can be found here: | |
https://ffmpeg.org/ffmpeg-filters.html#drawtext-1 | |
3b. Similar to the overlay, drawtext can be cut to specific times: | |
ffmpeg -i examplecutshort.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay,drawtext=fontsize=30:text=ricekab playername:x=(w-text_w)/4:y=(text_h+30):enable='between(t,0,10)'" -c:a copy output3b.mp4 | |
4. RECAP - Combining the above | |
Let's unpack this command in parts to see what we're doing: | |
ffmpeg -i examplecutshort.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay,drawtext=fontsize=30:text=ricekab playername:x=(w-text_w)/4:y=(text_h+30):enable='between(t,0,10)',drawtext=fontsize=30:text=tag | otherplayer:x=(w-text_w)*3/4:y=(text_h+30):enable='between(t,0,15)',drawtext=fontsize=24:fontcolor=Crimson:text='Winners Final':x=(w-text_w)/2:y=(text_h+60)" -c:a copy output4.mp4 | |
In parts: | |
[COMMAND INPUTS] | ffmpeg -i examplecutshort.mp4 -i overlay.png | |
[FILTER FLAG] | -filter_complex " | |
[EXPLICIT ORDER] | [0:v][1:v] | |
[OVERLAY] | overlay, | |
(for the whole video) | |
[DRAWTEXT] | drawtext=fontsize=30: | |
text=ricekab playername: | |
x=(w-text_w)/4: | |
y=(text_h+30) | |
[DRAWTEXT] | drawtext=fontsize=30: | |
text=tag | otherplayer: | |
x=(w-text_w)*3/4: | |
y=(text_h+30): | |
enable='between(t,0,15)', | |
[DRAWTEXT] | drawtext=fontsize=24: | |
fontcolor=Crimson: | |
text='Winners Final': | |
x=(w-text_w)/2: | |
y=(text_h+60)" | |
[COPY AUDIO] | -c:a copy | |
[OUTPUT FILE] | output4.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment