FFmpeg CLI to convert a video file to an MP3 audio file

CK CK 3776 
Created at  
344 0 0

You can use ffmpeg to convert a video file to an MP3 audio file with a simple command. Here’s a straightforward example:

ffmpeg -i input_video.mp4 -vn -acodec libmp3lame -q:a 2 output_audio.mp3

Explanation of Options

  • -i input_video.mp4: Specifies the input video file.
  • -vn: Tells ffmpeg to ignore the video stream (extract only audio).
  • -acodec libmp3lame: Sets the audio codec to libmp3lame, which is a common codec for MP3 encoding.
  • -q:a 2: Controls the audio quality. Lower values give better quality (2 is typically very good; you can adjust from 0–9, with 0 being the best).
  • output_audio.mp3: Specifies the output file name in MP3 format.

 

Example in Python

You can also use ffmpeg in Python via the subprocess module or with the ffmpeg-python library. Here’s an example using ffmpeg-python:

import ffmpeg

# Convert video to mp3
ffmpeg.input('input_video.mp4').output('output_audio.mp3', **{'vn': None, 'q:a': 2}).run()

This script will read input_video.mp4 and output output_audio.mp3 with the specified quality.

Tags FFmpeg FFmpeg MP3 Conversion MP4 to MP3 Facebook X
Comments 0
Similar posts
  1. FFmpeg CLI to merge a video only mp4 and mp3 audio file
    332
  2. FFmpeg CLI to mix two different audios in a single audio file such as mp3
    598
  3. FFmpeg CLI to remove audio track from MP4
    540
  4. Secure HLS encoding using AES-128 encryption with FFmpeg
    1,129
  5. How do I create animated background for Google Meet?
    18,991
  6. FFmpeg compile option to support SCTE-35
    837
  7. Script checking internet restriction with FFmpeg
    678
  8. FFmpeg compile options based on configure
    1,109
  1. Recovering a crashed HLS.js player
    1,273
  2. How do I create animated background for Google Meet?
    18,991
  3. Secure HLS encoding using AES-128 encryption with FFmpeg
    1,129
  4. Machine Learning Models for Ad Detection from a Video Stream
    184
  5. Unlock Flawless HLS Audio Sync: The Power of #EXT-X-INDEPENDENT-SEGMENTS
    368
  6. NVIDIA CUDA library which can be integrated with C/C++
    374
  7. Approaches to Scene Detection in Video Processing
    642
  8. FFmpeg CLI to remove audio track from MP4
    540
  9. Building GPU as a Service aka Dockerized GPU
    1,560
  10. IAB Categories (a.k.a. OpenRTB Code)
    1,012
  11. FFmpeg library that can be directly integrated into C/C++/Rust/Python without CLI
    2,046
  12. HTTP Live Streaming (HLS) was developed by Apple as part of QuickTime X in iOS3.0, and became an official standard (RFC 8126) in 2017
    591
  13. Progressive MP4 is an application of streaming techniques using the standardized MP4 container invented by MPEG LA consortium
    1,068
  14. FFmpeg CLI to mix two different audios in a single audio file such as mp3
    598
  15. FFmpeg CLI to merge a video only mp4 and mp3 audio file
    332
  16. HLS.js options to support subtitle
    511
  17. When HLS.js need to load m3u8 URL redirecting to the different URL (302 Redirection)
    659
  18. HLS.js code to reload when user face bufferfull error
    702
  19. HLS.js code to reload video when levelLoadTimeOut occurs
    703
  20. Change the manifest loading timeout in HLS.js
    1,027
  21. HLS.js Custom Error Handler to load Main Manifest from unstable HLS Live Stream
    1,422
  22. Mastering Audio Sync: Keyframes, GOP, FFmpeg, and HLS Explained
    534
  23. How do I display trickplay images with hls.js that elaborated at EXT-X-IMAGE-STREAM-INF in m3u8
    798
Recently updated
  1. How do I create animated background for Google Meet?
    18,991
  2. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    192
  3. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    75
  4. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    150
  5. Array of arguments passed to script in PHP
    83
  6. Invalid Auction Storms in Ad Tech
    91
  7. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    194
  8. The Two Clocks of Ad Server Architecture
    61
  9. Frequency Cap Architecture Overview
    505
  10. Collecting Proof-of-Play from 100,000 Screens
    139
  11. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    276
  12. What is RedisVL?
    102
  13. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    218
  14. TPU & GPU Cluster Management Tools
    229
  15. The Concept of Scaffolding in AI Agents
    217
  16. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    568
  17. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    246
  18. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    321
  19. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    196
  20. Machine Learning: Training vs. Ranking
    200
  21. The Continuous Learning Machine: Designing a Loop That Actually Turns
    212
  22. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    188
  23. Designing a Data Curation System Around a Vector Database
    212
  24. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    228
  25. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    646
  26. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    179
  27. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    203
  28. Understanding Data Lineage
    251
  29. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    159
  30. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    229