Reputation: 816
I'm writing a bash script to automatically extract audio track from a video file using avconv
. This script should handle any video format and only extract the audio track without keeping the original codec conversion. For example:
extract_audio name.flv
where the audio track of the flv file is an mp3 should produce a file named name.mp3
, but if it contains and aac track it should produce aumatically name.aac
For now my script looks like this:
#!/bin/bash
dryname=${1%.*} #get remove video extention
avconv -i "$1" -vn -acodec copy "${dryname}.${audio_extension}"
The only part that I miss is how to get the codec used in the audio track of the video file. I'm sure it's possible to do it with an avconv
command but I can't figure it out from the help page.
Upvotes: 0
Views: 453
Reputation: 1709
audio_extension=$(avconv -i "$1" 2>&1 | grep -io "audio:...."|cut -d ' ' -f2)
Upvotes: 2
Reputation: 8879
You can run below command firstly to check codec info, then do extract with proper suffix.
$ avconv -i test.mp4 2>&1 |grep Audio
Stream #0.0(eng): Audio: aac, 44100 Hz, stereo, fltp, 62 kb/s (default)
Upvotes: 1