我适应了Gyan 算法对于交叉淡入淡出 - 我更喜欢其结果xfade
- 将两个视频连接在一起并与第三个视频交叉淡入淡出:
ffmpeg -i "source1.mp4" -i "source2.mp4" -i "source3.mp4" \
-preset ultrafast \
-movflags faststart \
-filter_complex \
"color=black:1440x1080:d=1789.145[base]; \
[0:v]scale=1440x1080,setpts=PTS-STARTPTS[v0]; \
[1:v]scale=1440x1080,trim=start=15.5,setpts=PTS-STARTPTS+((593.106000)/TB)[v1]; \
[2:v]scale=1440x1080,format=yuva420p,fade=in:st=0:d=2:alpha=1,setpts=PTS-STARTPTS+((1186.028000)/TB)[v2]; \
[base][v1]overlay[tmp]; \
[tmp][v2]overlay,format=yuv420p[crossfade]; \
[v0][crossfade]concat=n=2:v=1:a=0[fv]; \
[1:a]atrim=start=15.5,asetpts=PTS-STARTPTS[a1]; \
[0:a][a1]concat=n=2:v=0:a=1[aconcat]; \
[aconcat][2:a]acrossfade=d=2[fa]" \
-map "[fv]" -map "[fa]" -c:v libx264 -crf 15 -c:a libopus -shortest "test1.mp4"
在编码了视频最终长度的一半并用完了我全部 16GB RAM 之后,FFmpeg 最终耗尽并崩溃。
以下是崩溃后任务管理器中的内存使用情况:
完整输出如下:
ffmpeg version N-100422-gff6f8c272e-g1eb751955e+1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
configuration: --pkg-config=pkgconf --cc='ccache gcc' --cxx='ccache g++' --disable-autodetect --enable-amf --enable-bzlib --enable-
cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-zlib --enable-sdl2 --enable-f
fnvcodec --enable-nvdec --enable-cuda-llvm --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --
enable-libx265 --enable-libdav1d --enable-libaom --disable-debug --enable-libfdk-aac --enable-openssl --extra-libs=-liconv --enable-gp
l --enable-nonfree
libavutil 56. 62.100 / 56. 62.100
libavcodec 58.115.102 / 58.115.102
libavformat 58. 65.100 / 58. 65.100
libavdevice 58. 11.103 / 58. 11.103
libavfilter 7. 93.100 / 7. 93.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'source1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.65.100
Duration: 00:09:54.11, start: 0.000000, bitrate: 372 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x240, 242 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'source2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.65.100
Duration: 00:09:52.92, start: 0.000000, bitrate: 315 kb/s
Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 181 kb/s, 25 fps, 25 tbr, 12800 tbn,
50 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc.
vendor_id : [0][0][0][0]
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc.
vendor_id : [0][0][0][0]
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'source3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.65.100
Duration: 00:10:02.12, start: 0.000000, bitrate: 314 kb/s
Stream #2:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 180 kb/s, 25 fps, 25 tbr, 12800 tbn,
50 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc.
vendor_id : [0][0][0][0]
Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc.
vendor_id : [0][0][0][0]
File 'test1.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 (h264) -> scale
Stream #0:1 (aac) -> concat:in0:a0
Stream #1:0 (h264) -> scale
Stream #1:1 (aac) -> atrim
Stream #2:0 (h264) -> scale
Stream #2:1 (aac) -> acrossfade:crossfade1
concat -> Stream #0:0 (libx264)
acrossfade -> Stream #0:1 (libopus)
Press [q] to stop, [?] for help
[libx264 @ 000002475283b600] using SAR=1/1
[libx264 @ 000002475283b600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 000002475283b600] profile Constrained Baseline, level 4.0, 4:2:0, 8-bit
[libx264 @ 000002475283b600] 264 - core 161 r3027 4121277 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264
.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 tre
llis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 in
terlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0
crf=15.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
[libopus @ 0000024752837f40] No bit rate set. Defaulting to 96000 bps.
Output #0, mp4, to 'test1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.65.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, progressive), 1440x1080 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 12800 tbn (de
fault)
Metadata:
encoder : Lavc58.115.102 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: opus (Opus / 0x7375704F), 48000 Hz, stereo, flt, 96 kb/s (default)
Metadata:
encoder : Lavc58.115.102 libopus
Error while filtering: Cannot allocate memorye=00:16:48.79 bitrate=7107.6kbits/s speed=3.19x
Last message repeated 1 times
Failed to inject frame into filter network: Cannot allocate memory
Error while processing the decoded data for stream #1:0
[libx264 @ 000002475283b600] frame I:101 Avg QP: 7.17 size:104091
[libx264 @ 000002475283b600] frame P:25125 Avg QP: 9.65 size: 34810
[libx264 @ 000002475283b600] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 000002475283b600] mb P I16..4: 3.9% 0.0% 0.0% P16..4: 37.3% 0.0% 0.0% 0.0% 0.0% skip:58.8%
[libx264 @ 000002475283b600] coded y,uvDC,uvAC intra: 36.5% 45.6% 16.1% inter: 23.8% 13.9% 0.3%
[libx264 @ 000002475283b600] i16 v,h,dc,p: 43% 29% 11% 16%
[libx264 @ 000002475283b600] i8c dc,h,v,p: 39% 26% 14% 21%
[libx264 @ 000002475283b600] kb/s:7017.47
[libopus @ 0000024752837f40] 1 frames left in the queue on closing
Conversion failed!
这是一个错误,还是我遗漏了命令中的某些内容?
答案1
经过几天的努力解决这个问题,我确定,至少根据我自己的经验,它总是由数字不相加引起的,例如-ss
超出视频长度或计算错误的SETPTS
值。
我仍然相信这是一个错误,原因有二:
因为这不仅仅是我最初怀疑的 FFmpeg 耗尽所有可用内存的情况,而是在仍有可用内存的情况下迅速消耗大量内存,最终崩溃
因为当参数显然无法计算时,FFmpeg 应该真正检测并抛出错误,从而消耗大量内存,最终导致程序崩溃