我有ffmpeg合并3 mp4视频,然后是另一个命令,它将音频从第一个命令添加到输出文件。命令如下:
ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -filter_complex "[0:v][1:v][2:v]concat=n=3:v=1" -preset ultrafast -crf 1 output.mp4
ffmpeg -i output.mp4 -i audio.mp3 -preset ultrafast -crf 1 final.mp4
有没有在一个命令中执行此操作?我还想将音频添加到第一个命令中创建的视频中。这可能吗?
“ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i audio.mp3”的控制台输出
[jstevens@jr testing]$ ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i audio.mp3
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 6.1.1 (GCC) 20160510 (Red Hat 6.1.1-2)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Duration: 00:00:05.00, start: 0.000000, bitrate: 1085 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1081 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Duration: 00:00:05.00, start: 0.000000, bitrate: 1018 kb/s
Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1014 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'vid-3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Duration: 00:00:05.00, start: 0.000000, bitrate: 823 kb/s
Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 819 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
[mp3 @ 0x1ca30c0] Skipping 0 bytes of junk at 0.
[mp3 @ 0x1ca30c0] Estimating duration from bitrate, this may be inaccurate
Input #3, mp3, from 'audio.mp3':
Duration: 00:00:19.57, start: 0.000000, bitrate: 64 kb/s
Stream #3:0: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
At least one output file must be specified
答案 0 :(得分:1)
ffmpeg -i vid-1.mp4 -i vid-2.mp4 -i vid-3.mp4 -i audio.mp3 \
-filter_complex "[0:v][1:v][2:v]concat=n=3:v=1:a=0[v]" \
-map "[v]" -map 3:a -shortest output.mp4
我建议使用-map
手动定义映射,而不是依赖default stream selection behavior。
添加了-shortest
选项,因为连续的视频时长比音频持续时间短。