I would like to add a text to a video file with FFMPEG. While I was able to do this with plain text

$FFMPEG -y -i $SOURCE \ -vf drawtext="fontfile=/usr/share/fonts/Lato-Reg-webfont.ttf:fontsize=40:box=1:boxcolor=black:fontcolor=white:text='$WATERMARK':x=(main_w-text_w)-10:y=(main_h-text_h)-4" \ -threads $THREADS -f mp4 -vcodec mpeg4 -b $MOBILE_BITRATE -r $MOBILE_FRAME_RATE -strict -2 \ -s $RESOLUTION_SD -acodec libfaac -ar $MOBILE_AUDIO_RATE -ac $MOBILE_AUDIO_CHANNELS -ab $MOBILE_AUDIO_BITRATE \ $VIDEONAME_MOBILE-android.mp4

this won't look good enough. So I tried with adding a transparent PNG file as a watermark. Looking for examples I tried like this:

$FFMPEG -y -i $SOURCE \ -vf "movie=$WATERMARK_SMALL_PATH [watermark]; [in][watermark] overlay=10:main_h/2-overlay_h/2 [out]" \ -threads $THREADS -f mp4 -vcodec mpeg4 -b $MOBILE_BITRATE -r $MOBILE_FRAME_RATE -strict -2 \ -s $RESOLUTION_SD -acodec libfaac -ar $MOBILE_AUDIO_RATE -ac $MOBILE_AUDIO_CHANNELS -ab $MOBILE_AUDIO_BITRATE \ $VIDEONAME_MOBILE-android.mp4

it won't work. I can share the exact error output if that could be useful to anyone.

migrated from stackoverflow.com Nov 20 '13 at 2:53

This question came from our site for professional and enthusiast programmers.

  • Have you tried looking here ? stackoverflow.com/questions/17135973/… – Ely Nov 19 '13 at 13:22
  • 1
    You need to show the actual, unscripted ffmpeg commands and the complete ffmpeg console outputs. – llogan Nov 19 '13 at 17:57

With the overlay filter you don't need the movie= format. It's easier, so use this format instead:

ffmpeg -y -i inputmovie -i inputpicture.png -filter_complex 'overlay=0:0' -s 1280x720 ...other parameters... outputfile.mp4

The size I put in is as an example only- yours will be different. Note that the size is the same for the picture as well as the movie frame, and no scaling is actually being done here. The 0:0 is for alignment of the picture to the top left of the movie frame- this is logical since they are both the same size.

  • A complex filtergraph uses one or more inputs and produces one or more outputs, so -filter_complex should be used here instead of -vf. -y is a global option so it should be the first option. The scaling should be in the filtergraph by using the scale filter instead of using -s; otherwise it may be ambiguous as to when and where it is being applied. – llogan Nov 20 '13 at 18:29
  • @LordNeckbeard Thanks. Always used -filter_complex because there were other filters in the chain. It was wrong for me to infer that removing other filters from the chain automatically would mean that -vf would work. I realize now that there are 2 inputs. Correcting it. – Rajib Nov 21 '13 at 2:45
  • This could probably be improved upstream since I think using -filter_complex works for linear filtering/simple filtergraphs too (but I may be wrong about that and I haven't looked at the code). – llogan Nov 21 '13 at 2:58
  • 1
    Thank you @Rajib, it worked how you suggested. Anyway, an important detail for is that I needed to also convert the PNG to 8bit using pngquant – Alex Flo Nov 22 '13 at 13:48
  • @Alex Flo It would be great if you share your full command for everyone's benefit. – Rajib Nov 22 '13 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.