Tuesday, May 12, 2009

Extract audio tracks from video

To extract audio tracks from videos:
ffmpeg -i video.aviInput #0, avi, from 'video.avi':
Duration: 00:55:21.8, start: 0.000000, bitrate: 1380 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 704x384, 25.00 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 160 kb/s
Stream #0.2: Audio: mp3, 48000 Hz, stereo, 160 kb/s
Must supply at least one output file


With that command, we don't extract anything, but we can see the audio track amount.
We see, that the video has 2 audio tracks. To extract one:

ffmpeg -i video.avi -map 0.2 audio.mp3Input #0, avi, from 'video.avi':
Duration: 00:55:21.8, start: 0.000000, bitrate: 1380 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 704x384, 25.00 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 160 kb/s
Stream #0.2: Audio: mp3, 48000 Hz, stereo, 160 kb/s
Must supply at least one output file


We'll get the second audio track into audio.mp3 file.

In the case that we want to extract all audio's from all video's:
j=1;for i in *.avi;
do ffmpeg -i "$i" -map 0.2 /home/pron/SubWorkspace/Audio$j.mp3;
((j++));done;


For each avi file, we'll get an Audio?.mp3 file.

No comments: