VideoHelp Forum
+ Reply to Thread
Results 1 to 11 of 11
Thread
  1. Member
    Join Date: Oct 2013
    Location: India
    Search PM
    I am using drawtext to add watermark to videos
    Code:
    -vf drawtext="fontsize=15:fontfile=FreeSerif.ttf:text=hello::ontcolor=white:shadowcolor=black:shadowx=1:shadowy=1:x=w-tw-2:y=h-th-2
    The problem is with watermark size.. It changes itself according to the original video resolution.
    For Ex: A watermark with fontsize of 20 looks too large when a original video with small resolution is converted and looks too small when original video with large resolution is converted..
    How to fix this size ??
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date: Jul 2012
    Location: NORTHWEST ILLINOIS, USA
    Search Comp PM
    That is because using the same size font in higher resolution is like when you change your desktop resolution. The higher you go the smaller the Icon letters become so 1280x720 has smaller letters than 640x480. Since you increase the number of number of pixels with higher resolution in the same space, the fonts appear smaller. I'm sure there is a much better explanation but the simplest method is increase the font size as a proportion of your resolution.

    In the photos below I picked a Font of 15 size that looked good in 640x360 then used the same font in 1280x720 and then 30 Font size with 1280x720. You can see the 30 font (1280x720) and the 15 font (640x360) appear almost the same size. You just need to pick one that looks good at a certain resolution and then adjust per the difference as "New Size = FontSizeyouLiked x NewResolution / ResolutionYouLiked"

    Name:  1280x720_15.jpg
Views: 185
Size:  12.0 KB
    1280x720 Font size 15

    Name:  640x360_15.jpg
Views: 186
Size:  16.8 KB
    640x360 Font Size 15

    Name:  1280x720_30.jpg
