ffmpeg placing audio at specific location [closed]

Solution 1:

Say you want to lay Audio tracks on to a video file at various points. The Audio tracks that you use will be cut and trimmed at various points. In the following example, one audio is from the video file itself, and there is a second one from from a purely audio file- a wav file. The video file is videoandaudio.mov and the audio is audio_only.wav.

The atrim filter "cuts" the audio channels. The adelay filter places the audio at various points. The amix filter mixes those audios into a single mixed output. The aformat filter ensures consistency. Especially for flv you need sampling not more than 44100Hz.

In the example the audio of the video file is used upto 20 seconds. The second audio actually starts at 10000 milliseconds, which is earlier than the end of the audio (20 seconds) but this illustrative example purposely shows that amix can handle that. After that the second audio kicks in and goes till we trim the end at 240 seconds. The flv1 coder is again illustrative only- you can use anything. Be sure to use nice bitrates and other parameters for the video. For audio you can't do a-acodec copy if you use filtergraph so I am showing with PCM.

ffmpeg -i videoandaudio.mov -i audio_only.wav  -filter_complex 
  "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=mono,
     atrim=end=20[aud1];
   [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=mono,
     atrim=end=240[bud2];
   [bud2]adelay=10000[aud2];
   [aud1][aud2]amix=inputs=2"
  -map 0:v -c:v flv1 -pix_fmt yuv420p -c:a pcm_s16le out.flv