【问题标题】:ffmpeg add semi transparent watermark(png) with different sizeffmpeg添加不同大小的半透明水印(png)
【发布时间】:2017-01-28 05:39:10
【问题描述】:

我正在尝试在半透明的 h264 视频上添加 png 水印(带 alpha 通道)。通过使用叠加过滤器,我设法为视频添加了水印。

ffmpeg -y -i input.mp4 -i watermark.png -filter_complex "[0][1] overlay=0:0" -c:v libx264 -an output.mp4

但覆盖过滤器不提供透明选项。所以我尝试使用混合过滤器。但是,当我使用原点解析时,会出现错误消息。

ffmpeg -y -i input.mp4 -i watermark.png -filter_complex "[0][1]blend=all_mode=overlay:all_opacity=0.3" -c:v libx264 -an output.mp4

输出:

  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
  Duration: 00:00:45.08, start: 0.000000, bitrate: 1872 kb/s
    Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 1869 kb/s, 29.72 fps, 30 tbr, 16k tbn, 32k tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #1, png_pipe, from 'watermark.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 64x64, 25 tbr, 25 tbn, 25 tbc
[Parsed_blend_0 @ 00750600] First input link top parameters (size 1920x1080, SAR 0:1) do not match the corresponding second input link bottom parameters (64x64, SAR 0:1)
[Parsed_blend_0 @ 00750600] Failed to configure output pad on Parsed_blend_0
Error configuring complex filters.
Invalid argument

结果看起来像是参数的一些分辨率问题。所以我尝试在混合之前缩放水印。

ffmpeg -y -i input.mp4 -i watermark.png -filter_complex "[0:0]scale=1920x1080[a]; [1:0]scale=1920x1080[b]; [a][b]blend=all_mode=overlay:all_opacity=0.3" -c:v libx264 -an output.mp4

FFMPEG 使用这些参数。但是输出不是我所期望的,因为水印已经被拉伸了。 有什么想法可以混合不同分辨率的水印而不拉伸到具有透明度的视频?

这里是测试文件。 (ffmpeg 版本 3.1.2) https://drive.google.com/open?id=0B2X3VLS01TogdHVJZ2I1ZC1GUUU https://drive.google.com/open?id=0B2X3VLS01TogbjhuZTlBOFFpN1k

【问题讨论】:

  • 对于其他人,为了降低叠加水印的不透明度,我只是编辑了 .png,将其降低到 50% 的不透明度,将其重新保存为 .png 并使用它。效果很好

标签: filter ffmpeg transparency blend


【解决方案1】:

Logo 相对于 image 大小 v1(居中)缩放

ffmpeg -y \
-i "bird.jpg" \
-i "logo.png" \
-filter_complex "\
[1][0]scale2ref=h=ow/mdar:w=iw/4[#A logo][bird];\
[#A logo]format=argb,colorchannelmixer=aa=0.5[#B logo transparent];\
[bird][#B logo transparent]overlay\
=(main_w-w)/2:(main_h-h)/2" \
image_with_logo.jpg

#A preserve aspect ratio of logo, scale width of logo to 1/4 of image width
#B add alpha channel, reduce opacity to 50%
# overlay image an logo
#position is horizontally and vertically centered

Logo 相对于 image 大小 v2 缩放(右下角有边距)

ffmpeg -y \
-i "bird.jpg" \
-i "logo.png" \
-filter_complex "\
[1][0]scale2ref=h=ow/mdar:w=iw/4[#A logo][bird];\
[#A logo]format=argb,colorchannelmixer=aa=0.5[#B logo transparent];\
[bird][#B logo transparent]overlay\
=(main_w-w)-(main_w*0.1):(main_h-h)-(main_h*0.1)" \
image_with_logo.jpg

#A preserve aspect ratio of logo, scale width of logo to 1/4 of image width
#B add alpha channel, reduce opacity to 50%
# overlay image an logo
# position: bottom right, with a margin of 10% of the edges

【讨论】:

    【解决方案2】:

    在叠加之前使用 lut 滤镜

    ffmpeg -y -i input.mp4 -i watermark.png -filter_complex 
              "[1]lut=a=val*0.3[a];[0][a]overlay=0:0"
           -c:v libx264 -an output.mp4
    

    【讨论】:

    • 非常感谢。这对我很有帮助。
    猜你喜欢
    • 2023-04-08
    • 1970-01-01
    • 2012-09-15
    • 2021-07-15
    • 2012-06-10
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    相关资源
    最近更新 更多