FFmpeg CLI to mix two different audios in a single audio file such as mp3

CK CK 3788 
Created at  
603 0 0

FFmpeg offers a wide range of mixers for audio and video processing. You can use the `amix` filter for audio mixing, which allows combining multiple audio streams into a single output. For video, `overlay` is commonly used to superimpose one video stream onto another, while `blend` enables mixing two video streams with configurable transparency levels. These are just some examples, and FFmpeg provides many other options for mixing audio and video based on your specific needs. 
 

To mix different audio tracks into a single audio stream with ffmpeg, you can use the -filter_complex option along with the amix filter, which allows you to combine multiple audio inputs into one output. Here’s a simple command to do it:

ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest" -c:a libmp3lame output.mp3

Explanation:

  • -i audio1.mp3 and -i audio2.mp3: Specify the input audio files.
  • -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest":
    • [0:a][1:a] are the audio streams from each input.
    • amix=inputs=2: Mixes 2 audio inputs.
    • duration=longest: Ensures the output lasts as long as the longest input file. You can also use shortest to stop when the shortest input ends.
  • -c:a libmp3lame: Specifies the MP3 codec for the output.
  • output.mp3: Name of the output file.

 

Additional Options

You can adjust the mix levels by adding weights. For example, to give audio1 twice the volume of audio2:

ffmpeg -i audio1.mp3 -i audio2.mp3 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest:weights='2 1'" -c:a libmp3lame output.mp3

This command will give you a single mixed audio file with balanced audio from both sources.

Tags Audio Mixing FFmpeg FFmpeg Audio Mixer FFmpeg CLI amix Facebook X
Comments 0
Similar posts
  1. FFmpeg CLI to merge a video only mp4 and mp3 audio file
    334
  2. FFmpeg CLI to convert a video file to an MP3 audio file
    348
  3. FFmpeg CLI to remove audio track from MP4
    542
  4. Secure HLS encoding using AES-128 encryption with FFmpeg
    1,131
  5. How do I create animated background for Google Meet?
    20,611
  6. FFmpeg compile option to support SCTE-35
    838
  7. Script checking internet restriction with FFmpeg
    682
  8. FFmpeg compile options based on configure
    1,111
  1. Limit Maximum Resolution in HLS.js
    664
  2. Magic line when HLS video manifest is mixed with encrypted / unencrypted video chunks
    1,461
  3. Recovering a crashed HLS.js player
    1,278
  4. How do I create animated background for Google Meet?
    20,611
  5. Secure HLS encoding using AES-128 encryption with FFmpeg
    1,131
  6. Machine Learning Models for Ad Detection from a Video Stream
    188
  7. Unlock Flawless HLS Audio Sync: The Power of #EXT-X-INDEPENDENT-SEGMENTS
    375
  8. NVIDIA CUDA library which can be integrated with C/C++
    376
  9. Approaches to Scene Detection in Video Processing
    645
  10. FFmpeg CLI to remove audio track from MP4
    542
  11. Building GPU as a Service aka Dockerized GPU
    1,575
  12. IAB Categories (a.k.a. OpenRTB Code)
    1,013
  13. FFmpeg library that can be directly integrated into C/C++/Rust/Python without CLI
    2,068
  14. 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
    596
  15. Progressive MP4 is an application of streaming techniques using the standardized MP4 container invented by MPEG LA consortium
    1,076
  16. FFmpeg CLI to merge a video only mp4 and mp3 audio file
    334
  17. FFmpeg CLI to convert a video file to an MP3 audio file
    348
  18. HLS.js options to support subtitle
    516
  19. When HLS.js need to load m3u8 URL redirecting to the different URL (302 Redirection)
    662
  20. HLS.js code to reload when user face bufferfull error
    705
  21. HLS.js code to reload video when levelLoadTimeOut occurs
    707
  22. Change the manifest loading timeout in HLS.js
    1,038
  23. HLS.js Custom Error Handler to load Main Manifest from unstable HLS Live Stream
    1,431
  24. Mastering Audio Sync: Keyframes, GOP, FFmpeg, and HLS Explained
    538
  25. How do I display trickplay images with hls.js that elaborated at EXT-X-IMAGE-STREAM-INF in m3u8
    804
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    39
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,611
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    243
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    216
  30. Understanding Data Lineage
    260