ffmpeg 淡入淡出幻灯片,图像尺寸没有减小

ffmpeg 淡入淡出幻灯片,图像尺寸没有减小

我有一个淡入淡出 ffmpeg 幻灯片,试图结合提供的两个示例这里

ffmpeg \
-loop 1 -t 5 -i 1.jpg \
-loop 1 -t 5 -i 2.png \
-loop 1 -t 5 -i 3.png \
-loop 1 -t 5 -i 4.png \
-loop 1 -t 5 -i 5.png \
-filter_complex \
"[1]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \
 [2]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \
 [3]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f2]; \
 [4]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+16/TB[f3]; \
 [0][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3]; \
 [bg3][f3]overlay,format=yuv420p[v]" -map "[v]" -movflags +faststart out.mp4

但是,如果其中一个图像(例如 input0.jpg)大于 1920x1080,则视频大小会增加以匹配,这似乎是在忽略force_original_aspect_ratio=decrease

我该如何解决这个问题,以便较大的图像不会增加视频大小?

这是不同组图像的输出,但发生了同样的问题:

$ bash mov.sh 
ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, image2, from '1.jpeg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 11071 kb/s
    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1000x1250 [SAR 72:72 DAR 4:5], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, image2, from '2.jpeg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 1845 kb/s
    Stream #1:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 251x201 [SAR 1:1 DAR 251:201], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #2, image2, from '3.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 76927 kb/s
    Stream #2:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 2000x1125 [SAR 96:96 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #3, image2, from '4.jpeg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 1882 kb/s
    Stream #3:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 300x168 [SAR 1:1 DAR 25:14], 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #4, image2, from '5.jpeg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 1458 kb/s
    Stream #4:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 300x168 [SAR 1:1 DAR 25:14], 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 (mjpeg) -> overlay:main
  Stream #1:0 (mjpeg) -> scale
  Stream #2:0 (mjpeg) -> scale
  Stream #3:0 (mjpeg) -> scale
  Stream #4:0 (mjpeg) -> scale
  format -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[swscaler @ 0x55cd71e74fc0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55cd71ea83c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55cd71f2c4a0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55cd71fc9a40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55cd72058500] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55cd71ea83c0] Warning: data is not aligned! This can lead to a speed loss
