Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a video file:

screencast.mpg (100sec)

And several audio files(file name indicate offset):

10.wav (10sec)
30.wav (5sec)
45.wav (8sec)

How can I combine those files together:

V:||||||||||||||||||||||||||||||||||||||||||||||||||
A:    .....     ...     ....

I want to write a script to do this job automatically.
I've tried ffmpeg -itsoffset option, but failed.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The following code assumes that your .wav files are 4800 Hz and stereo.
It builds segments of silence, based on the above values.
It produces a single .wav. which can be muxed with the video.

nrChannels=2
sampleRate=48000

rawSilence() {
  local nrSeconds=$1
  local sampleRate=$2
  local nrChannels=${3:-2}
  ffmpeg -acodec pcm_s16le \
         -ar $sampleRate \
         -ac $nrChannels \
         -f s16le \
         -i <(dd if=/dev/zero bs=$((sampleRate*2*nrChannels)) count=$nrSeconds) \
         -f s16le -
}

{ 
  rawSilence 10 $sampleRate $nrChannels 
  cat "10.wav" |ffmpeg -f wav -i - -f s16le -
  rawSilence 10 $sampleRate $nrChannels
  cat "30.wav" |ffmpeg -f wav -i - -f s16le -
  rawSilence 10 $sampleRate $nrChannels
  cat "45.wav" |ffmpeg -f wav -i - -f s16le -
  rawSilence 47 $sampleRate $nrChannels
} |
  ffmpeg -acodec pcm_s16le \
         -ar $sampleRate \
         -ac $nrChannels \
         -f s16le \
         -i - \
         -f wav -y 100sec.wav

To mux the video and audio together, this or some encoding variant should do it:

ffmpeg -i "100sec.mpg" \
       -i "100sec.wav" \
          -vcodec copy \
 -y "100sec.muxed.mpg"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.