Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

how to add audio to existing video using FFMPEG at specific time?

I have video file (.avi) that contain video of 10 minutes. I also have audio file (.wav) that contain 1 minute of sound.

I need to add the audio to the exist video but the audio need to start at after one minute of the video

How to do it ?

( prefer using ffmpeg if its possible )

try already this query ( 30 seconds delay )

-i video.avi -i audio.wav -filter_complex "[1]adelay=30000|30000[aud];[0][aud]amix" - c:v copy out.avi"

Attached the log of ffmpeg when trying to merge more then one wav:

ffmpeg started on 2018-01-10 at 11:14:57
Report written to "ffmpeg-20180110-111457.log"
Command line:
ffmpeg.exe -report -i "..\merged.avi" -i "Storage\1.wav" -i "Storage\2.wav" -i "Storage\3.wav" -filter_complex "adelay=30000|30000" "adelay=91000|91000" "adelay=151000|151000" -c:v copy "Storage\ALL.AVI"
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Splitting the commandline.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-i' ... matched as input url with argument '..mergedVideoOnly.avi'.
Reading option '-i' ... matched as input url with argument 'Storage030_0130.wav'.
Reading option '-i' ... matched as input url with argument 'Storage130_0230.wav'.
Reading option '-i' ... matched as input url with argument 'Storage230_0330.wav'.
Reading option '-filter_complex' ... matched as option 'filter_complex' (create a complex filtergraph) with argument 'adelay=30000|30000'.
Reading option 'adelay=91000|91000' ... matched as output url.
Reading option 'adelay=151000|151000' ... matched as output url.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option 'ALL.AVI' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Applying option filter_complex (create a complex filtergraph) with argument adelay=30000|30000.
Successfully parsed a group of options.
Parsing a group of options: input url ..mergedVideoOnly.avi.
Successfully parsed a group of options.
Opening an input file: ..mergedVideoOnly.avi.
[NULL @ 042ed360] Opening '..mergedVideoOnly.avi' for reading
[file @ 042ee300] Setting default whitelist 'file,crypto'
[avi @ 042ed360] Format avi probed with size=2048 and score=100
[avi @ 042ee500] use odml:1
[avi @ 042ed360] Before avformat_find_stream_info() pos: 5690 bytes read:100744 seeks:4 nb_streams:1
[avi @ 042ed360] parser not found for codec scpr, packets or times may be invalid.
[avi @ 042ed360] parser not found for codec scpr, packets or times may be invalid.
[avi @ 042ed360] max_analyze_duration 5000000 reached at 5000000 microseconds st:0
[avi @ 042ed360] rfps: 2.916667 0.012539
[avi @ 042ed360] rfps: 2.916667 0.012539
[avi @ 042ed360] rfps: 3.000000 0.000000
[avi @ 042ed360] rfps: 3.083333 0.012539
[avi @ 042ed360] rfps: 3.083333 0.012539
[avi @ 042ed360] rfps: 5.916667 0.012539
[avi @ 042ed360] rfps: 5.916667 0.012539
[avi @ 042ed360] rfps: 6.000000 0.000000
[avi @ 042ed360] rfps: 6.000000 0.000000
[avi @ 042ed360] rfps: 6.083333 0.012539
[avi @ 042ed360] rfps: 6.083333 0.012539
[avi @ 042ed360] rfps: 8.916667 0.012539
[avi @ 042ed360] rfps: 8.916667 0.012539
[avi @ 042ed360] rfps: 9.000000 0.000000
[avi @ 042ed360] rfps: 9.083333 0.012539
[avi @ 042ed360] rfps: 9.083333 0.012539
[avi @ 042ed360] rfps: 11.916667 0.012539
[avi @ 042ed360] rfps: 11.916667 0.012539
[avi @ 042ed360] rfps: 12.000000 0.000000
[avi @ 042ed360] rfps: 12.000000 0.000000
[avi @ 042ed360] rfps: 12.083333 0.012539
[avi @ 042ed360] rfps: 12.083333 0.012539
[avi @ 042ed360] rfps: 14.916667 0.012539
[avi @ 042ed360] rfps: 14.916667 0.012539
[avi @ 042ed360] rfps: 15.000000 0.000000
[avi @ 042ed360] rfps: 15.083333 0.012539
[avi @ 042ed360] rfps: 15.083333 0.012539
[avi @ 042ed360] rfps: 17.916667 0.012539
[avi @ 042ed360] rfps: 17.916667 0.012539
[avi @ 042ed360] rfps: 18.000000 0.000000
[avi @ 042ed360] rfps: 18.000000 -0.000000
[avi @ 042ed360] rfps: 18.083333 0.012539
[avi @ 042ed360] rfps: 18.083333 0.012539
[avi @ 042ed360] rfps: 20.916667 0.012539
[avi @ 042ed360] rfps: 20.916667 0.012539
[avi @ 042ed360] rfps: 21.000000 0.000000
[avi @ 042ed360] rfps: 21.083333 0.012539
[avi @ 042ed360] rfps: 21.083333 0.012539
[avi @ 042ed360] rfps: 23.916667 0.012539
[avi @ 042ed360] rfps: 23.916667 0.012539
[avi @ 042ed360] rfps: 24.000000 0.000000
[avi @ 042ed360] rfps: 24.000000 -0.000000
[avi @ 042ed360] rfps: 24.083333 0.012539
[avi @ 042ed360] rfps: 24.083333 0.012539
[avi @ 042ed360] rfps: 26.916667 0.012539
[avi @ 042ed360] rfps: 26.916667 0.012539
[avi @ 042ed360] rfps: 27.000000 0.000000
[avi @ 042ed360] rfps: 27.083333 0.012539
[avi @ 042ed360] rfps: 27.083333 0.012539
[avi @ 042ed360] rfps: 29.916667 0.012539
[avi @ 042ed360] rfps: 29.916667 0.012539
[avi @ 042ed360] rfps: 30.000000 0.000000
[avi @ 042ed360] rfps: 30.000000 -0.000000
[avi @ 042ed360] rfps: 33.000000 0.000000
[avi @ 042ed360] rfps: 36.000000 0.000000
[avi @ 042ed360] rfps: 36.000000 -0.000000
[avi @ 042ed360] rfps: 39.000000 0.000000
[avi @ 042ed360] rfps: 42.000000 0.000000
[avi @ 042ed360] rfps: 42.000000 0.000000
[avi @ 042ed360] rfps: 45.000000 0.000000
[avi @ 042ed360] rfps: 48.000000 0.000000
[avi @ 042ed360] rfps: 48.000000 0.000000
[avi @ 042ed360] rfps: 51.000000 0.000000
[avi @ 042ed360] rfps: 54.000000 0.000000
[avi @ 042ed360] rfps: 54.000000 -0.000000
[avi @ 042ed360] rfps: 57.000000 0.000000
[avi @ 042ed360] rfps: 60.000000 0.000000
[avi @ 042ed360] rfps: 60.000000 0.000000
[avi @ 042ed360] rfps: 120.000000 0.000000
[avi @ 042ed360] rfps: 120.000000 -0.000000
[avi @ 042ed360] rfps: 240.000000 0.000000
[avi @ 042ed360] rfps: 240.000000 -0.000000
[avi @ 042ed360] rfps: 23.976024 0.001038
[avi @ 042ed360] rfps: 23.976024 0.001038
[avi @ 042ed360] rfps: 29.970030 0.001622
[avi @ 042ed360] rfps: 29.970030 0.001622
[avi @ 042ed360] rfps: 59.940060 0.006487
[avi @ 042ed360] rfps: 59.940060 0.006487
[avi @ 042ed360] rfps: 11.988012 0.000259
[avi @ 042ed360] rfps: 11.988012 0.000259
[avi @ 042ed360] rfps: 14.985015 0.000405
[avi @ 042ed360] rfps: 14.985015 0.000405
[avi @ 042ed360] rfps: 47.952048 0.004152
[avi @ 042ed360] rfps: 47.952048 0.004152
[avi @ 042ed360] After avformat_find_stream_info() pos: 105829 bytes read:175139 seeks:4 frames:15
Input #0, avi, from '..mergedVideoOnly.avi':
  Metadata:
    encoder         : Lavf57.83.100
  Duration: 00:00:25.33, start: 0.000000, bitrate: 113 kb/s
    Stream #0:0, 15, 1/3: Video: scpr (SCPR / 0x52504353), rgb0, 1920x1200, 112 kb/s, 3 fps, 3 tbr, 3 tbn, 3 tbc
