在使用 ffmpeg 淡入覆盖时如何避免出现黑色背景?

在使用 ffmpeg 淡入覆盖时如何避免出现黑色背景?

我正在使用 ffmpeg 从非透明图像(例如没有 alpha 通道的 JPEG 或 PNG)中淡入覆盖:

$ ffmpeg -i big_buck_bunny_480p_surround-fix.avi -loop 1 -i logo.png \
-filter_complex "[1:v] fade=t=in:st=3:alpha=1 [logo]; \
[0:v][logo] overlay [outv]" \
-map "[outv]" -map 0:a -pix_fmt yuv420p -f matroska - | ffplay -

输出:

ffmpeg version 2.5.3 Copyright (c) 2000-2015 the FFmpeg developers
  built on Feb 12 2015 19:55:48 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfontconfig --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-openssl --enable-libopus --enable-frei0r --enable-libcaca --enable-libsoxr --enable-libquvi --enable-libvidstab --enable-libx265 --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 ' --enable-nonfree --enable-vda
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.102 / 56. 15.102
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, avi, from 'big_buck_bunny_480p_surround-fix.avi':
  Duration: 00:09:56.46, start: 0.000000, bitrate: 2957 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 2500 kb/s, 24 fps, 24 tbr, 24 tbn, 24 tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
ffplay version 2.5.3 Copyright (c) 2003-2015 the FFmpeg developers
  built on Feb 12 2015 19:55:48 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfontconfig --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-openssl --enable-libopus --enable-frei0r --enable-libcaca --enable-libsoxr --enable-libquvi --enable-libvidstab --enable-libx265 --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 ' --enable-nonfree --enable-vda
Input #1, png_pipe, from 'logo.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgb24, 400x300 [SAR 11811:11811 DAR 4:3],   libavutil      54. 15.100 / 54. 15.100
25 fps,   libavcodec     56. 13.100 / 56. 13.100
25 tbr, 25 tbn,   libavformat    56. 15.102 / 56. 15.102
25 tbc
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
[libx264 @ 0x7fa83d009200] using SAR=1/1
[libx264 @ 0x7fa83d009200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fa83d009200] profile High, level 3.0
[libx264 @ 0x7fa83d009200] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=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=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 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, matroska, to 'pipe:':   0KB vq=    0KB sq=    0B f=0/0
  Metadata:
    encoder         : Lavf56.15.102
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 854x480 [SAR 1:1 DAR 427:240], q=-1--1, 24 fps, 1k tbn, 24 tbc (default)
    Metadata:
      encoder         : Lavc56.13.100 libx264
    Stream #0:1: Audio: vorbis (libvorbis) (oV[0][0] / 0x566F), 48000 Hz, 5.1(side), fltp
    Metadata:
      encoder         : Lavc56.13.100 libvorbis
Stream mapping:
  Stream #0:0 (mpeg4) -> overlay:main (graph 0)
  Stream #1:0 (png) -> fade (graph 0)
  overlay (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (ac3 (native) -> vorbis (libvorbis))
Press [q] to stop, [?] for help

但是,徽标背景在淡入之前是黑色的。我已经设置了淡入淡出alpha=1,但是它不起作用。

我怎样才能避免这种情况?

答案1

一个解决方案就是改变覆盖流的内部格式以包含 alpha 通道。

为此,请使用format筛选

-filter_complex \
"[1:v]格式=pix_fmts=yuva420p, 淡入淡出=t=in:st=3:alpha=1 [标志]; \
[0:v][logo] 覆盖 [outv]”

该解决方案还向后兼容包含 alpha 通道的输入。

相关内容