Today we are discussing about how PHP add text to video with FFMPEG. To add text to a video with PHP we required FFMPEG extension. In this tutorial we are not discussing about what is FFMPEG. So I am directly jumping to the coding part.

To add a text to video there are two types of situation.

1. Add text to video from 1st frame of video to the last frame of video.

shell_exec('ffmpeg -i video.mp4 -strict experimental -vf drawtext=/"fontfile=OpenSans-Bold.ttf:text='Vishal Gupta':fontsize=20:fontcolor=black:x=100:y=100/" output.mp4');

  • video.mp4 is your video
  •  x and y is video position where you want to add text
  • output.mp4 is output video

2. Add text to video from specific frame to another specific frame.

shell_exec('ffmpeg -i video.mp4 -strict experimental -vf drawtext=/"fontfile=OpenSans-Bold.ttf:enable='between(t,3,8)':text='Vishal Gupta':fontsize=20:fontcolor=black:x=100:y=100/" output.mp4')

  • video.mp4 is your video
  • enable is the duration. In above code 3 sec to 8 sec duration text will be visible
  •  x and y is video position where you want to add text
  • output.mp4 is output video