[FFmpeg-user] Add time code AND a watermark in one pass

Kieran O Leary kieran.o.leary at gmail.com
Sun Feb 25 10:38:42 EET 2018


Hi Kevin,

Replies below..

On Sun, Feb 25, 2018 at 7:24 AM, Kevin Duffey
<kevinmduffey-at-yahoo.com at ffmpeg.org> wrote:
> Hi all,
> I have figured out from various sources how to add a watermark using a png file. Works well enough.
> What I also want to do is add timecode at 00:00:00:00 to my video as a text overlay.
> I have tried a few variations with the filter_complex, but I cant seem to get past any number of issues. In particular I get an issue with both text and a text file.. though I am never loading a text file, when trying to use drawtext.
> This is on a windows machine, though I suspect other than some of the batch syntax, it would be the same call on linux or mac. In particular I am trying to convert a directory of MOV DNxHR encoded videos to H.265, with the watermark AND timecode added.

I have to do this on a regular basis at work and we use this script on
pretty much a daily basis:
https://github.com/kieranjol/IFIscripts/blob/master/bitc.py - it works
on windows, linux and OSX. It looks for the starting timecode within
the file if it exists and adds our institutions watermark, but it
should be easy enough to alter these in the code itself. Let me know
if you need further help with it. I added standalone versions of the
ffmpeg calls in that script to ffmprovisr, which could help you out
too - https://amiaopensource.github.io/ffmprovisr/#overlay

> I think it would not be hard to add them in two passes.. e.g. add timecode first pass with copy mode, to keep it as DNxHR, then 2nd pass add watermark and convert to H.265 with lower resolution. I was hoping, however, to do it all in one pass, so as to save a lot of time

Yeah, you should be able to do it in one, however you can't add burn
in a timecode and use copy mode. You can't use any filters with -c
copy or -c:v copy as far as I know.

> Here is what I have, which fails with  Cannot find a valid font for the family Sans.  Even though I specify the font file, and have tried by using \\ and \\\ as well.  One time I was able to get past that, though I dont recall how now, and got the issue of the using both text and a text file with drawtext.

If it's any consolation, I spent many many hours figuring out the
correct escaping. I'd fix it in Windows, then it would break in OSX or
linux.

> Any help would be greatly appreciated. Naturally the watermark.png is the watermark image. My source DNxHR is 4K.  Here I am specifying h.264, though I would like to render to H.265 if possible... and assuming yahoo accept it as an upload format.
>
> for /R %%a in ("*.mov") do ffmpeg -i "%%a" -i watermark.png -filter_complex "[2:v]scale=4096x2160 [ovrl],[1:v][ovrl]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2; drawtext=fontfile='C:\\Windows\\Fonts||arial.ttf':fontsize=15:timecode='00\:00\:00\:00':r=24:x=(w-tw)/2:y=h-(2*lh):fontcolor=white" -s 720x480 -c:v libx264 -preset ultrafast -crf 20 d:\encoded\%%~na.mp4

Why are there two || characters before arial.ttf?

Batch scripts are not supported here, just regular ffmpeg calls.
Turning the ffmpeg call into a batch script is something you have to
do. Also it helps to copy/paste the full uncut terminal output of your
ffmpeg command and the output. Your command line is pretty complex and
difficult to replicate, so it also helps to simplify the issue as much
as possible, considering  you just need to find out how to escape
characters in windows in a ffmpeg/drawtext call.

C\\:\\\\Windows\\\\Fonts\\\\'arial.ttf'
^^ worked for me - so two escapes for the colon, three for each slash,
and then place 'arial.tff' in single quotes.
Here is a very simple command line which works on Windows 10:
ffmpeg -i out.mkv -vf
drawtext=fontfile=C\\:\\\\Windows\\\\Fonts\\\\'arial.ttf':fontsize=14:text=watermark_text
-y out.mov

Try your ffmpeg call without the batch script first and see if it
works. Sometimes scripts might need their own escaping, and that's a
different question for a different place..
Best,

Kieran O'Leary.


More information about the ffmpeg-user mailing list