我正在尝试使用 ffmpeg 导入三个文件,两个视频和一个音频。我想减慢第一个视频的速度,然后用音频文件替换其音频,然后在结果的末尾添加一个视频。
这是我目前所拥有的,但它肯定不起作用。我很难使用两个过滤器将慢动作和连接结合在一起。
ffmpeg -i /Users/dailyops/Desktop/source0.mp4 -i /Users/dailyops/Desktop/music.m4a -i /Users/dailyops/Desktop/outro.mp4 -vf [0:v]setpts=3*PTS [v0] -filter_complex [v0][1:a:0][2:v:0][2:a:0]concat=n=2:v=1:a=1[v1][a] -map [v1] -map [a] -shortest -vcodec libx264 -preset ultrafast -crf 22 -pix_fmt yuv420p -r 29.97 /Users/dailyops/Desktop/output1.mp4
这是否完全可行?
该命令的结果如下:
ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.1.0 (clang-802.0.42)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --disable-lzma --enable-nonfree --enable-vda
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/dailyops/Desktop/source0.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2017-04-15T07:07:08.000000Z
Duration: 00:03:20.81, start: 0.000000, bitrate: 1081 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 951 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
Metadata:
creation_time : 2017-04-15T07:07:08.000000Z
handler_name : ISO Media file produced by Google Inc.
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
creation_time : 2017-04-15T07:07:08.000000Z
handler_name : ISO Media file produced by Google Inc.
[aac @ 0x7fb2718a9800] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide) layout, use -strict 1 to decode according to the specification instead.
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/dailyops/Desktop/music.m4a':
Metadata:
major_brand : M4A
minor_version : 0
compatible_brands: M4A mp42isom
creation_time : 2015-12-16T22:35:44.000000Z
iTunSMPB : 00000000 00000DFD 0000034B 00000000000B0EB8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Duration: 00:00:16.53, start: 0.081202, bitrate: 243 kb/s
Stream #1:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, 7.1, fltp, 241 kb/s (default)
Metadata:
creation_time : 2015-12-16T22:35:44.000000Z
handler_name : Core Media Audio
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/dailyops/Desktop/outro.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2017-07-04T19:21:14.000000Z
encoder : HandBrake 1.0.7 2017040900
Duration: 00:00:06.06, start: 0.000000, bitrate: 1153 kb/s
Stream #2:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1036 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2017-07-04T19:21:14.000000Z
handler_name : VideoHandler
Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 112 kb/s (default)
Metadata:
creation_time : 2017-07-04T19:21:14.000000Z
handler_name : Stereo
[NULL @ 0x7fb272000000] Unable to find a suitable output format for '[v0]'
[v0]: Invalid argument
答案1
无需单独的-vf
过滤器;您可以使用 完成所有操作-filter_complex
。(事实上,当您想要进一步使用该输出时,您必须这样做,就像 的情况一样v0
。)
构造-filter_complex
命令时,请将其放在引号中。使用 时,输出标签也一样-map
。否则,您的 shell 可能会在 ffmpeg 看到这些字符之前就解释它们。
ffmpeg -i /Users/dailyops/Desktop/source0.mp4 \
-i /Users/dailyops/Desktop/music.m4a \
-i /Users/dailyops/Desktop/outro.mp4 \
-filter_complex "[0:v]setpts=3*PTS[v0]; \
[v0][1:a:0][2:v:0][2:a:0]concat=n=2:v=1:a=1[v1][a]" \
-map "[v1]" -map "[a]" \
-shortest -vcodec libx264 -preset ultrafast -crf 22 -pix_fmt yuv420p -r 29.97 \
/Users/dailyops/Desktop/output1.mp4