In this tutorial, we will learn working with audio files using FFmpeg to extract audio from video files, convert audio files between different formats, change audio quality and parameters, and add metadata to audio files.


I have recently started using ffmpeg (belatedly!) for my audio and some video content work at gaathastory and my personal blog. While learning how to use this awesome command line tool, I referred to several online tutorials and guides. Below is a short introduction to ffmpeg based on those guides and notes.

Working with audio files using FFMpeg

Step a: Extract Audio from a Video File

Let’s extract the audio from a video file (input.mp4 or input.mov) and save it as an MP3 file (output.mp3) with a bitrate of 128 kbps:

$ ffmpeg -i input.mp4 -b:a 128k output.mp3

Here’s what’s happening:

You can also extract audio from a video file and save it as an OGG or WAV file by changing the output file extension and format:

$ ffmpeg -i input.mp4 -b:a 128k output.ogg
$ ffmpeg -i input.mp4 -b:a 128k output.wav

Step b: Convert Audio File between Formats

Let’s convert an OGG file (input.ogg) to an MP3 file (output.mp3):

$ ffmpeg -i input.ogg -b:a 128k output.mp3

You can also convert an MP3 file to an OGG file or a WAV file:

$ ffmpeg -i input.mp3 -b:a 128k output.ogg
$ ffmpeg -i input.mp3 -b:a 128k output.wav

Step c: Change Audio Quality and Parameters

Let’s change the audio bitrate to 256 kbps and add a low-pass filter to remove high-frequency noise:

$ ffmpeg -i input.mp3 -b:a 256k -af lowpass=f=2000 output.mp3

Here’s what’s happening:

You can also change other audio parameters, such as the sample rate or channels:

$ ffmpeg -i input.mp3 -b:a 256k -ac 2 output.mp3

Here, -ac 2 sets the number of audio channels to stereo.

Step e: Add Metadata to an Audio File

Let’s add metadata to an MP3 file (input.mp3) using FFmpeg:

$ ffmpeg -i input.mp3 -metadata title="My Song" -metadata artist="John Doe" -metadata album="My Album" output.mp3

Here’s what’s happening:

You can add other metadata fields, such as the year or comments:

$ ffmpeg -i input.mp3 -metadata title="My Song" -metadata artist="John Doe" -metadata album="My Album" -metadata date="2022" -metadata comment="This is a great song!" output.mp3

That’s it! You have now learned working with audio files using FFmpeg to extract audio from video files, convert audio files between different formats, change audio quality and parameters, and add metadata to audio files.


ट्यूटोरियल: FFmpeg का उपयोग करके ऑडियो फाइल के साथ काम करना

परिचय

इस ट्यूटोरियल में, हम FFmpeg का उपयोग करके वीडियो फाइल से ऑडियो निकालने, ऑडियो फाइल के प्रारूप बदलने, ऑडियो गुणवत्ता और पैरामीटर बदलने, और ऑडियो फाइल में मेटाडेटा जोड़ने के तरीके सीखेंगे।

चरण a: वीडियो फाइल से ऑडियो निकालना

आइए एक वीडियो फाइल (input.mp4 या input.mov) से ऑडियो निकालकर एक MP3 फाइल (output.mp3) में सहेजते हैं, जिसका बिटरेट 128 kbps है:

$ ffmpeg -i input.mp4 -b:a 128k output.mp3

यहां क्या हो रहा है:

आप एक वीडियो फाइल से ऑडियो निकालकर OGG या WAV फाइल में भी सहेज सकते हैं:

$ ffmpeg -i input.mp4 -b:a 128k output.ogg
$ ffmpeg -i input.mp4 -b:a 128k output.wav

चरण b: ऑडियो फाइल के प्रारूप बदलना

आइए एक OGG फाइल (input.ogg) को MP3 फाइल (output.mp3) में बदलें:

$ ffmpeg -i input.ogg -b:a 128k output.mp3

आप एक MP3 फाइल को OGG फाइल या WAV फाइल में भी बदल सकते हैं:

$ ffmpeg -i input.mp3 -b:a 128k output.ogg
$ ffmpeg -i input.mp3 -b:a 128k output.wav

चरण c: ऑडियो गुणवत्ता और पैरामीटर बदलना

आइए एक MP3 फाइल (input.mp3) की ऑडियो बिटरेट को 256 kbps पर सेट करें और उच्च-आवृत्ति शोर को हटाने के लिए लो-पास फिल्टर जोड़ें:

$ ffmpeg -i input.mp3 -b:a 256k -af lowpass=f=2000 output.mp3

यहां क्या हो रहा है:

आप अन्य ऑडियो पैरामीटर, जैसे नमूना दर या चैनल, भी बदल सकते हैं:

$ ffmpeg -i input.mp3 -b:a 256k -ac 2 output.mp3

यहां, -ac 2 स्टीरियो चैनल निर्दिष्ट करता है।

चरण d: ऑडियो फाइल में मेटाडेटा जोड़ना

आइए एक MP3 फाइल (input.mp3) में मेटाडेटा जोड़ें, जैसे कि शीर्षक, कलाकार, और एल्बम:

$ ffmpeg -i input.mp3 -metadata title="मेरा गाना" -metadata artist="जॉन डो" -metadata album="मेरा एल्बम" output.mp3

यहां क्या हो रहा है:

आप अन्य मेटाडेटा फील्ड, जैसे साल या टिप्पणी, भी जोड़ सकते हैं:

$ ffmpeg -i input.mp3 -metadata title="मेरा गाना" -metadata artist="जॉन डो" -metadata album="मेरा एल्बम" -metadata date="2022" -metadata comment="यह एक अच्छा गाना है!" output.mp3

यही है! अब आप FFmpeg का उपयोग करके वीडियो फाइल से ऑडियो निकालने, ऑडियो फाइल के प्रारूप बदलने, ऑडियो गुणवत्ता और पैरामीटर बदलने, और ऑडियो फाइल में मेटाडेटा जोड़ने के तरीके सीख गए हैं।


Resources and Tools


This post titled working with audio files using FFmpeg was largely possible due to the awesome work by the ffmpeg team.