1

I want to have the watermark scaled to the same resolution as the output file. How do I do this? Alternatively, how do I center the watermark in the middle of the output instead?

Here is what I have:

ffmpeg -i input.mp4 -i watermark.png -filter_complex \
"[0:v]scale=min(640\, iw):-1[scaled]; \
 [scaled][1:v]overlay[scaledwatermarked]; \
 [scaledwatermarked]drawtext=fontfile=/path/to/FreeSans.ttf:text='TEST':\
 x=0:y=0[text]" -map "[text]" \
-vcodec libx264 output.mov

So I scale the input movie file using scale=min(640\, iw):-1, i.e., to a maximum of 640 pixels horizontally while keeping the aspect ratio of the input movie file. Then I add a watermark and then some text.

The watermark should be scaled to the same size as the output file, ignoring the resulting aspect ratio of the watermark file. It should be stretched or shrunk to fit the width and height of the output, ignoring the original aspect ratio of the watermark file. Using the above command, the watermarked file instead gets cut off instead of being scaled.

(From the command I have removed some quality, time code and audio options for clarity.)

Here is output from ffmpeg:

ffmpeg version 2.1.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Dec  7 2013 16:02:05 with gcc 4.2.1 (GCC) (Apple Inc. build 5577)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avresample --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libass --enable-libbluray --enable-gnutls --enable-libfreetype --disable-indev=jack --disable-outdev=xv --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=i386 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid --enable-nonfree --enable-libfaac
libavutil      52. 48.101 / 52. 48.101
libavcodec     55. 39.101 / 55. 39.101
libavformat    55. 19.104 / 55. 19.104
libavdevice    55.  5.100 / 55.  5.100
libavfilter     3. 90.100 /  3. 90.100
libavresample   1.  1.  0 /  1.  1.  0
libswscale      2.  5.101 /  2.  5.101
libswresample   0. 17.104 /  0. 17.104
libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp42mp41
    creation_time   : 2013-12-04 18:19:48
  Duration: 01:00:04.67, start: 0.000000, bitrate: 4182 kb/s
    Stream #0:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 3923 kb/s, 23.98 fps, 23.98 tbr, 2398 tbn, 1k tbc (default)
    Metadata:
      creation_time   : 2013-12-04 18:19:48
      handler_name    : Apple Video Media Handler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default)
    Metadata:
      creation_time   : 2013-12-04 18:19:48
      handler_name    : Apple Sound Media Handler
Input #1, image2, from 'watermark.png':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: png, rgba, 640x480 [SAR 2835:2835 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x300f620] using SAR=1/1
[libx264 @ 0x300f620] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
[libx264 @ 0x300f620] profile High, level 3.0
[libx264 @ 0x300f620] 264 - core 136 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=5000 vbv_bufsize=5000 crf_max=0.0 nal_hrd=none ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mov':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp42mp41
    encoder         : Lavf55.19.104
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, max. 5000 kb/s, 19184 tbn, 23.98 tbc (default)
Stream mapping:
  Stream #0:0 (mpeg4) -> scale
  Stream #1:0 (png) -> overlay:overlay
  drawtext -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
frame=  552 fps= 64 q=-1.0 Lsize=    5218kB time=00:00:22.93 bitrate=1863.8kbits/s
video:5211kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.140648%
[libx264 @ 0x300f620] frame I:5     Avg QP:17.84  size: 34541
[libx264 @ 0x300f620] frame P:144   Avg QP:19.27  size: 16691
[libx264 @ 0x300f620] frame B:403   Avg QP:21.00  size:  6846
[libx264 @ 0x300f620] consecutive B-frames:  1.3%  1.1%  9.2% 88.4%
[libx264 @ 0x300f620] mb I  I16..4: 37.9% 33.1% 29.0%
[libx264 @ 0x300f620] mb P  I16..4:  2.2%  6.8%  1.8%  P16..4: 30.8% 34.1% 20.4%  0.0%  0.0%    skip: 3.8%
[libx264 @ 0x300f620] mb B  I16..4:  0.7%  0.7%  0.2%  B16..8: 41.1% 19.1% 10.2%   direct:12.8%  skip:15.1%  L0:46.2% L1:43.9% BI: 9.9%
[libx264 @ 0x300f620] 8x8 transform intra:52.6% inter:31.2%
[libx264 @ 0x300f620] direct mvs  spatial:98.3% temporal:1.7%
[libx264 @ 0x300f620] coded y,uvDC,uvAC intra: 91.2% 85.9% 59.9% inter: 51.7% 33.6% 9.4%
[libx264 @ 0x300f620] i16 v,h,dc,p:  8% 34% 36% 22%
[libx264 @ 0x300f620] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  6% 19% 10%  8% 11%  9% 13%  8% 16%
[libx264 @ 0x300f620] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 15%  8%  8% 11% 11% 12% 10% 16%
[libx264 @ 0x300f620] i8c dc,h,v,p: 49% 31% 13%  7%
[libx264 @ 0x300f620] Weighted P-Frames: Y:4.9% UV:4.9%
[libx264 @ 0x300f620] ref P L0: 46.8% 13.7% 22.3%  8.1%  8.4%  0.6%  0.1%
[libx264 @ 0x300f620] ref B L0: 89.8%  7.1%  2.0%  1.0%
[libx264 @ 0x300f620] ref B L1: 98.5%  1.5%
[libx264 @ 0x300f620] kb/s:1854.19

Example:

The input.mp4 is 640x100. The watermark.png is 640x480. The output will be 640x100. How do I tell ffmpeg to scale the watermark.png to 640x100 instead of cutting it to 640x100?

Altnernatively, how do I tell ffmpeg to put the watermark.png at the center, i.e., with its center point at (320,50) in this example in the output file?

  • Have you looked at the scale2ref filter? – Ken Sharp Jan 30 '17 at 12:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.