我想将几张照片(.jpg
或.png
)与电影(主要在.mp4
)合并并将最终输出存储为电影(在.mp4
)
期间
照片默认时长 - 6 秒
默认视频时长 - 无变化(与原始文件一样)
声音
照片上没有声音。
视频 - 原声(与原始文件相同)
第一人称射击游戏
照片的FPS ( framerate
) 并不重要。我知道最低值是6
。对我来说可以是6
或24
。视频的 FPS 应该保持原样(不做任何更改)。
所有文件的大小可以不同(例如,500x100
++ 1024+2028
)360x480
。我认为输出应该以某种方式统一(例如,1920×1080
拉伸其余文件但调整比例)
作为我正在使用的依赖项
https://github.com/bravobit/FFmpeg-Android
测试于
三星 Note 8(Android 9)和模拟器
命令:
-loop 1 -framerate 6 -t 6 -i <PATH>/<IMAGE>.png
-i <PATH>/<VIDEO>.mp4
-loop 1 -framerate 6 -t 6 -i <PATH>/<IMAGE>.jpg
-loop 1 -framerate 6 -t 6 -i <PATH>/<IMAGE>.jpg
-filter_complex
[0:v]scale=1920:-2,format=yuv420p[v0];
[1:v]scale=1920:-2,format=yuv420p[v1];
[2:v]scale=1920:-2,format=yuv420p[v2];
[3:v]scale=1920:-2,format=yuv420p[v3];
[v0][v1][v2][v3]concat=n=4:v=1:unsafe=1[v]
-map [v]
-preset superfast
-crf 20
-r 24
-c:v libx264
-movflags +faststart
<OUTPUT>/<VIDEO>.mp4
-y
我也尝试过:
- 有还是没有
-r 24
- 有还是没有
movflags
- 与不同
-preset
的 - 与不同
-crf
的
但效果是一样的。
结果
视频已创建(具有适当的尺寸、比例和持续时间)。
我可以在默认(本机)或外部 Android 视频播放器(例如 VLC)中播放视频。
例如,我无法分享到 Instagram — — 它不起作用。
影响
完整控制台日志
(无debug
选项)
ffmpeg version n4.0-39-gda39990 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.9.x (GCC) 20150123 (prerelease)
configuration: --target-os=linux --cross-prefix=/root/bravobit/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/root/bravobit/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-ffprobe --enable-libopus --enable-libvorbis --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-libvpx --enable-libass --enable-yasm --enable-pthreads --disable-debug --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-linux-perf --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --enable-nonfree --enable-network --enable-avresample --enable-avformat --enable-avcodec --enable-indev=lavfi --enable-hwaccels --enable-ffmpeg --enable-zlib --enable-gpl --enable-small --enable-nonfree --pkg-config=pkg-config --pkg-config-flags=--static --prefix=/root/bravobit/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/root/bravobit/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/root/bravobit/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags=
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100
Input #0, png_pipe, from '<IMAGE>.png':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: png, rgb24(pc), 483x875, 6 fps, 6 tbr, 6 tbn, 6 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '<MOVIE>.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2019-10-15T23:40:52.000000Z
com.android.version: 9
Duration: 00:00:01.61, start: 0.000000, bitrate: 16336 kb/s
Stream #1:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 16080 kb/s, SAR 1:1 DAR 16:9, 27.93 fps, 30 tbr, 90k tbn, 180k tbc (default)
Metadata:
rotate : 90
creation_time : 2019-10-15T23:40:52.000000Z
handler_name : VideoHandle
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #1:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
Metadata:
creation_time : 2019-10-15T23:40:52.000000Z
handler_name : SoundHandle
Input #2, image2, from '<MOVIE>.jpg':
Duration: 00:00:00.17, start: 0.000000, bitrate: 26989 kb/s
Stream #2:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1429x2160 [SAR 1:1 DAR 1429:2160], 6 fps, 6 tbr, 6 tbn, 6 tbc
Input #3, image2, from '<MOVIE>.jpg':
Duration: 00:00:00.17, start: 0.000000, bitrate: 28343 kb/s
Stream #3:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1472x2160 [SAR 1:1 DAR 92:135], 6 fps, 6 tbr, 6 tbn, 6 tbc
Stream mapping:
Stream #0:0 (png) -> scale
Stream #1:0 (h264) -> scale
Stream #2:0 (mjpeg) -> scale
Stream #3:0 (mjpeg) -> scale
concat -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[swscaler @ 0xe8c27000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0xe8c5c000] deprecated pixel format used, make sure you did set range correctly
[Parsed_concat_8 @ 0xf29c29c0] Input link in1:v0 parameters (size 1920x3414, SAR 5121:5120) do not match the corresponding output link in0:v0 parameters (1920x3478, SAR 5121:5120)
[Parsed_concat_8 @ 0xf29c29c0] Input link in2:v0 parameters (size 1920x2902, SAR 2073479:2073600) do not match the corresponding output link in0:v0 parameters (1920x3478, SAR 5121:5120)
[Parsed_concat_8 @ 0xf29c29c0] Input link in3:v0 parameters (size 1920x2818, SAR 32407:32400) do not match the corresponding output link in0:v0 parameters (1920x3478, SAR 5121:5120)
[libx264 @ 0xf29eed00] using SAR=4096/4095
[libx264 @ 0xf29eed00] using cpu capabilities: ARMv6 NEON
[libx264 @ 0xf29eed00] profile High, level 5.1
[libx264 @ 0xf29eed00] 264 - core 152 r2851M ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x3 me=dia subme=1 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 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=1 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc=crf mbtree=0 crf=20.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 pb_ratio=1.30 aq=1:1.00
Output #0, mp4, to '<MOVIE>.mp4':
Metadata:
encoder : Lavf58.12.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1920x3478 [SAR 5121:5120 DAR 15363:27824], q=-1--1, 24 fps, 12288 tbn, 24 tbc (default)
Metadata:
encoder : Lavc58.18.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 8 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A dup=6 drop=0 speed= 0x
frame= 20 fps= 15 q=19.0 size= 512kB time=-00:00:00.08 bitrate=N/A dup=15 drop=0 speed=N/A
frame= 32 fps= 17 q=14.0 size= 512kB time=00:00:00.41 bitrate=10065.3kbits/s dup=24 drop=0 speed=0.215x
frame= 40 fps= 16 q=13.0 size= 768kB time=00:00:00.75 bitrate=8388.2kbits/s dup=30 drop=0 speed=0.301x
frame= 52 fps= 17 q=12.0 size= 1280kB time=00:00:01.25 bitrate=8388.4kbits/s dup=39 drop=0 speed=0.402x
frame= 64 fps= 18 q=12.0 size= 1536kB time=00:00:01.75 bitrate=7190.1kbits/s dup=48 drop=0 speed=0.484x
frame= 76 fps= 18 q=12.0 size= 1536kB time=00:00:02.25 bitrate=5592.4kbits/s dup=57 drop=0 speed=0.546x
frame= 92 fps= 19 q=12.0 size= 1536kB time=00:00:02.91 bitrate=4314.2kbits/s dup=69 drop=0 speed=0.615x
frame= 108 fps= 19 q=12.0 size= 1792kB time=00:00:03.58 bitrate=4096.8kbits/s dup=81 drop=0 speed=0.641x
frame= 124 fps= 20 q=12.0 size= 1792kB time=00:00:04.25 bitrate=3454.2kbits/s dup=93 drop=0 speed=0.677x
frame= 136 fps= 20 q=12.0 size= 1792kB time=00:00:04.75 bitrate=3090.6kbits/s dup=102 drop=0 speed=0.693x
frame= 148 fps= 20 q=12.0 size= 2048kB time=00:00:05.25 bitrate=3195.7kbits/s dup=111 drop=0 speed=0.709x
Past duration 2.702934 too large
Past duration 2.903450 too large
Past duration 3.103981 too large
frame= 154 fps= 19 q=17.0 size= 2048kB time=00:00:05.50 bitrate=3050.4kbits/s dup=113 drop=0 speed=0.689x
Past duration 3.304787 too large
Past duration 3.505577 too large
Past duration 3.706123 too large
Past duration 3.906654 too large
frame= 160 fps= 19 q=19.0 size= 2048kB time=00:00:05.75 bitrate=2917.8kbits/s dup=113 drop=0 speed=0.67x
frame= 164 fps= 18 q=20.0 size= 3584kB time=00:00:05.91 bitrate=4962.3kbits/s dup=113 drop=1 speed=0.647x
frame= 167 fps= 17 q=20.0 size= 3584kB time=00:00:06.04 bitrate=4859.6kbits/s dup=113 drop=1 speed=0.624x
frame= 168 fps= 16 q=20.0 size= 4864kB time=00:00:06.08 bitrate=6550.0kbits/s dup=113 drop=2 speed=0.593x
frame= 171 fps= 16 q=20.0 size= 5120kB time=00:00:06.20 bitrate=6755.9kbits/s dup=113 drop=2 speed=0.567x
frame= 175 fps= 15 q=20.0 size= 6656kB time=00:00:06.37 bitrate=8553.0kbits/s dup=113 drop=3 speed=0.553x
frame= 179 fps= 15 q=20.0 size= 7680kB time=00:00:06.54 bitrate=9617.5kbits/s dup=113 drop=4 speed=0.543x
frame= 181 fps= 14 q=20.0 size= 8192kB time=00:00:06.62 bitrate=10129.6kbits/s dup=113 drop=5 speed=0.527x
frame= 183 fps= 14 q=20.0 size= 8704kB time=00:00:06.70 bitrate=10629.0kbits/s dup=113 drop=5 speed=0.511x
frame= 187 fps= 14 q=20.0 size= 9728kB time=00:00:06.87 bitrate=11591.5kbits/s dup=113 drop=6 speed= 0.5x
Past duration 1.269432 too large
frame= 195 fps= 14 q=20.0 size= 12032kB time=00:00:07.20 bitrate=13673.8kbits/s dup=118 drop=7 speed=0.502x
frame= 203 fps= 13 q=19.0 size= 14080kB time=00:00:07.54 bitrate=15294.0kbits/s dup=124 drop=7 speed=0.501x
frame= 211 fps= 14 q=16.0 size= 15872kB time=00:00:07.87 bitrate=16510.8kbits/s dup=130 drop=7 speed=0.504x
frame= 223 fps= 14 q=14.0 size= 16128kB time=00:00:08.37 bitrate=15775.5kbits/s dup=139 drop=7 speed=0.517x
frame= 235 fps= 14 q=14.0 size= 16896kB time=00:00:08.87 bitrate=15595.6kbits/s dup=148 drop=7 speed=0.527x
frame= 247 fps= 14 q=18.0 size= 17408kB time=00:00:09.37 bitrate=15211.3kbits/s dup=157 drop=7 speed=0.535x
frame= 259 fps= 14 q=18.0 size= 17664kB time=00:00:09.87 bitrate=14653.4kbits/s dup=166 drop=7 speed=0.545x
frame= 271 fps= 15 q=19.0 size= 18176kB time=00:00:10.37 bitrate=14351.5kbits/s dup=175 drop=7 speed=0.556x
frame= 283 fps= 15 q=18.0 size= 18688kB time=00:00:10.87 bitrate=14077.4kbits/s dup=184 drop=7 speed=0.566x
frame= 295 fps= 15 q=19.0 size= 19200kB time=00:00:11.37 bitrate=13827.3kbits/s dup=193 drop=7 speed=0.573x
frame= 307 fps= 15 q=18.0 size= 19712kB time=00:00:11.87 bitrate=13598.3kbits/s dup=202 drop=7 speed=0.58x
frame= 319 fps= 15 q=19.0 size= 20224kB time=00:00:12.37 bitrate=13387.8kbits/s dup=211 drop=7 speed=0.588x
frame= 331 fps= 15 q=18.0 size= 20736kB time=00:00:12.87 bitrate=13193.7kbits/s dup=220 drop=7 speed=0.595x
frame= 343 fps= 15 q=21.0 size= 21248kB time=00:00:13.37 bitrate=13014.1kbits/s dup=229 drop=7 speed=0.603x
frame= 355 fps= 16 q=19.0 size= 22528kB time=00:00:13.87 bitrate=13300.8kbits/s dup=238 drop=7 speed=0.609x
frame= 367 fps= 16 q=19.0 size= 23040kB time=00:00:14.37 bitrate=13129.9kbits/s dup=247 drop=7 speed=0.616x
frame= 379 fps= 16 q=18.0 size= 23296kB time=00:00:14.87 bitrate=12829.6kbits/s dup=256 drop=7 speed=0.622x
frame= 391 fps= 16 q=19.0 size= 24064kB time=00:00:15.37 bitrate=12821.6kbits/s dup=265 drop=7 speed=0.628x
frame= 403 fps= 16 q=18.0 size= 24320kB time=00:00:15.87 bitrate=12549.8kbits/s dup=274 drop=7 speed=0.634x
frame= 415 fps= 16 q=19.0 size= 24832kB time=00:00:16.37 bitrate=12422.8kbits/s dup=283 drop=7 speed=0.64x
frame= 427 fps= 16 q=18.0 size= 25344kB time=00:00:16.87 bitrate=12303.3kbits/s dup=292 drop=7 speed=0.646x
frame= 439 fps= 16 q=19.0 size= 25856kB time=00:00:17.37 bitrate=12190.6kbits/s dup=301 drop=7 speed=0.65x
frame= 451 fps= 17 q=18.0 size= 26112kB time=00:00:17.87 bitrate=11966.9kbits/s dup=310 drop=7 speed=0.656x
frame= 463 fps= 17 q=19.0 size= 26880kB time=00:00:18.37 bitrate=11983.7kbits/s dup=319 drop=7 speed=0.661x
frame= 471 fps= 17 q=19.0 size= 27136kB time=00:00:18.70 bitrate=11882.3kbits/s dup=325 drop=7 speed=0.66x
[mp4 @ 0xf29bea00] Starting second pass: moving the moov atom to the beginning of the file
frame= 471 fps= 16 q=-1.0 Lsize= 27880kB time=00:00:19.50 bitrate=11712.5kbits/s dup=325 drop=7 speed=0.678x
video:27874kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.023015%
[libx264 @ 0xf29eed00] frame I:6 Avg QP: 7.62 size:1001547
[libx264 @ 0xf29eed00] frame P:143 Avg QP:11.39 size:151068
[libx264 @ 0xf29eed00] frame B:322 Avg QP:13.28 size: 2888
[libx264 @ 0xf29eed00] consecutive B-frames: 8.3% 0.8% 2.5% 88.3%
[libx264 @ 0xf29eed00] mb I I16..4: 12.0% 33.8% 54.2%
[libx264 @ 0xf29eed00] mb P I16..4: 2.2% 10.0% 4.9% P16..4: 18.5% 0.0% 0.0% 0.0% 0.0% skip:64.5%
[libx264 @ 0xf29eed00] mb B I16..4: 0.0% 0.1% 0.0% B16..8: 1.5% 0.0% 0.0% direct: 2.3% skip:96.0% L0:20.0% L1:78.9% BI: 1.1%
[libx264 @ 0xf29eed00] 8x8 transform intra:53.8% inter:28.3%
[libx264 @ 0xf29eed00] coded y,uvDC,uvAC intra: 77.4% 56.2% 31.9% inter: 3.7% 4.3% 0.4%
[libx264 @ 0xf29eed00] i16 v,h,dc,p: 37% 24% 29% 10%
[libx264 @ 0xf29eed00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 16% 28% 4% 9% 6% 6% 5% 8%
[libx264 @ 0xf29eed00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 18% 25% 4% 9% 5% 6% 5% 7%
[libx264 @ 0xf29eed00] i8c dc,h,v,p: 45% 20% 24% 11%
[libx264 @ 0xf29eed00] Weighted P-Frames: Y:11.2% UV:0.0%
[libx264 @ 0xf29eed00] kb/s:11635.01
合并工作正常。所有元素的长度都正确。但主要问题是电影底部闪烁着“绿色”(有时是“粉红色”)(几乎存在于整个电影中,高度始终相同)
以及如何使照片保持静音但保留视频的声音。
答案1
ffmpeg -t 0.1 -f lavfi -i anullsrc=cl=stereo:r=44100 \
-loop 1 -framerate 1 -t 6 -i v1.jpg \
-i video.mp4 \
-loop 1 -framerate 1 -t 6 -i v3.jpg \
-loop 1 -framerate 1 -t 6 -i v4.jpg \
-filter_complex \
"[1:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,setsar=1,fps=24,format=yuv420p[v1];
[2:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,setsar=1,fps=24,format=yuv420p[v2];
[3:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,setsar=1,fps=24,format=yuv420p[v3];
[4:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,setsar=1,fps=24,format=yuv420p[v4];
[v1][0][v2][2:a][v3][0][v4][0]concat=n=4:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -c:v libx264 -preset superfast -crf 20 -c:a aac -movflags +faststart out.mp4