我有一段时长的视频10秒,并借助以下命令,我可以使用以下命令修剪然后连接它:
视频
ffmpeg -y -i test_video.mp4 -filter_complex \
"[0:v]split=3[outvideo1][outvideo2][outvideo3]; \
[outvideo1]trim=0:2,setpts=PTS-STARTPTS[video1]; \
[outvideo2]trim=2:8,setpts=PTS-STARTPTS[video2]; \
[outvideo3]trim=start=8,setpts=PTS-STARTPTS[video3]; \
[video1][video2][video3]concat=n=3:v=1:a=0[outvideo]" \
-map '[outvideo]' test_video_text.mp4
上述结果视频命令很好,并且 test_video_text.mp4 的持续时间也是10秒
但是当使用上述命令处理音频时,如下所示:
声音的
ffmpeg -y -i test_video.mp4 -filter_complex \
"[0:a]asplit=3[outaudio1][outaudio2][outaudio3]; \
[outaudio1]atrim=0:2,asetpts=PTS-STARTPTS[audio1]; \
[outaudio2]atrim=2:8,asetpts=PTS-STARTPTS[audio2]; \
[outaudio3]atrim=start=8,asetpts=PTS-STARTPTS[audio3]; \
[audio1][audio2][audio3]concat=n=3:v=0:a=1[outaudio]" \
-map '[outaudio]' test_video_text.mp3
test_video_text.mp3 的时长从10秒至20秒有安静之后10秒。
以下是音频的控制台输出:
ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-vda
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 'test_video.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp41mp42isom
creation_time : 2015-09-24 18:32:33
Duration: 00:00:09.87, start: 0.068254, bitrate: 235 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 320x320, 183 kb/s, 29.67 fps, 29.67 tbr, 29673 tbn, 59.35 tbc (default)
Metadata:
creation_time : 2015-09-24 18:32:33
handler_name : Core Media Video
Stream #0:1(und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 48 kb/s (default)
Metadata:
creation_time : 2015-09-24 18:32:33
handler_name : Core Media Audio
Output #0, mp3, to 'test_video_text.mp3':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp41mp42isom
TSSE : Lavf57.25.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp (default)
Metadata:
encoder : Lavc57.24.102 libmp3lame
Stream mapping:
Stream #0:1 (aac) -> asplit
concat -> Stream #0:0 (libmp3lame)
Press [q] to stop, [?] for help
size= 156kB time=00:00:09.95 bitrate= 128.6kbits/s speed=63.7x
video:0kB audio:156kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.219216%
笔记: 即使我删除资产对于音频命令,结果相同20秒持续时间。
答案1
这不是编码错误,而是与 MP3 元数据相关的错误,即 FFmpeg 未编码 20 秒的音频。插入-write_xing 0
。应显示正确的持续时间。