Views: 185
Size:  9.7 KB
    1280x720 Font Size 30 (Image Size reduced by 1/2)
    Quote Quote  
  3. Member
    Join Date: Oct 2013
    Location: India
    Search PM
    Actually i don't want to input different font sizes for each video.. I want to make it stable for each resolution.. Is there any way to make it stable ?
    Quote Quote  
  4. Member
    Join Date: Jun 2012
    Location: USA
    Search Comp PM
    Instead of setting the font size as a constant, set is as a calculated percentage of the height or width. (I've never done it but ffmpeg is pretty flexible and it should be possible.)
    Quote Quote  
  5. Member Budman1's Avatar
    Join Date: Jul 2012
    Location: NORTHWEST ILLINOIS, USA
    Search Comp PM
    I've been trying to calculate it but for some reason my ffmpeg drawtext doesn't seem to understand:
    ffmpeg -i <video.mp4> -vf drawtext="fontsize=15*main_h/640:fontfile=FreeSerif.ttf:text=hello\\::fontcolor=white: shadowcolor=black: shadowx=1: shadowy=1: x=w-tw-2: y=h-th-2"
    Keep getting a missing '(' error message. Unless someone knows how to enter it correctly but I haven't been able to find an example of using main_h, h.
    Last edited by Budman1; 17th Feb 2014 at 13:45.
    Quote Quote  
  6. Member
    Join Date: Oct 2013
    Location: India
    Search PM
    It would be very helpful if my issue gets solved.. You can see drawtext examples at ffmpeg drawtext documentation and help me if you find anything useful.
    Quote Quote  
  7. Looking at the output of
    Code:
    ffplay -i "F:\TestClips&Co\test.avi" -vf drawtext="fontsize=15*main_h/640:fontfile=FreeSerif.ttf:text='hello':fontcolor=white:shadowcolor=black:shadowx=1:shadowy=1:x=w-tw-2:y=h-th-2"
    output:
    Code:
    [drawtext @ 00000000092c7d60] [Eval @ 0000000008a9f2a0] Undefined constant or missing '(' in 'main_h/640'
    [drawtext @ 00000000092c7d60] Unable to parse option value "15*main_h/640"
    [drawtext @ 00000000092c7d60] [Eval @ 0000000008a9f310] Undefined constant or missing '(' in 'main_h/640'
    [drawtext @ 00000000092c7d60] Unable to parse option value "15*main_h/640"
    [drawtext @ 00000000092c7d60] Error setting option fontsize to value 15*main_h/640.
    [Parsed_drawtext_0 @ 000000000277ede0] Error applying options to the filter.
    Error initializing filter 'drawtext' with args 'fontsize=15*main_h/640:fontfile=FreeSerif.ttf:text=hello:fontcolor=white:shadowcolor=black:shadowx=1:shadowy=1:x=w-tw-2:y=h-th-2'
    it seems like ffmpeg doesn't support calculating the fontsize,...
    -> may be asking in the ffmpeg irc channel will help

    Cu Selur

    Ps.: as a side note, just for consitency I would either use 'h' or 'main_h' to address the height of the input not both (just makes the whole think more confusing), also shrinking the call a bit when trying to find the problem isn't a bad idea either,...
    That said, even if I use just:
    Code:
    ffplay -i "F:\TestClips&Co\test.avi" -vf drawtext="fontsize=15*main_h/640:text='hello'"
    the error stays the same, which is why I suspect that what you want isn't simply supported in ffmpeg
    Last edited by Selur; 18th Feb 2014 at 15:13.
    Quote Quote  
  8. Member Budman1's Avatar
    Join Date: Jul 2012
    Location: NORTHWEST ILLINOIS, USA
    Search Comp PM
    I agree... GUI ability yes... CLI not so much... Is there a large demand for this?

    UPDATE: apparently, after reading more, variables such as main_h, etc. are only used for calculating x and y such as :
    x=(w-text_w)/2:y=(h-text_h-line_h)/2

    So, again, it looks like an intermediate utility or program is needed to interrogate the video characteristics. Font will correctly calculate such as , 'fontsize=15*2'. or 'fontsize=15*1280/640' but without knowing the 640/1280/320/xxx it can't be plugged in unless all the videos are the same size. It is possible but you'd need a program that reads the MediaInfo CLI processes output and then creates the script. Something like :

    Name:  ScreenHunter_58 Feb. 18 22.51.jpg
Views: 119
Size:  43.7 KB
    Last edited by Budman1; 18th Feb 2014 at 22:53. Reason: Updated information
    Quote Quote  
  9. Member
    Join Date: Oct 2013
    Location: India
    Search PM
    Is there any alternative for adding the watermark without any issues regarding the size ?
    Quote Quote  
  10. first alternatives that pop to mind:
    • write a batch file (shell script) to analyse the file to get the resolution and then call ffmpeg with the parameters you want
    • use Avisynths Subtitle-function (should be easily possible with in example MeGui)
      I thought about adding something similar to Hybrid but dropped it since I wanted a ffmpeg&mencoder solution and dropped it after I realized I can't do something like this with mencoder.
    • if the images all have the same aspect ratio: create a transparent image which has the correct size matching the largest resolution you encounter; load the normal source and the image with ffmpeg overlay the image over the movie and scale the image to the movie size
    • find some one who writes you a small tool which does what you want (or modifies an existing tool)
    • post a feature request to the ffmpeg bug tracker and hope that someone finds the time and has interest to implement this
    Quote Quote  
  11. Member Budman1's Avatar
    Join Date: Jul 2012
    Location: NORTHWEST ILLINOIS, USA
    Search Comp PM
    All good suggestions, especially:

    •find some one who writes you a small tool which does what you want (or modifies an existing tool)
    Noticing my earlier post, I already did half of what you want with a GUI that ran MediaInfo and output the results and can locate the specific items you need to build a string for ffmpeg and run in the same Window. That is why I asked:

    Is there a large demand for this?
    since it would take a few days to do exactly what you want and really would not be worth the time for a one time use on say 10 files...

    I assume you wish to select a FOLDER and convert ALL videos in it, REGARDLESS of their resolution, and convert to their ORIGINAL resolution ALL using the SAME codec?

    If this is not true (the videos are all the same size) then the result is easy since you simply find a resolution that a certain Fontsize looks good. Let's say 640x480 looks good with Fontsize 16. If the videos are all the same resolution, say 720, then your font size would be 'Fontsize=16x720/480' because 720/480 is 1.5 so the Font size would be raised to 24 (16*1.5) and would look proportionally the same size.

    Update: and yes the Fontsize will calculate without variables.
    Quote Quote  



Similar Threads