i am trying to add gif and text on video using ffmpeg somewhat similar to tiktok. want it to be like tiktok ie on top right gif and text and after sometime left bottom same gif and text on the video.
Asked
Active
Viewed 1,574 times
3 Answers
0
ffmpeg -i video.mp4 -ignore_loop 0 -i logo.gif -filter_complex "[0:v][1:v]overlay=x=10:y=10:format=auto:enable='lte(t,5)':shortest=1[bg];[bg][1:v]overlay=x=main_w-overlay_w-10:y=main_h-overlay_h-20:format=auto:enable='gte(t,5)':shortest=1,drawtext=text='@user1872811':fontsize=16:fontcolor=white:x=10:y=40:enable='lte(t,5)',drawtext=text='@user1872811':fontsize=16:fontcolor=white:x=w-tw-10:y=h-th-10:enable='gte(t,5)',format=yuv420p[v]" -map "[v]" -c:v libx264 -crf 18 -map 0:a -c:a copy -movflags +faststart output.mp4
You will need to adjust x
and y
positions for overlay and drawtext depending on the GIF width x height.
Adapted from:
- Text on video ffmpeg
- provide time period in ffmpeg drawtext filter
- How to position drawtext text
- How to add watermark with ffmpeg?
Also see:

llogan
- 121,796
- 28
- 232
- 243
-
thanks it works but video quality is very bad..any idea how to get same video quality? – user1872811 Aug 12 '20 at 11:04
-
where to add this option? after which command basically? – user1872811 Sep 02 '20 at 19:37
-
can you please tell me how to make it top right and then bottom left? – user1872811 Sep 07 '20 at 00:25
-
@user1872811 See the links in the answer *How to position drawtext text* or *How to add watermark with ffmpeg?* – llogan Sep 08 '20 at 17:03
0
Top-Left To Bottom-Right loop:
ffmpeg -i video.mp4 -i watermark.png -filter_complex \
"[0:v][1:v]overlay=x='if(lt(mod(t,10),5),10,W-w-10)':y='if(lt(mod(t,10),5),10,H-h-10)'" \
-codec:a copy out.mp4
Top-Right To Bottom-Left loop:
ffmpeg -i video.mp4 -i watermark.png -filter_complex \
"[0:v][1:v]overlay=x='if(lt(mod(t,10),5),W-w-10,10)':y='if(lt(mod(t,10),5),10,H-h-10)'" \
-codec:a copy out.mp4
Idea is very simple
- Take every 10sec duration, get remainder sec i.e. mod(t,10)
- if sec < 5, set top position else bottom position
Please note I have excluded text i.e. username.

Ramesh Jangama
- 81
- 1
- 4
-1
ffmpeg -y -i out.mp4 -i 1080_Happy_Holidays_Red_Videvo.mov -i logo.png -filter_complex "[0]scale=iw/4:-1[pip];[1][pip]overlay=100:100[watermark];[watermark][2]overlay=main_w-overlay_w-10:main_h-overlay_h-10" output.mp4
You have more examples on my webste but it is forbiddien to give here an URL. Send me a private message

Seb
- 65
- 1
- 6