Successfully opened the file.
Parsing a group of options: input url " "Storage030_0130.wav.
Successfully parsed a group of options.
Opening an input file: " "Storage1.wav.
[NULL @ 03be0180] Opening '" "Storage1.wav' for reading
[file @ 03be0820] Setting default whitelist 'file,crypto'
[wav @ 03be0180] Format wav probed with size=2048 and score=99
[wav @ 03be0180] Before avformat_find_stream_info() pos: 44 bytes read:65580 seeks:1 nb_streams:1
[wav @ 03be0180] probing stream 0 pp:32
[wav @ 03be0180] probing stream 0 pp:31
[wav @ 03be0180] probing stream 0 pp:30
[wav @ 03be0180] probing stream 0 pp:29
[wav @ 03be0180] probing stream 0 pp:28
[wav @ 03be0180] probing stream 0 pp:27
[wav @ 03be0180] probing stream 0 pp:26
[wav @ 03be0180] probing stream 0 pp:25
[wav @ 03be0180] probing stream 0 pp:24
[wav @ 03be0180] probing stream 0 pp:23
[wav @ 03be0180] probing stream 0 pp:22
[wav @ 03be0180] probing stream 0 pp:21
[wav @ 03be0180] probing stream 0 pp:20
[wav @ 03be0180] probing stream 0 pp:19
[wav @ 03be0180] probing stream 0 pp:18
[wav @ 03be0180] probing stream 0 pp:17
[wav @ 03be0180] probing stream 0 pp:16
[wav @ 03be0180] probing stream 0 pp:15
[wav @ 03be0180] probing stream 0 pp:14
[wav @ 03be0180] probing stream 0 pp:13
[wav @ 03be0180] probing stream 0 pp:12
[wav @ 03be0180] probing stream 0 pp:11
[wav @ 03be0180] probing stream 0 pp:10
[wav @ 03be0180] probing stream 0 pp:9
[wav @ 03be0180] probing stream 0 pp:8
[wav @ 03be0180] probing stream 0 pp:7
[wav @ 03be0180] probing stream 0 pp:6
[wav @ 03be0180] probing stream 0 pp:5
[wav @ 03be0180] probing stream 0 pp:4
[wav @ 03be0180] probing stream 0 pp:3
[wav @ 03be0180] probing stream 0 pp:2
[wav @ 03be0180] probing stream 0 pp:1
[wav @ 03be0180] probed stream 0
[wav @ 03be0180] parser not found for codec pcm_s16le, packets or times may be invalid.
[wav @ 03be0180] max_analyze_duration 5000000 reached at 5120000 microseconds st:0
[wav @ 03be0180] After avformat_find_stream_info() pos: 131116 bytes read:196652 seeks:1 frames:22
Guessed Channel Layout for Input Stream #1.0 : mono
Input #1, wav, from '" "Storage030_0130.wav':
  Duration: 00:00:56.80, bitrate: 128 kb/s
    Stream #1:0, 22, 1/8000: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
