Add time code AND a watermark in one pass
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 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. 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. 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 Thank you.
Hi Kevin, Replies below.. On Sun, Feb 25, 2018 at 7:24 AM, Kevin Duffey <kevinmduffey-at-yahoo.com@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.
P.S, you will probably need two escapes for each colon in your timecode too: 09\\:58\\:00\\:00
On 25-2-2018 9:38, Kieran O Leary <kieran.o.leary@gmail.com> wrote:
On Sun, Feb 25, 2018 at 7:24 AM, Kevin Duffey <kevinmduffey-at-yahoo.com@ffmpeg.org> wrote:
[...] 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?
[...]
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 If you ask me there's no need for so many escape-characters.
ffmpeg -i <input> -vf "drawtext=fontfile='C\:\\Windows\\Fonts\\arial.ttf':fontsize=14:fontcolor=white:text=watermark_text" -f sdl - and even ffmpeg -i <input> -vf "drawtext=fontfile='C\:/Windows/Fonts/arial.ttf':fontsize=14:fontcolor=white:text=watermark_text" -f sdl - work just fine for me. -- Reino
Hi On Sun, Feb 25, 2018 at 10:48 AM, Reino Wijnsma <rwijnsma@xs4all.nl> wrote:
On 25-2-2018 9:38, Kieran O Leary <kieran.o.leary@gmail.com> wrote:
On Sun, Feb 25, 2018 at 7:24 AM, Kevin Duffey <kevinmduffey-at-yahoo.com@ffmpeg.org> wrote:
[...] 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?
[...]
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 If you ask me there's no need for so many escape-characters.
ffmpeg -i <input> -vf "drawtext=fontfile='C\:\\Windows\\Fonts\\arial.ttf':fontsize=14:fontcolor=white:text=watermark_text" -f sdl -
and even
ffmpeg -i <input> -vf "drawtext=fontfile='C\:/Windows/Fonts/arial.ttf':fontsize=14:fontcolor=white:text=watermark_text" -f sdl -
work just fine for me.
-- Reino
Thanks Reino, both work perfect here too. Much simpler. -K
On 2/25/2018 12:38 AM, Kieran O Leary wrote:
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.
In a similar vein, I use tcl for this kind of scripting; highly portable when properly written and avoids most or all of the escaping problems of windows batch or *nix shell. z!
Hi, thank you for the replies. So here is my current script, and ill past some output below that. It is a windows .bat, but really the for loop is it, the ffmpeg call is the issue. I am NOT attempting to keep the video the same.. e.g. I want to convert it to h.265 AND add the timecode (starting at 00:00:00:00) and the watermark image in one pass if possible. btw..I know I am using h.264. for /R %%a in ("*.mov") do ffmpeg -i "%%a" -i watermark.png -filter_complex "[1:v]scale=4096x2160 [ovrl],[0:v][ovrl]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2; [1:v]drawtext=fontfile='C\:/Windows/Fonts/arial.ttf':fontsize=35:timecode='00\:00\:00\:00':r=24:x=10:y=10:fontcolor=white" -s 720x480 -c:v libx264 -preset ultrafast -crf 20 d:\encoded\%%~na.mp4 So the above works.. in that it creates the h.264 video, resolution AND the overlay. However I do NOT see the timecode. If you look, I have a [1:v] and the output shows that it is stream 1 along with the overlay, being stream 1. I am guessing that is wrong. When I try using [2:v] it gives me an error indicating index 2 is invalid. So I am a bit lost yet as to how to get both the overlay image and the timecode in one pass. I was hoping the [] indicating the layer, with 0 on the bottom, 1 above (overlayed) and so forth. I dont understand the filter_complex and using [1:v], [0:v], [ovr1], etc. I assumed 0 is the bottom layer, 1 the layer above, etc. I would assume then 0:v should be the main source file, where 1:v, 2:v, etc would be layer 1, 2, etc to overlay on top. I got enough errors to see that you can have inputs and outputs using labels.. and that [ovr1] is a label and used in the chain.. but that is about all I got. Somehow I got timecode for a few seconds, then the video ended abruptly.. in that i had the overlay AND a tiny text of timecode show up in upper left corner (that is where i want it so set x to 10, and y to 10. I cant seem to get that back now. So, I am able to get the overlayed image and the video, but no timecode shows up. On Sunday, February 25, 2018, 9:49:34 AM PST, Carl Zwanzig <cpz@tuunq.com> wrote: On 2/25/2018 12:38 AM, Kieran O Leary wrote:
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.
In a similar vein, I use tcl for this kind of scripting; highly portable when properly written and avoids most or all of the escaping problems of windows batch or *nix shell. z! _______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
On Tue, Feb 27, 2018 at 10:07 PM, Kevin Duffey <kevinmduffey-at-yahoo.com@ffmpeg.org> wrote:
Hi, thank you for the replies. So here is my current script, and ill past some output below that.
I don't see it..
participants (4)
-
Carl Zwanzig -
Kevin Duffey -
Kieran O Leary -
Reino Wijnsma