使用 FFMPEG 混合透明 FLV 视频和背景图像

使用 FFMPEG 混合透明 FLV 视频和背景图像

我很难将背景 png 与透明 flv 混合。我使用 filter_complex 缩放和裁剪 flv 视频,然后我想将其叠加在背景 png 上。

当我将 png 设置为叠加滤镜中的第一个输入并将其置于背景中时,我收到错误,结果是视频中只有 png 和视频中的音频。这是我的命令 + 完整输出:

iMacBert:test bert$ ffmpeg -i test.flv -i test.png -filter_complex '[0:v]scale=max(552\, 420*iw/ih):-1[OUT1]; [OUT1]crop=552:420[OUT2];[1:v][OUT2]overlay[out]' -map [out] -map 0:a -t 00:00:10 -s 552x420 out.mp4
ffmpeg version 1.1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar  4 2013 11:19:29 with Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
  configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libfreetype --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid --enable-nonfree --enable-libfaac
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 86.100 / 54. 86.100
  libavformat    54. 59.106 / 54. 59.106
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 32.100 /  3. 32.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, flv, from 'test.flv':
  Metadata:
    audiodelay      : 0
    canSeekToEnd    : true
  Duration: 00:00:41.48, start: 0.000000, bitrate: 6444 kb/s
    Stream #0:0: Video: vp6a, yuva420p, 1920x1080, 10240 kb/s, 25 tbr, 1k tbn, 1k tbc
    Stream #0:1: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
Input #1, image2, from 'test.png':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: png, rgba, 552x420 [SAR 2835:2835 DAR 46:35], 25 tbr, 25 tbn, 25 tbc
File 'out.mp4' already exists. Overwrite ? [y/N] y
using SAR=1/1
[libx264 @ 0x7fe10b042a00] using cpu capabilities: none!
[libx264 @ 0x7fe10b042a00] profile High, level 3.0
[libx264 @ 0x7fe10b042a00] 264 - core 128 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - 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=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:
    audiodelay      : 0
    canSeekToEnd    : true
    encoder         : Lavf54.59.106
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 552x420 [SAR 1:1 DAR 46:35], q=-1--1, 12800 tbn, 25 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s
Stream mapping:
  Stream #0:0 (vp6a) -> scale (graph 0)
  Stream #1:0 (png) -> overlay:main (graph 0)
  overlay (graph 0) -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (mp3 -> libfaac)
Press [q] to stop, [?] for help
[Parsed_overlay_2 @ 0x7fe10ac1e680] Buffer queue overflow, dropping.
    Last message repeated 14 times
Buffer queue overflow, dropping.      0kB time=00:00:01.81 bitrate=   0.2kbits/s    
[Parsed_overlay_2 @ 0x7fe10ac1e680] Buffer queue overflow, dropping.
    Last message repeated 47 times
Buffer queue overflow, dropping.      0kB time=00:00:03.76 bitrate=   0.1kbits/s    
[Parsed_overlay_2 @ 0x7fe10ac1e680] Buffer queue overflow, dropping.
    Last message repeated 50 times
Buffer queue overflow, dropping.      0kB time=00:00:05.85 bitrate=   0.1kbits/s    
[Parsed_overlay_2 @ 0x7fe10ac1e680] Buffer queue overflow, dropping.
    Last message repeated 50 times
Buffer queue overflow, dropping.      0kB time=00:00:07.91 bitrate=   0.0kbits/s    
[Parsed_overlay_2 @ 0x7fe10ac1e680] Buffer queue overflow, dropping.
    Last message repeated 48 times
frame=    1 fps=0.4 q=28.0 Lsize=     162kB time=00:00:10.00 bitrate= 132.4kbits/s    
video:2kB audio:156kB subtitle:0 global headers:0kB muxing overhead 1.862288%
[libx264 @ 0x7fe10b042a00] frame I:1     Avg QP:26.10  size:  1776
[libx264 @ 0x7fe10b042a00] mb I  I16..4: 61.4% 35.3%  3.3%
[libx264 @ 0x7fe10b042a00] 8x8 transform intra:35.3%
[libx264 @ 0x7fe10b042a00] coded y,uvDC,uvAC intra: 18.6% 13.4% 2.2%
[libx264 @ 0x7fe10b042a00] i16 v,h,dc,p: 65% 23%  1% 11%
[libx264 @ 0x7fe10b042a00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 29% 23%  5%  3%  3%  4%  2%  4%
[libx264 @ 0x7fe10b042a00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 64% 16%  0%  0%  0%  0%  0%  1%
[libx264 @ 0x7fe10b042a00] i8c dc,h,v,p: 72% 19%  9%  0%
[libx264 @ 0x7fe10b042a00] kb/s:355.20

奇怪的是,当我把它放在前台时,通过将其设置为第二个参数,我没有收到错误,但这不是我想要实现的,图像必须在背景中。

有人有解决方案吗?

这是我的命令,经过自动换行处理,更加容易阅读:

ffmpeg -i test.flv -i test.png -filter_complex '[0:v]scale=max(552\, 420*iw/ih):-1[OUT1]; [OUT1]crop=552:420[OUT2];[1:v][OUT2]overlay[out]' -map [out] -map 0:a -t 00:00:10 -s 552x420 out.mp4

答案1

您必须循环播放 PNG 文件,因为您遇到了Buffer queue overflow, dropping.错误。

ffmpeg -i test.flv -loop 1 -i test.png -filter_complex '[0:v]scale=max(552\, 420*iw/ih):-1[OUT1]; [OUT1]crop=552:420[OUT2];[1:v][OUT2]overlay[out]' -map [out] -map 0:a -t 00:00:10 out.mp4

如果这不起作用,则与框架大小有关。这个 Stack Overflow 问题可能也会对你有所帮助:将两个视频叠加到静态图像上

相关内容