ffmpeg:带边距的水印图像缩放

ffmpeg:带边距的水印图像缩放

我第一次使用 ffmpeg,在给视频添加水印时遇到了一些问题。

我使用以下命令成功完成了该任务:

ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=main_w-overlay_w-10:10" -codec:a copy out.mp4

现在的问题是,我为不同的视频获得了不同分辨率的水印图像,但我想为每个视频(视频是高分辨率或低分辨率)修复 100x100 分辨率或具有相应分辨率的水印。

我尝试过一些命令,但遇到了问题:

使用此命令我得到了输出但其视频尺寸增加了一倍:

ffmpeg -i video.mp4 -i logo.png -filter_complex "[1:v]scale=100:100[v1];[0:v][v1]overlay=main_w-overlay_w-10:10" out.mp4

输出:

ffmpeg version N-94664-g0821bc4eee Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.1.1 (GCC) 20190807
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 33.100 / 56. 33.100
  libavcodec     58. 55.101 / 58. 55.101
  libavformat    58. 31.104 / 58. 31.104
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 58.101 /  7. 58.101
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.31.104
  Duration: 00:01:42.04, start: 0.000000, bitrate: 460 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1080x1920 [SAR 1:1 DAR 9:16], 458 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #1, png_pipe, from 'logo.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 119x129 [SAR 11811:11811 DAR 119:129], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 (h264) -> overlay:main
  Stream #1:0 (png) -> scale
  overlay -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 00000200b937d500] using SAR=1/1
[libx264 @ 00000200b937d500] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000200b937d500] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 00000200b937d500] 264 - core 158 r2984 3759fcb - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - 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=18 lookahead_threads=3 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 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.31.104
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1080x1920 [SAR 1:1 DAR 9:16], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc58.55.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: 18446744073709551615
frame= 2551 fps=123 q=-1.0 Lsize=    5288kB time=00:01:41.92 bitrate= 425.0kbits/s speed=4.91x
video:5259kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.543195%
[libx264 @ 00000200b937d500] frame I:12    Avg QP:13.83  size: 62825
[libx264 @ 00000200b937d500] frame P:961   Avg QP:18.60  size:  3922
[libx264 @ 00000200b937d500] frame B:1578  Avg QP:16.49  size:   546
[libx264 @ 00000200b937d500] consecutive B-frames: 12.9% 11.3%  7.8% 68.1%
[libx264 @ 00000200b937d500] mb I  I16..4: 51.2% 31.8% 17.0%
[libx264 @ 00000200b937d500] mb P  I16..4:  2.6%  3.4%  0.4%  P16..4:  4.8%  0.7%  0.5%  0.0%  0.0%    skip:87.6%
[libx264 @ 00000200b937d500] mb B  I16..4:  0.2%  0.1%  0.0%  B16..8:  5.2%  0.2%  0.0%  direct: 0.0%  skip:94.4%  L0:54.0% L1:44.6% BI: 1.4%
[libx264 @ 00000200b937d500] 8x8 transform intra:48.4% inter:48.1%
[libx264 @ 00000200b937d500] coded y,uvDC,uvAC intra: 8.3% 8.6% 5.6% inter: 0.7% 0.4% 0.2%
[libx264 @ 00000200b937d500] i16 v,h,dc,p: 51% 47%  2%  0%
[libx264 @ 00000200b937d500] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 46% 16% 35%  0%  0%  0%  0%  0%  1%
[libx264 @ 00000200b937d500] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 24% 18%  3%  4%  4%  4%  4%  4%
[libx264 @ 00000200b937d500] i8c dc,h,v,p: 81% 13%  6%  0%
[libx264 @ 00000200b937d500] Weighted P-Frames: Y:1.9% UV:1.9%
[libx264 @ 00000200b937d500] ref P L0: 75.4%  6.4% 13.4%  4.7%  0.0%
[libx264 @ 00000200b937d500] ref B L0: 71.2% 26.3%  2.6%
[libx264 @ 00000200b937d500] ref B L1: 97.7%  2.3%
[libx264 @ 00000200b937d500] kb/s:422.18

我找到了一个解决方案这里可以缩放徽标尺寸,但我得到的是徽标左上角无边距

ffmpeg -i inputvideo.mp4 -i watermarklogo.png -filter_complex "\
[1:v]scale=200:100[v1];[0:v][v1]overlay[outv]
\" -map "[outv]" output.mp4

有人可以帮忙吗?

答案1

使用

ffmpeg -i inputvideo.mp4 -i watermarklogo.png -filter_complex “[1:v]scale=200:100[v1];[0:v][v1]overlay=10:main_h-覆盖-10[outv]”-map“[outv]”输出.mp4

例如,10像素是左下角边距。

相关内容