[libx264 @ 0x55cd71b82140] using SAR=1/1
[libx264 @ 0x55cd71b82140] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55cd71b82140] profile High, level 3.2
[libx264 @ 0x55cd71b82140] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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=6 lookahead_threads=1 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:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1000x1250 [SAR 1:1 DAR 4:5], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc57.107.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=   40 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   51 fps= 49 q=28.0 size=       0kB time=-00:00:00.07 bitrate=N/A speed=Nframe=   96 fps= 63 q=28.0 size=       0kB time=00:00:01.72 bitrate=   0.2kbits/frame=  127 fps= 62 q=28.0 size=       0kB time=00:00:02.96 bitrate=   0.1kbits/frame=  164 fps= 64 q=28.0 size=       0kB time=00:00:04.44 bitrate=   0.1kbits/frame=  202 fps= 66 q=28.0 size=       0kB time=00:00:05.96 bitrate=   0.1kbits/frame=  213 fps= 59 q=28.0 size=       0kB time=00:00:06.40 bitrate=   0.1kbits/frame=  225 fps= 55 q=28.0 size=       0kB time=00:00:06.88 bitrate=   0.1kbits/frame=  243 fps= 53 q=28.0 size=       0kB time=00:00:07.60 bitrate=   0.1kbits/frame=  259 fps= 50 q=28.0 size=     256kB time=00:00:08.24 bitrate= 254.6kbits/frame=  275 fps= 49 q=28.0 size=     512kB time=00:00:08.88 bitrate= 472.4kbits/frame=  292 fps= 47 q=28.0 size=     512kB time=00:00:09.56 bitrate= 438.8kbits/frame=  306 fps= 46 q=28.0 size=     512kB time=00:00:10.12 bitrate= 414.5kbits/frame=  318 fps= 44 q=28.0 size=     512kB time=00:00:10.60 bitrate= 395.7kbits/frame=  341 fps= 44 q=28.0 size=     512kB time=00:00:11.52 bitrate= 364.1kbits/frame=  366 fps= 44 q=28.0 size=     768kB time=00:00:12.52 bitrate= 502.5kbits/frame=  398 fps= 45 q=28.0 size=     768kB time=00:00:13.80 bitrate= 455.9kbits/frame=  420 fps= 45 q=28.0 size=     768kB time=00:00:14.68 bitrate= 428.6kbits/frame=  454 fps= 46 q=28.0 size=    1024kB time=00:00:16.04 bitrate= 523.0kbits/frame=  486 fps= 47 q=28.0 size=    1024kB time=00:00:17.32 bitrate= 484.4kbits/[mp4 @ 0x55cd71b7f780] Starting second pass: moving the moov atom to the beginning of the file
frame=  525 fps= 48 q=-1.0 Lsize=    1254kB time=00:00:20.88 bitrate= 491.8kbits/s speed=1.91x    
video:1247kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.558540%
[libx264 @ 0x55cd71b82140] frame I:3     Avg QP:11.75  size: 86794
[libx264 @ 0x55cd71b82140] frame P:137   Avg QP:16.58  size:  6656
[libx264 @ 0x55cd71b82140] frame B:385   Avg QP:21.56  size:   269
[libx264 @ 0x55cd71b82140] consecutive B-frames:  1.7%  1.1%  1.1% 96.0%
[libx264 @ 0x55cd71b82140] mb I  I16..4: 29.9% 58.3% 11.8%
[libx264 @ 0x55cd71b82140] mb P  I16..4:  2.7%  8.5%  0.5%  P16..4:  7.6%  1.9%  1.0%  0.0%  0.0%    skip:77.8%
[libx264 @ 0x55cd71b82140] mb B  I16..4:  0.4%  0.2%  0.0%  B16..8:  1.9%  0.0%  0.0%  direct: 1.0%  skip:96.6%  L0:25.0% L1:68.5% BI: 6.5%
[libx264 @ 0x55cd71b82140] 8x8 transform intra:66.3% inter:81.2%
[libx264 @ 0x55cd71b82140] coded y,uvDC,uvAC intra: 32.3% 41.8% 17.9% inter: 1.6% 3.2% 0.2%
[libx264 @ 0x55cd71b82140] i16 v,h,dc,p: 52% 18%  5% 25%
[libx264 @ 0x55cd71b82140] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 18% 36%  3%  5%  4%  5%  4%  4%
[libx264 @ 0x55cd71b82140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 23% 11%  6% 10%  7%  7%  7%  5%
[libx264 @ 0x55cd71b82140] i8c dc,h,v,p: 65% 16% 10%  8%
[libx264 @ 0x55cd71b82140] Weighted P-Frames: Y:16.8% UV:16.1%
[libx264 @ 0x55cd71b82140] ref P L0: 63.1% 15.4% 20.2%  1.0%  0.2%
[libx264 @ 0x55cd71b82140] ref B L0: 68.3% 28.5%  3.2%
[libx264 @ 0x55cd71b82140] ref B L1: 97.6%  2.4%e
[libx264 @ 0x55cd71b82140] kb/s:486.04

这是生成的视频。请注意,第一张图片似乎定义了视频的尺寸,而不是调整为 1920x 1080px。

https://streamable.com/xnegp

答案1

您正在缩放输入 1–4,但不会缩放输入 0,其格式为 1000x1250。因此,您的输出将是该大小。

如果您希望将输出限制为 1920⨉1080,请scale为输入插入一个过滤器[0],例如:

ffmpeg \
-loop 1 -t 5 -i 1.jpg \
-loop 1 -t 5 -i 2.png \
-loop 1 -t 5 -i 3.png \
-loop 1 -t 5 -i 4.png \
-loop 1 -t 5 -i 5.png \
-filter_complex \
"[0]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p[bg]; \
 [1]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \
 [2]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \
 [3]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f2]; \
 [4]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+16/TB[f3]; \
 [bg][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3]; \
 [bg3][f3]overlay,format=yuv420p[v]" -map "[v]" -movflags +faststart out.mp4

相关内容