ffmpeg add or embed text into video on iis or xampp server

June 11, 2015
  1. Download video_processing.zip and dejavu-fonts-ttf.tar.bz2 and extract it.Note- copy both the files in your project directory.
  2. We are going to use php exec() function to execute commands related to video processing.
  3. C:\>ffmpeg -i inputvideo.mp4 -vf drawtext="fontfile=ttf\DejaVuSerif.ttf:
    text='+919987688035':fontsize=70:fontcolor=red:x=700:y=925:enable='between(t,61.6,78)'" outputvideo.mp4
  4. In the above code replace “ffmpeg” with absolute path (i.e C:\directory\ffmpeg).Also replace inputvideo.mp4 and outputvideo.mp4 with their absolute path.Note- outputvideo.mp4 is not present and will be generated after successful execution of the command,but we have to put it’s path in the command.
  5. Your command will look like this
    C:\>C:\directory\ffmpeg -i C:\directory\inputvideo.mp4 -vf drawtext="fontfile=
    C:\directory\ttf\DejaVuSerif.ttf: text='+919987688035':fontsize=70:
    fontcolor=red:x=700:y=925:enable='between(t,61.6,78)'" C:\directory\outputvideo.mp4
  6. Once you you run above command in windows cmd,you will get your outputvideo.mp4 with text added to it.
  7. In above code “between(t,61.6,78)” means text will be added during time frame of 61.6 and 78 seconds of the original video.
  8. If you want to do this in PHP, you just have to put it in exec() function.i.e.
    exec(C:\>C:\directory\ffmpeg -i C:\directory\inputvideo.mp4 -vf drawtext="fontfile=
    C:\directory\ttf\DejaVuSerif.ttf: text='+919987688035':fontsize=70:
    fontcolor=red:x=700:y=925:enable='between(t,61.6,78)'" C:\directory\outputvideo.mp4)

    Note- Please place quotes properly in the above command string while using for php.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *