我想将时长为 5 秒的 M4A 音频添加到 MP4 视频文件中。我已经尝试了-itsoffset
命令ffmpeg
。
ffmpeg -i a.mp4 -itsoffset 00:00:10 -i b.m4a -map 0:0 -map 1:0 -preset ultrafast o.mp4
命令行输出
ffmpeg -i psy.mp4 -itsoffset 00:00:10 -i cut.m4a -map 0:0 -map 1:0 -c:v copy -preset ultrafast -y out.mp4
ffmpeg version N-50911-g9efcfbe Copyright (c) 2000-2013 the FFmpeg developers
built on Mar 13 2013 21:26:48 with gcc 4.7.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libg
sm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libo
pencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-li
bschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-lib
twolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enabl
e-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 19.100 / 52. 19.100
libavcodec 55. 0.100 / 55. 0.100
libavformat 55. 0.100 / 55. 0.100
libavdevice 54. 4.100 / 54. 4.100
libavfilter 3. 45.103 / 3. 45.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'psy.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2013-12-03 03:22:01
Duration: 00:04:12.17, start: 0.000000, bitrate: 723 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yu
v420p, 640x360, 624 kb/s, 23.98 fps, 23.98 tbr, 48k tbn, 47.95 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96
kb/s
Metadata:
creation_time : 2013-12-03 03:22:02
handler_name : IsoMedia File Produced by Google, 5-11-2011
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'cut.m4a':
Metadata:
major_brand : M4A
minor_version : 512
compatible_brands: isomiso2
encoder : Lavf55.0.100
Duration: 00:00:05.24, start: 0.237460, bitrate: 99 kb/s
Stream #1:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96
kb/s
Metadata:
handler_name : SoundHandler
Codec AVOption preset (Set the encoding preset (cf. x264 --fullhelp)) specified
for output file #0 (out.mp4) has not been used for any stream. The most likely r
eason is either wrong type (e.g. a video option with no video streams) or that i
t is a private option of some encoder which was not actually used for any stream
.
Output #0, mp4, to 'out.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
encoder : Lavf55.0.100
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 640x360, q=
2-31, 624 kb/s, 23.98 fps, 48k tbn, 48k tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16
, 128 kb/s
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (aac -> libvo_aacenc)
Press [q] to stop, [?] for help
frame= 916 fps=0.0 q=-1.0 size= 865kB time=00:00:38.16 bitrate= 185.7kbits/
frame= 1758 fps=1749 q=-1.0 size= 865kB time=00:01:13.28 bitrate= 96.7kbits
frame= 2477 fps=1645 q=-1.0 size= 865kB time=00:01:43.26 bitrate= 68.6kbits
frame= 3182 fps=1586 q=-1.0 size= 865kB time=00:02:12.67 bitrate= 53.4kbits
frame= 3961 fps=1580 q=-1.0 size= 865kB time=00:02:45.16 bitrate= 42.9kbits
frame= 4904 fps=1631 q=-1.0 size= 865kB time=00:03:24.49 bitrate= 34.7kbits
frame= 5667 fps=1615 q=-1.0 size= 865kB time=00:03:56.31 bitrate= 30.0kbits
frame= 6046 fps=1549 q=-1.0 Lsize= 19345kB time=00:04:12.12 bitrate= 628.6kbit
s/s
video:19234kB audio:83kB subtitle:0 global headers:0kB muxing overhead 0.146119%
问题是:它确实从 00:00:10 开始,但每 10 秒就会重复一次。(只有在不触摸搜索栏的情况下播放整个视频时,您才能注意到这一点。)
当我在 Android 上播放此视频时,音频从头开始播放。使用 VLC 播放效果很好。
预期结果:视频静音直到指定时间,然后是我的音频,音频之后再次静音。
答案1
我最终通过添加 1 个选项解决了这个问题-async
ffmpeg -y -i a.mp4 -itsoffset 00:00:30 -i sng.m4a -map 0:0 -map 1:0 -c:v copy -preset ultrafast -async 1 out.mp4
默认情况下,音频/视频时间戳会被拉伸以相互匹配;这是我的问题,即使给出了“itsoffset”选项,音频仍然从初始位置开始。
按照Ffmpeg 文档,使用-async 1
仅更正音频的初始时间戳。我知道此选项已被弃用;但无论如何它解决了我的情况。