我正在尝试将 gif/图像与视频合并/合并以输出一个在一帧中包含两者的视频。为此,我在 nodejs 上使用 FFMPEG。我使用的过滤器是 Hstack,由于内容可以动态调整大小,因此我通过运行 scale2ref 过滤器两次根据视频参数调整 gif 的大小。
但它需要很长时间并且不会停止。我想我必须按 CTRL+C 才能停止终端。
命令如下:
ffmpeg -i in1.gif -i in2.mp4 -filter_complex
"[0][1]scale2ref='oh*mdar':'if(lt(main_h,ih),ih,main_h)'[0s][1s];
[1s][0s]scale2ref='oh*mdar':'if(lt(main_h,ih),ih,main_h)'[1s][0s];
[0s][1s]hstack,setsar=1" output.mp4
以下是我在 vscode 终端中运行此命令时发生的情况:
ffmpeg -i input1.gif -i input2.mp4 -filter_complex "[0][1]scale2ref='oh*mdar':'if(lt(main_h,ih),ih,main_h)'[0s][1s]; [1s][0s]scale2ref='oh*mdar':'if(lt(main_h,ih),ih,main_h)'[1s][0s]; [0s][1s]hstack,setsar=1" Output2.mp4
输出结果如下:
ffmpeg version git-2020-03-03-60b1f85 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20200122
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray
--enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 42.100 / 56. 42.100
libavcodec 58. 73.102 / 58. 73.102
libavformat 58. 39.101 / 58. 39.101
libavdevice 58. 9.103 / 58. 9.103
libavfilter 7. 77.100 / 7. 77.100
libswscale 5. 6.100 / 5. 6.100
libswresample 3. 6.100 / 3. 6.100
libpostproc 55. 6.100 / 55. 6.100
Input #0, gif, from 'input1.gif':
Duration: 00:00:48.00, start: 0.000000, bitrate: 866 kb/s
Stream #0:0: Video: gif, bgra, 800x600, 1.25 fps, 1.25 tbr, 100 tbn, 100 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'input2.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41isomavc1
creation_time : 2020-03-06T02:02:36.000000Z
Duration: 00:00:36.71, start: 0.000000, bitrate: 949 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 692 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc (default)
Metadata:
creation_time : 2020-03-06T02:02:36.000000Z
handler_name : L-SMASH Video Handler
encoder : AVC Coding
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 253 kb/s (default)
Metadata:
creation_time : 2020-03-06T02:02:36.000000Z
handler_name : L-SMASH Audio Handler
Stream mapping:
Stream #0:0 (gif) -> scale2ref:default (graph 0)
Stream #1:0 (h264) -> scale2ref:ref (graph 0)
setsar (graph 0) -> Stream #0:0 (libx264)
Stream #1:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[mp4 @ 00000253e9d58640] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
[libx264 @ 00000253e9e60540] using SAR=1/1
[libx264 @ 00000253e9e60540] MB rate (151200000) > level limit (16711680)
[libx264 @ 00000253e9e60540] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000253e9e60540] profile High, level 6.2, 4:2:0, 8-bit
[libx264 @ 00000253e9e60540] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - 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 'Output2.mp4':
Metadata:
encoder : Lavf58.39.101
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 2240x720 [SAR 1:1 DAR 28:9], q=-1--1, 24k tbn, 24k tbc (default)
Metadata:
encoder : Lavc58.73.102 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
fltp, 128 kb/s (default)
Metadata:
creation_time : 2020-03-06T02:02:36.000000Z
handler_name : L-SMASH Audio Handler
encoder : Lavc58.73.102 aac ts/s dup=999 drop=0 speed=0.0062x
More than 1000 frames duplicated 0kB time=00:00:00.03 bitrate= 9.8kbiits/s dup=9999 drop=0 speed=0.0123xts/s dup=999 drop=0 speed=0.0062x bits/s dup=99994 drop=0 speed=0.00757x
More than 10000 frames duplicated 2048kB time=00:00:00.46 bitrate=35747.8kbbits/s dup=444976 drop=0 speed=0.00696x its/s dup=9999 drop=0 speed=0.0123x
More than 100000 frames duplicated 46592kB time=00:00:04.56 bitrate=83604.4kbits/s dup=99994 drop=0 speed=0.00757x
frame=447447 fps=164 q=33.0 size= 184320kB time=00:00:19.41 bitrate=77779.0kframe=448448 fps=164 q=33.0 size= 184576kB time=00:00:19.41 bitrate=77887.0kframe=449449 fps=164 q=33.0 size= 185088kB time=00:00:19.41 bitrate=78103.1kframe=450450 fps=164 q=33.0 size= 185344kB time=00:00:19.41 bitrate=78211.1kframe=451451 fps=164 q=33.0 size= 185856kB time=00:00:19.41 bitrate=78427.2kframe=452452 fps=164 q=33.0 size= 186112kB time=00:00:19.41 bitrate=78535.2kframe=453453 fps=164 q=33.0 size= 186624kB time=00:00:19.41 bitrate=78751.2kframe=454454 fps=164 q=33.0 size= 186880kB time=00:00:19.41 bitrate=78859.3kframe=455455 fps=164 q=33.0 size= 187392kB time=00:00:19.41 bitrate=79075.3kframe=456456 fps=164 q=33.0 size= 187648kB time=00:00:19.41 bitrate=79183.4kframe=457457 fps=164 q=33.0 size= 188160kB time=00:00:19.41 bitrate=79399.4kframe=457457 fps=164 q=33.0 size= 188160kB time=00:00:19.43 bitrate=79312.2kframe=459459 fps=164 q=33.0 size= 188928kB time=00:00:19.92 bitrate=77674.9kframe=460460 fps=164 q=33.0 size= 189440kB time=00:00:19.92 bitrate=77885.4kframe=460800 fps=164 q=33.0 size= 189440kB time=00:00:19.92 bitrate=77885.4kframe=461461 fps=164 q=33.0 size= 189696kB time=00:00:19.92 bitrate=77990.7kframe=462462 fps=164 q=33.0 size= 190208kB time=00:00:19.92 bitrate=78201.2kframe=463463 fps=164 q=33.0 size= 190464kB time=00:00:19.92 bitrate=78306.4kframe=464464 fps=164 q=33.0 size= 190976kB time=00:00:19.92 bitrate=78516.9kframe=465465 fps=164 q=33.0 size= 191488kB time=00:00:19.92 bitrate=78727.4kframe=466466 fps=164 q=33.0 size= 191744kB time=00:00:19.92 bitrate=78832.7kframe=467467 fps=164 q=33.0 size= 192256kB time=00:00:19.92 bitrate=79043.2kframe=468468 fps=164 q=33.0 size= 192512kB time=00:00:19.92 bitrate=79148.4kframe=469469 fps=164 q=33.0 size= 193024kB time=00:00:19.92 bitrate=79358.9kframe=470470 fps=164 q=33.0 size= 193536kB time=00:00:19.92 bitrate=79569.4kframe=471471 fps=164 q=33.0 size= 193792kB time=00:00:19.92 bitrate=79674.7kframe=472472 fps=164 q=33.0 size= 194304kB time=00:00:19.92 bitrate=79885.2kframe=473473 fps=163 q=33.0 size= 194560kB time=00:00:19.92 bitrate=79990.4kframe=474474 fps=163 q=33.0 size= 195072kB time=00:00:19.92 bitrate=80200.9kframe=475475 fps=163 q=33.0 size= 195328kB time=00:00:19.92 bitrate=80306.2kframe=476476 fps=163 q=33.0 size= 195840kB time=00:00:19.92 bitrate=80516.7kframe=477477 fps=163 q=33.0 size= 196096kB time=00:00:19.92 bitrate=80621.9kframe=478478 fps=163 q=33.0 size= 196352kB time=00:00:19.93 bitrate=80691.4kframe=479479 fps=163 q=33.0 size= 196352kB time=00:00:19.97 bitrate=80522.9kframe=480000 fps=163 q=33.0 size= 196352kB time=00:00:19.99 bitrate=80435.5kframe=480000 fps=163 q=33.0 size= 196352kB time=00:00:19.99 bitrate=80435.5kframe=480480 fps=163 q=33.0 size= 197376kB time=00:00:20.05 bitrate=80630.2kframe=481481 fps=163 q=33.0 size= 197632kB time=00:00:20.07 bitrate=80649.0kframe=483483 fps=163 q=33.0 size= 198656kB time=00:00:20.43 bitrate=79628.3kframe=484484 fps=163 q=33.0 size= 198912kB time=00:00:20.43 bitratMore than 1000000 frames duplicated330240kB time=00:00:41.59 bitrate=65035.7kbits/s dup=997468 drop=0 speed=0.0076x
frame=1075200 fps=186 q=33.0 size= 330240kB time=00:00:44.79 bitrate=60390.0kbits/s dup=1074264 drop=0 speed=0.00773x
答案1
我不能 100% 确定你想做什么,正如短语
同一帧内同时包含两个内容的视频
建议我将其放在 1 帧中(组成视频的帧,因此只有其中一帧),这实际上只能用作视频上的某种标记,而对观看者则没有用,因此我怀疑您指的是一个视频。下面的代码将图像叠加在视频上 X 时间。我希望这就是您要找的。我相信您可以适应您想要的任何调整大小,因为叠加位似乎是您要问的,我希望我已经理解了。
ffmpeg -i input.mp4 -i image.png -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4
我从关于 SE 视频制作的另一个问题。它解释了选项等等。
根据您提供的数据,正如您所怀疑的那样,看起来您创建了一个循环,并且它会不断重复,即它陷入了无限循环。
答案2
hstack 选择第一个输入的帧速率,但 GIF 的速率可能太低,因此 ffmpeg 选择了时间基准。因此,请为 GIF 输入设置手动速率。
-filter_complex "[0]fps=24[0v];[0v][1]scale2ref='oh*mdar':'if(lt(main_h,ih),ih,main_h)'[0s][1s]; [1s][0s]scale2ref='oh*mdar':'if(lt(main_h,ih),ih,main_h)'[1s][0s]; [0s][1s]hstack,setsar=1"