среда, 11 сентября 2013 г.

Extract audio with silence from video with ffmpeg

Usually excracting audio track from video file is not a problem and can be done using ffmpeg:
ffmpeg -i video.avi -vn result_audio_track.wav
But if you have video where audio track has silent parts, the command above will extract and concatenate only the parts where audio is not silent. So the result audio track will be shorter than the original. To overcome this the additional parameters should be set:
ffmpeg -i video.avi -vn -af \
    aresample=min_comp=0.001:min_hard_comp=0.100000 \
    result_audio_track.wav
These options prevent ffmpeg from dropping silent parts of audio track:
  • aresample resamples the input audio to the specified parameters.
  • min_comp sets the minimum difference between timestamps and audio data (in seconds) to trigger stretching/squeezing/filling or trimming of the data to make it match the timestamps.
  • min_hard_comp sets the minimum difference between timestamps and audio data (in seconds) to trigger adding/dropping samples to make it match the timestamps.