Using avconv in Ubuntu to export audio from video and merging edited audio with original video
Few days ago, on August 29th, I presented the Ultimate Marketing Class in George Town, Penang, Malaysia.
I used a camera to record my presentation, so I could have more material to promote future events.
The problem is that I was not using a microphone, and the camera was in a place with noise from fans, so it was really hard to hear my voice in the recording.
I learned how to use Audacity to edit audio tracks, removing noise and increase voice volume, but I needed to export the audio from the video so I could edit it, and then merge the edited audio with the original video. And that’s when avconv (former ffmpeg) came to the rescue (I’m using Ubuntu 16.04).
NOTE: actually, you don’t need to export the audio because Audacity can extract audio from video files automatically. Just click File > Open and select the video file.
First of all, make sure you have avconv installed
In Ubuntu 16.04, all you have to do to install avconv is to install the package libav-tools:
$ sudo apt-get update
$ sudo apt-get install libav-conv
It’s useful to have the package mediainfo installed, so you can gather information about video files:
$ sudo apt-get install mediainfo
And now we can go to the commands.
Exporting the audio from a video using avconv
First, use mediainfo to check what’s the audio format in the video:
$ mediainfo UMA-720p-original.mp4
Complete name : UMA-720p-original.mp4
Format : MPEG-4
ID : 2
Format : AAC <= this is what we want to know
Format/Info : Advanced Audio Codec
Format profile : LC
For the AAC audio format, we can use .aac, .m4a or .wav extensions for the exported audio filename. This is the command which does the trick:
$ avconv -i “[input video file]” -map 0:1 -c:a copy “[output audio file]”
Merging an external audio with a video
After you finished editing the export audio, save it in a new file and use the following command to merge the audio with the original video file:
$ avconv -i “[input video file]” -i “[input audio file]” -map 0:0 -map 1:0 -vcodec copy -acodec copy “[output video file]”
You can also convert both video and audio formats on the fly, you just need to add the corresponding parameters. For example, if you want the output video file to be in MP4 format, the command could be the following:
$ avconv -i “[input video file]” -i “[input audio file]” -map 0:0 -map 1:0 -f mp4 -vcodec libx264 -acodec aac -strict -2 “[output video file].mp4”
NOTE: the parameter -strict -2 is required because the AAC audio encoder is experimental in avconv 2.8.6.
I’ll use avconv for several other different tasks and will write articles like this to serve for me as notes in the future. Hope it’s useful for you too.