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:
ffmpegis the command to execute FFmpeg.-i input.mp4: specifies the input file.-b:a 128k: sets the audio bitrate to 128 kbps.output.mp3: specifies the output file name and format.
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:
-b:a 256k: sets the audio bitrate to 256 kbps.-af lowpass=f=2000: applies a low-pass filter to remove high-frequency noise above 2000 Hz.
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:
-metadata title="My Song": sets the title of the song.-metadata artist="John Doe": sets the artist’s name.-metadata album="My Album": sets the album title.
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
यहां क्या हो रहा है:
ffmpeg: FFmpeg का आदेश है।-i input.mp4: इनपुट फाइल निर्दिष्ट करता है।-b:a 128k: ऑडियो बिटरेट को 128 kbps पर सेट करता है।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
यहां क्या हो रहा है:
-b:a 256k: ऑडियो बिटरेट को 256 kbps पर सेट करता है।-af lowpass=f=2000: 2000 Hz से ऊपर के उच्च-आवृत्ति शोर को हटाने के लिए लो-पास फिल्टर लागू करता है।
आप अन्य ऑडियो पैरामीटर, जैसे नमूना दर या चैनल, भी बदल सकते हैं:
$ 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
यहां क्या हो रहा है:
-metadata title="मेरा गाना": गाने का शीर्षक निर्दिष्ट करता है।-metadata artist="जॉन डो": कलाकार का नाम निर्दिष्ट करता है।-metadata album="मेरा एल्बम": एल्बम का नाम निर्दिष्ट करता है।
आप अन्य मेटाडेटा फील्ड, जैसे साल या टिप्पणी, भी जोड़ सकते हैं:
$ ffmpeg -i input.mp3 -metadata title="मेरा गाना" -metadata artist="जॉन डो" -metadata album="मेरा एल्बम" -metadata date="2022" -metadata comment="यह एक अच्छा गाना है!" output.mp3
यही है! अब आप FFmpeg का उपयोग करके वीडियो फाइल से ऑडियो निकालने, ऑडियो फाइल के प्रारूप बदलने, ऑडियो गुणवत्ता और पैरामीटर बदलने, और ऑडियो फाइल में मेटाडेटा जोड़ने के तरीके सीख गए हैं।
Resources and Tools
- FFmpeg Official Documentation: The official FFmpeg documentation is an exhaustive resource that covers everything from basic usage to advanced topics.
- FFmpeg Tutorials by Digital Video: Digital Video offers a comprehensive series of FFmpeg tutorials that cover topics such as video encoding, decoding, and streaming.
- FFmpeg Guide: The FFmpeg Guide is a detailed resource that covers the basics of FFmpeg, including installation, command-line usage, and examples.
- Learn FFmpeg by tutorialspoint: tutorialspoint offers a comprehensive FFmpeg tutorial that covers topics such as video and audio processing, streaming, and more.
- FFmpeg Cheat Sheet: This FFmpeg cheat sheet provides a concise reference guide for common FFmpeg commands and options.
This post titled working with audio files using FFmpeg was largely possible due to the awesome work by the ffmpeg team.