Separate Audio from Video (with ffmpeg)

Hello 👋

In this short article I will show you how to split audio from video using ffmpeg.

When I worked on my Udemy course I needed a way to process audio in Audacity and edit the video in Kdenlive.

So I wrote two bash scripts, one for spliting audio and video and another one to combine the processed audio (usually a .wav file with the same name) with the video.

The result is the following

split-video.sh

filename=`echo "$1" | awk '{gsub(/.*[/]|[.].*/, "", $0)} 1'`
ffmpeg -i "$1" -vn -c:a copy "${filename}Temp.m4a"
ffmpeg -i "$1" -an -c:v copy "${filename}Temp.mp4"

combine-video.sh

filename=`echo "$1" | awk '{gsub(/.*[/]|[.].*/, "", $0)} 1'`
ffmpeg -i "./${filename}Temp.mp4" -i "./${filename}Temp.wav" -c:v copy -c:a aac "./${filename}Final.mp4"
rm "./${filename}Temp.m4a"
rm "./${filename}Temp.mp4"

Thanks for reading and happy hacking! 🏄

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.