使用ffmpeg 设置水印的位置

水印在左上角:

ffmpeg -i gopro.mp4 -i 168-50.png -filter_complex "overlay=10:10" -codec:a copy output.mp4  

其中10:10 可以指定 x、y 坐标的位置

具体如下:

➜  Downloads ffmpeg -i gopro.mp4 -i 168-50.png -filter_complex "overlay=main_w-overlay_w-20:20" -codec:a copy output.mp4
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.38)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'gopro.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:04:13.98, start: 0.000000, bitrate: 2610 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2474 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, png_pipe, from '168-50.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 168x50 [SAR 5669:5669 DAR 84:25], 25 tbr, 25 tbn, 25 tbc
File 'output.mp4' already exists. Overwrite ? [y/N] y 输入 y 继续
[libx264 @ 0x7fbac900c400] using SAR=1/1
[libx264 @ 0x7fbac900c400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fbac900c400] profile High, level 3.1
[libx264 @ 0x7fbac900c400] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 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=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
    Metadata:
      encoder         : Lavc57.64.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 (h264) -> overlay:main
  Stream #1:0 (png) -> overlay:overlay
  overlay -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 7610 fps= 36 q=-1.0 Lsize=   77794kB time=00:04:13.93 bitrate=2509.7kbits/s speed=1.19x
video:73560kB audio:3970kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.340952%
[libx264 @ 0x7fbac900c400] frame I:125   Avg QP:19.08  size: 58060
[libx264 @ 0x7fbac900c400] frame P:2658  Avg QP:22.50  size: 15608
[libx264 @ 0x7fbac900c400] frame B:4827  Avg QP:24.71  size:  5507
[libx264 @ 0x7fbac900c400] consecutive B-frames:  6.7% 18.7% 22.4% 52.2%
[libx264 @ 0x7fbac900c400] mb I  I16..4: 23.2% 43.3% 33.5%
[libx264 @ 0x7fbac900c400] mb P  I16..4:  6.5% 15.0%  3.2%  P16..4: 32.5%  9.7%  3.8%  0.0%  0.0%    skip:29.3%
[libx264 @ 0x7fbac900c400] mb B  I16..4:  1.1%  2.6%  0.8%  B16..8: 31.4%  4.2%  0.8%  direct: 1.6%  skip:57.6%  L0:44.2% L1:49.6% BI: 6.2%
[libx264 @ 0x7fbac900c400] 8x8 transform intra:57.9% inter:64.8%
[libx264 @ 0x7fbac900c400] coded y,uvDC,uvAC intra: 41.4% 44.0% 9.7% inter: 8.7% 8.6% 0.4%
[libx264 @ 0x7fbac900c400] i16 v,h,dc,p: 19% 32% 13% 36%
[libx264 @ 0x7fbac900c400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 25% 24%  4%  5%  4%  6%  4%  6%
[libx264 @ 0x7fbac900c400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 23% 16%  6%  8%  7%  8%  5%  7%
[libx264 @ 0x7fbac900c400] i8c dc,h,v,p: 58% 23% 15%  5%
[libx264 @ 0x7fbac900c400] Weighted P-Frames: Y:8.4% UV:4.1%
[libx264 @ 0x7fbac900c400] ref P L0: 66.7% 18.0% 10.7%  4.3%  0.3%
[libx264 @ 0x7fbac900c400] ref B L0: 88.5%  9.6%  1.8%
[libx264 @ 0x7fbac900c400] ref B L1: 98.3%  1.7%
[libx264 @ 0x7fbac900c400] kb/s:2373.17

水印在右上角:

ffmpeg -i gopro.mp4 -i 168-50.png -filter_complex "overlay=main_w-overlay_w-10:10"  -codec:a copy output.mp4    

水印在左下角:

ffmpeg -i gopro.mp4 -i 168-50.png -filter_complex "overlay=10:main_h-overlay_h-10“  -codec:a copy output.mp4

水印在右下角:

ffmpeg -i gopro.mp4 -i 168-50.png -filter_complex "overlay=main_w-overlay_w-10:main_h-overlay_h-10“  -codec:a copy output.mp4

水印在中间:

ffmpeg -i gopro.mp4 -i 168-50.png -filter_complex "overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2“  -codec:a copy output.mp4

播放

➜  Downloads ffplay gopro.mp4
ffplay version 3.2.4 Copyright (c) 2003-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.38)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'gopro.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:04:13.98, start: 0.000000, bitrate: 2610 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2474 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
  12.36 A-V: -0.008 fd=  36 aq=   19KB vq=   69KB sq=    0B f=0/0

1