用户将选择多个 gif,缩放它们,将它们放置在屏幕上的所需位置,然后将它们叠加在视频之上。
在简单的情况下,用户只选择一张 gif 来叠加...这行代码对我来说工作得很好,但是现在它永远运行!!:
'-i video.mp4 -ignore_loop 0 -i gif1.gif -b:v 1M '
'-filter_complex [1:v]scale=${width - 30}:${height - 30}[ovrl],'
'[0:v][ovrl]overlay=${x -30}:${y - 30}:shortest=1 output.mp4';
我过去常常shortest=1
阻止它永远运行,但是现在即使shortest=1
它永远运行...当我删除它并将 ignore_loop 设为 0 时永远运行的问题就停止了,但是 gif 只能工作一次然后就停止了 !!
如何让它适用于 3 个或更多 gif 以及当我想让 gif 循环时如何阻止它永远运行?
我的日志:
D/flutter-ffmpeg(15047): Running FFmpeg with arguments: [-i, /data/user/0/com.q8intouch.hareem/cache/REC4669564718372657066.mp4, -ignore_loop, 0, -i, /data/user/0/com.q8intouch.hareem/cache/1622464370-cheaf.gif, -b:v, 1M, -filter_complex, [1:v]scale=70.0:70.0[ovrl];[0:v][ovrl]overlay=104.53258167613635:62.36039595170453:shortest=1, /data/user/0/com.q8intouch.hareem/cache/OFBy8.mp4].
I/mobile-ffmpeg(15047): Loading mobile-ffmpeg.
I/mobile-ffmpeg(15047): Loaded mobile-ffmpeg-full-x86-4.4-20200725.
D/mobile-ffmpeg(15047): Callback thread started.
I/mobile-ffmpeg(15047): ffmpeg version v4.4-dev-416
I/mobile-ffmpeg(15047): Copyright (c) 2000-2020 the FFmpeg developers
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): built with Android (6454773 based on r365631c2) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489587874b2a325e7a516b99d838599c6f) (based on LLVM 9.0.8svn)
I/mobile-ffmpeg(15047): configuration: --cross-prefix=i686-linux-android- --sysroot=/files/android-sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/mobile-ffmpeg/prebuilt/android-x86/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=i686 --cpu=i686 --cc=i686-linux-android24-clang --cxx=i686-linux-android24-clang++ --extra-libs='-L/home/taner/Projects/mobile-ffmpeg/prebuilt/android-x86/cpu-features/lib -lndk_compat' --target-os=android --disable-neon --disable-asm --disable-inline-asm --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --enable-shared --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-openssl --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-static --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gmp --enable-gnutls --enable-libmp3lame --enable-libass --enable-iconv --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxml2 --enable-libopencore-amrnb --enable-libshine --enable-libspeex --enable-libwavpack --enable-libkvazaar --enable-libilbc --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libaom --enable-libtwolame --disable-sdl2 --enable-libvo-amrwbenc --enable-zlib --enable-mediacodec
I/mobile-ffmpeg(15047): libavutil 56. 55.100 / 56. 55.100
I/mobile-ffmpeg(15047): libavcodec 58. 96.100 / 58. 96.100
I/mobile-ffmpeg(15047): libavformat 58. 48.100 / 58. 48.100
I/mobile-ffmpeg(15047): libavdevice 58. 11.101 / 58. 11.101
I/mobile-ffmpeg(15047): libavfilter 7. 87.100 / 7. 87.100
I/mobile-ffmpeg(15047): libswscale 5. 8.100 / 5. 8.100
I/mobile-ffmpeg(15047): libswresample 3. 8.100 / 3. 8.100
I/mobile-ffmpeg(15047): [mov,mp4,m4a,3gp,3g2,mj2 @ 0xaa636800] decoding for stream 0 failed
I/mobile-ffmpeg(15047): Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/com.q8intouch.hareem/cache/REC4669564718372657066.mp4':
I/mobile-ffmpeg(15047): Metadata:
I/mobile-ffmpeg(15047): major_brand :
I/mobile-ffmpeg(15047): mp42
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): minor_version :
I/mobile-ffmpeg(15047): 0
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): compatible_brands:
I/mobile-ffmpeg(15047): isommp42
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): creation_time :
I/mobile-ffmpeg(15047): 2021-06-07T17:22:42.000000Z
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): com.android.version:
I/mobile-ffmpeg(15047): 8.1.0
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Duration:
I/mobile-ffmpeg(15047): 04:55:02.33
I/mobile-ffmpeg(15047): , start:
I/mobile-ffmpeg(15047): 0.000000
I/mobile-ffmpeg(15047): , bitrate:
I/mobile-ffmpeg(15047): 0 kb/s
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Stream #0:0
I/mobile-ffmpeg(15047): (eng)
I/mobile-ffmpeg(15047): : Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 320x240, 0 kb/s
I/mobile-ffmpeg(15047): , SAR 1:1 DAR 4:3
I/mobile-ffmpeg(15047): ,
I/mobile-ffmpeg(15047): 0.02 fps,
I/mobile-ffmpeg(15047): 90k tbr,
I/mobile-ffmpeg(15047): 90k tbn,
I/mobile-ffmpeg(15047): 180k tbc
I/mobile-ffmpeg(15047): (default)
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Metadata:
I/mobile-ffmpeg(15047): rotate :
I/mobile-ffmpeg(15047): 90
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): creation_time :
I/mobile-ffmpeg(15047): 2021-06-07T17:22:42.000000Z
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): handler_name :
I/mobile-ffmpeg(15047): VideoHandle
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Side data:
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): displaymatrix: rotation of -90.00 degrees
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Stream #0:1
I/mobile-ffmpeg(15047): (eng)
I/mobile-ffmpeg(15047): : Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, flt, 12 kb/s
I/mobile-ffmpeg(15047): (default)
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Metadata:
I/mobile-ffmpeg(15047): creation_time :
I/mobile-ffmpeg(15047): 2021-06-07T17:22:42.000000Z
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): handler_name :
I/mobile-ffmpeg(15047): SoundHandle
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Input #1, gif, from '/data/user/0/com.q8intouch.hareem/cache/1622464370-cheaf.gif':
I/mobile-ffmpeg(15047): Metadata:
I/mobile-ffmpeg(15047): comment :
I/mobile-ffmpeg(15047): Resized on https://ezgif.com/resize
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Duration:
I/mobile-ffmpeg(15047): 00:00:03.56
I/mobile-ffmpeg(15047): , start:
I/mobile-ffmpeg(15047): 0.000000
I/mobile-ffmpeg(15047): , bitrate:
I/mobile-ffmpeg(15047): 748 kb/s
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Stream #1:0
I/mobile-ffmpeg(15047): : Video: gif, bgra, 250x250
I/mobile-ffmpeg(15047): ,
I/mobile-ffmpeg(15047): 25 fps,
I/mobile-ffmpeg(15047): 25 tbr,
I/mobile-ffmpeg(15047): 100 tbn,
I/mobile-ffmpeg(15047): 100 tbc
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Stream mapping:
I/mobile-ffmpeg(15047): Stream #0:0 (h264) -> overlay:main
I/mobile-ffmpeg(15047): (graph 0)
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Stream #1:0 (gif) -> scale
I/mobile-ffmpeg(15047): (graph 0)
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): overlay
I/mobile-ffmpeg(15047): (graph 0)
I/mobile-ffmpeg(15047): -> Stream #0:0 (mpeg4)
I/mobile-ffmpeg(15047): Stream #0:1 -> #0:1
I/mobile-ffmpeg(15047): (amr_nb (amrnb) -> aac (native))
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Press [q] to stop, [?] for help
W/mobile-ffmpeg(15047): [aac @ 0x624e7000] Too many bits 8832.000000 > 6144 per frame requested, clamping to max
I/mobile-ffmpeg(15047): frame= 0 fps=0.0 q=0.0 size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A
I/flutter (15047): 7105
W/mobile-ffmpeg(15047): [graph 0 input from stream 1:0 @ 0x8345aea0] sws_param option is deprecated and ignored
W/mobile-ffmpeg(15047): [graph 0 input from stream 0:0 @ 0x8345ab40] sws_param option is deprecated and ignored
W/mobile-ffmpeg(15047): [mpeg4 @ 0x8c059400] bitrate tolerance 4000000 too small for bitrate 1000000, overriding
I/mobile-ffmpeg(15047): Output #0, mp4, to '/data/user/0/com.q8intouch.hareem/cache/OFBy8.mp4':
I/mobile-ffmpeg(15047): Metadata:
I/mobile-ffmpeg(15047): major_brand :
I/mobile-ffmpeg(15047): mp42
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): minor_version :
I/mobile-ffmpeg(15047): 0
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): compatible_brands
I/mobile-ffmpeg(15047): isommp42
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): com.android.version:
I/mobile-ffmpeg(15047): 8.1.0
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): encoder :
I/mobile-ffmpeg(15047): Lavf58.48.100
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Stream #0:0
I/mobile-ffmpeg(15047): : Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 240x320 [SAR 1:1 DAR 3:4], q=2-31, 1000 kb/s
I/mobile-ffmpeg(15047): ,
I/mobile-ffmpeg(15047): 0.02 fps,
I/mobile-ffmpeg(15047): 15200 tbn,
I/mobile-ffmpeg(15047): 0.02 tbc
I/mobile-ffmpeg(15047): (default)
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Metadata:
I/mobile-ffmpeg(15047): encoder :
I/mobile-ffmpeg(15047): Lavc58.96.100 mpeg4
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Side data:
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): cpb:
I/mobile-ffmpeg(15047): bitrate max/min/avg: 0/0/1000000 buffer size: 0
I/mobile-ffmpeg(15047): vbv_delay: N/A
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Stream #0:1
I/mobile-ffmpeg(15047): (eng)
I/mobile-ffmpeg(15047): : Audio: aac (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 48 kb/s
I/mobile-ffmpeg(15047): (default)
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): Metadata:
I/mobile-ffmpeg(15047): creation_time :
I/mobile-ffmpeg(15047): 2021-06-07T17:22:42.000000Z
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): handler_name :
I/mobile-ffmpeg(15047): SoundHandle
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): encoder :
I/mobile-ffmpeg(15047): Lavc58.96.100 aac
I/mobile-ffmpeg(15047):
I/mobile-ffmpeg(15047): frame= 1 fps=1.0 q=2.7 size= 0kB time=00:00:09.85 bitrate= 0.0kbits/s speed=9.69x
答案1
如何叠加多张 gif
添加更多比例和叠加过滤器:
ffmpeg -i video.mp4 -ignore_loop 0 -i gif1.gif -ignore_loop 0 -i gif2.gif -ignore_loop 0 -i gif3.gif -filter_complex "[1:v]scale=200:-1[ovrl1];[2:v]scale=200:-1[ovrl2];[3:v]scale=200:-1[ovrl3];[0:v][ovrl1]overlay=5:5:shortest=1:format=auto[bg];[bg][ovrl2]overlay=main_w-overlay_w-5:5:shortest=1:format=auto[bg2];[bg2][ovrl3]overlay=main_w-overlay_w-5:main_h-overlay_h-5:shortest=1:format=auto,format=yuv420p" -c:a copy -movflags +faststart output.mp4
看覆盖位置示例。