使用 ffmpeg 显示多幅图像

使用 ffmpeg 显示多幅图像

我已经用带有背景图像的图像创建了一个视频幻灯片,但我希望能够在视频左下角添加另一张图片。

在此处输入图片描述 我怎样才能让 -i“C:/test/logo.png”显示在左下角。

这是以下 ffmpeg 命令。

    runtime = createObject("java", "java.lang.Runtime").getRuntime();
    command = '#ffmpegPath#' &
    ' -loop 1' &
    ' -framerate 1' &
    ' -i "C:/test/bg.jpg"' & 
    ' -framerate 1/5' &
    ' -i "C:/test/%03d.jpg"' & 
    ' -i "C:/test/logo.png"' & 
    ' -i "C:/test/music.mp3"' &
    ' -filter_complex' &
        ' "[1:v]drawbox=t=5:c=white[fg];[0:v][fg]overlay=(W-w)/2:(H-h)/2:shortest=1,' & 
        ' drawtext="fontsize=50:fontfile=/Windows/Fonts/arial.ttf:fontcolor=White:text=Eterni-T:x=(w-text_w)/2:y=40",' & 
        ' drawtext="fontsize=50:fontfile=/Windows/Fonts/arial.ttf:fontcolor=White:text="Laurence Collard (Simard) 1925-1999":x=w-text_w-10:y=h-text_h-10",' &
        ' drawbox=x=0:y=10:w=5000:h=100:[email protected]:t=50[bg];' &
        ' [bg][2:v]overlay=10:H-h-10,' &
        ' format=yuv420p[v]"' &
        ' -map "[v]"' &
    ' -c:v libx264' &
    ' -c:a aac -strict experimental' &
    ' -b:a 192k' &
    ' -r 30' &
    ' -movflags +faststart' &
    ' -shortest' &
    ' "C:/test/out.mp4"';

日志:

ffmpeg version N-69587-g15a8846 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
  libavutil      54. 18.100 / 54. 18.100
  libavcodec     56. 21.102 / 56. 21.102
  libavformat    56. 19.100 / 56. 19.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5.  9.103 /  5.  9.103
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, image2, from 'C:/test/bg.jpg':
  Duration: 00:00:01.00, start: 0.000000, bitrate: 1900 kb/s
    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1360 [SAR 1:1 DAR 24:17], 1 fps, 1 tbr, 1 tbn, 1 tbc
Input #1, image2, from 'C:/test/%03d.jpg':
  Duration: 00:00:15.00, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 540x800, 0.20 fps, 0.20 tbr, 0.20 tbn, 0.20 tbc
Input #2, png_pipe, from 'C:/test/logo.png':
  Duration: N/A, bitrate: N/A
    Stream #2:0: Video: png, rgba, 453x209, 25 tbr, 25 tbn, 25 tbc
[mp3 @ 0000000005039ee0] Estimating duration from bitrate, this may be inaccurate
Input #3, mp3, from 'C:/test/music.mp3':
  Duration: 00:02:18.40, start: 0.000000, bitrate: 224 kb/s
    Stream #3:0: Audio: mp3, 44100 Hz, stereo, s16p, 224 kb/s
Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (C:/test/out.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
[swscaler @ 00000000049c9000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 00000000049dbac0] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0000000004b386a0] using SAR=1/1
[libx264 @ 0000000004b386a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0000000004b386a0] profile High, level 5.0
[libx264 @ 0000000004b386a0] 264 - core 144 r2525 40bb568 - 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=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 'C:/test/out.mp4':
  Metadata:
    encoder         : Lavf56.19.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1360 [SAR 1:1 DAR 24:17], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc56.21.102 libx264
Stream mapping:
  Stream #0:0 (mjpeg) -> overlay:main
  Stream #1:0 (mjpeg) -> drawbox
  Stream #2:0 (png) -> overlay:overlay
  format -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
Input stream #1:0 frame changed from size:540x800 fmt:yuvj444p to size:1115x672 fmt:yuvj444p
[swscaler @ 0000000004bb3e20] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0000000004b1d640] deprecated pixel format used, make sure you did set range correctly
frame=  120 fps=0.0 q=29.0 size=     366kB time=00:00:02.06 bitrate=1450.0kbits/s dup=117 drop=0    
frame=  150 fps= 98 q=29.0 size=     369kB time=00:00:03.06 bitrate= 984.5kbits/s dup=146 drop=0    
frame=  180 fps= 74 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
Input stream #1:0 frame changed from size:1115x672 fmt:yuvj444p to size:1000x607 fmt:yuvj444p
[swscaler @ 0000000004bb3e20] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0000000006990ee0] deprecated pixel format used, make sure you did set range correctly
frame=  120 fps=0.0 q=29.0 size=     366kB time=00:00:02.06 bitrate=1450.0kbits/s dup=117 drop=0    
frame=  150 fps=100 q=29.0 size=     369kB time=00:00:03.06 bitrate= 984.5kbits/s dup=146 drop=0    
frame=  180 fps= 75 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
Input stream #1:0 frame changed from size:1115x672 fmt:yuvj444p to size:1000x607 fmt:yuvj444p
[swscaler @ 00000000050dc160] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0000000004c8ae80] deprecated pixel format used, make sure you did set range correctly
frame=  180 fps= 62 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 53 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 46 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 41 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 37 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 33 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 30 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 28 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 26 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 24 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 23 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 21 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 20 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 19 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 18 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 17 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    
frame=  180 fps= 17 q=29.0 size=     371kB time=00:00:04.06 bitrate= 747.9kbits/s dup=175 drop=0    

答案1

您只需添加另一个叠加过滤器。新的叠加过滤器将使用前一个叠加的输出以及徽标图像作为输入。

-loop 1 \
-framerate 1 \
-i logo.png \
-filter_complex \
"[1:v]drawbox=t=5:c=white[fg]; \
 [0:v][fg]overlay=(W-w)/2:(H-h)/2:shortest=1,drawtext=…,drawtext=…,drawbox=…[bg]; \
 [bg][2:v]overlay=10:H-h-10:shortest=1,format=yuv420p[v]" \
-map "[v]" \
-map 3:a \
  • 我替换了每个过滤器的一些选项,以便您可以直观地看到过滤图更轻松。

  • 此示例假设徽标图像文件为[2:v];第三个视频输入(ffmpeg从 0 开始计数)。我还使徽标文件循环,否则如果您的输入更改属性(帧大小、像素格式等),第二个覆盖可能会无限期编码。

  • shortest=1由于您的徽标图像未设置为循环,因此未包含在第二个覆盖中,但我认为它仍然可以工作。

  • 我倾向于使用format=yuv420p最后一个,所以我将其从第一个覆盖层中移除,并将其放在滤镜图的末尾。或者,您可以format=yuv420p完全移除并使用-pix_fmt yuv420p滤镜图之外的选项,但我喜欢format在过滤时使用它,这样我就可以更好地控制。

相关内容