We'll explore the introduction of lyrics in future posts, but it's pretty common to overlay text onto a video. Applying moving text is a bit less common, but easily do-able with a bit of tweaking and patience.
Let's take a simple video, a guaranteed ear wig:
Next, if we grab the lyrics and paste them into a text file; http://www.metrolyrics.com/dowackado-lyrics-roger-miller.html
We can overlay the contents of the lyrics file in the form of moving text by the following command:
$ ffmpeg -y -i video.mp4 -vf "drawtext=enable='gte(t,0)':fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:fontsize=36:fontcolor=white:borderw=5:textfile=lyrics.txt:reload=1:y=h-line_h-10:x=W-((W/tw)*325*n+350)" -acodec copy outVideo.mp4
Whoa, that's worthy of a command breakdown:
The drawtext video filter starts with an enable conditional [e.g. enable='gte(t,0)], while it has little affect in this example, this is a way to turn on the drawtext videofilter after a duration has expired. This could prove valuable if you wish to postpone the drawing of text later into the video.
The fontfile is precisely that, the preferred font. You may wish to play around with available fonts to select the most appropriate one for your overlay.
Font size, font color, borderwidth are all specifiers for the overlay font.
The next argument specifies the textfile that contains the overlay contents. The format of the file is important, consisting of 1 continuous line containing the entirety of the lyrics. Short pauses in lyrics can be done by adding spaces.
The reload command implies that the lyrics can change from frame to frame. The last arguments specify the y-position of the beginning of the text. Notice that the y-position video frame height (e.g. h), minus the height of the text along with an additional offset to draw the text up a bit from the absolute bottom of the video. The x-position is the more interesting one, starting at the frame width (e.g. W) and frame-by-frame subtracting a dX.
The result:
It takes a good deal of patience and tweaking to get the timing right.
Have fun!
No comments:
Post a Comment