Successfully opened the file.
Parsing a group of options: input url " "Storage2.wav.
Successfully parsed a group of options.
Opening an input file: " "Storage2.wav.
[NULL @ 03bed760] Opening '" "Storage2.wav' for reading
[file @ 03bb3100] Setting default whitelist 'file,crypto'
[wav @ 03bed760] Format wav probed with size=2048 and score=99
[wav @ 03bed760] Before avformat_find_stream_info() pos: 44 bytes read:65580 seeks:1 nb_streams:1
[wav @ 03bed760] probing stream 0 pp:32
[wav @ 03bed760] probing stream 0 pp:31
[wav @ 03bed760] probing stream 0 pp:30
[wav @ 03bed760] probing stream 0 pp:29
[wav @ 03bed760] probing stream 0 pp:28
[wav @ 03bed760] probing stream 0 pp:27
[wav @ 03bed760] probing stream 0 pp:26
[wav @ 03bed760] probing stream 0 pp:25
[wav @ 03bed760] probing stream 0 pp:24
[wav @ 03bed760] probing stream 0 pp:23
[wav @ 03bed760] probing stream 0 pp:22
[wav @ 03bed760] probing stream 0 pp:21
[wav @ 03bed760] probing stream 0 pp:20
[wav @ 03bed760] probing stream 0 pp:19
[wav @ 03bed760] probing stream 0 pp:18
[wav @ 03bed760] probing stream 0 pp:17
[wav @ 03bed760] probing stream 0 pp:16
[wav @ 03bed760] probing stream 0 pp:15
[wav @ 03bed760] probing stream 0 pp:14
[wav @ 03bed760] probing stream 0 pp:13
[wav @ 03bed760] probing stream 0 pp:12
[wav @ 03bed760] probing stream 0 pp:11
[wav @ 03bed760] probing stream 0 pp:10
[wav @ 03bed760] probing stream 0 pp:9
[wav @ 03bed760] probing stream 0 pp:8
[wav @ 03bed760] probing stream 0 pp:7
[wav @ 03bed760] probing stream 0 pp:6
[wav @ 03bed760] probing stream 0 pp:5
[wav @ 03bed760] probing stream 0 pp:4
[wav @ 03bed760] probing stream 0 pp:3
[wav @ 03bed760] probing stream 0 pp:2
[wav @ 03bed760] probing stream 0 pp:1
[wav @ 03bed760] probed stream 0
[wav @ 03bed760] parser not found for codec pcm_s16

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use

ffmpeg -i in.avi -i audio.wav -filter_complex
"[1]adelay=62000|62000[aud];[0][aud]amix" -c:v copy out.avi

The adelay delays the start of the WAV by 62000 milliseconds for all channels, assuming 2 channels in the WAV and then that is mixed with the video's audio.


To mix two audio files,

ffmpeg -i in.avi -i audio1.wav -i audio2.wav -filter_complex
"[1]adelay=30000|30000[aud1];[2]adelay=90000|90000[aud2];
 [0][aud1][aud2]amix=3" -c:v copy out.avi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...