FFmpeg CLI to merge a video only mp4 and mp3 audio file

CK CK 3788 
Created at  
340 0 0

You need to merge video and audio files with ffmpeg when you have separate video and audio tracks that you want to combine into a single multimedia file. This is often necessary when editing videos, as you might need to replace the original audio track with a different one, add a soundtrack, or synchronize audio with existing footage. Merging files allows you to create a complete video file with both visual and sound elements, ready for sharing or playback. 
 

To merge a video-only MP4 file and an MP3 audio file into a single video with FFmpeg, use the following command:

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -shortest output.mp4

Explanation:

  • -i video.mp4: Specifies the video-only input file.
  • -i audio.mp3: Specifies the audio input file.
  • -c:v copy: Copies the video stream without re-encoding.
  • -c:a aac: Encodes the audio in AAC format, which is compatible with MP4.
  • -shortest: Ensures the output duration matches the shorter of the two inputs (in case the audio or video is longer than the other).
  • output.mp4: The output file with both video and audio.
Tags FFmpeg FFmpeg CLI FFmpeg merge video Merge Video Facebook X
Comments 0
Similar posts
  1. FFmpeg CLI to mix two different audios in a single audio file such as mp3
    607
  2. FFmpeg CLI to convert a video file to an MP3 audio file
    352
  3. FFmpeg CLI to remove audio track from MP4
    548
  4. Secure HLS encoding using AES-128 encryption with FFmpeg
    1,143
  5. How do I create animated background for Google Meet?
    22,829
  6. FFmpeg compile option to support SCTE-35
    843
  7. Script checking internet restriction with FFmpeg
    686
  8. FFmpeg compile options based on configure
    1,119
  1. Ad Marker: SCTE-35 Message Encoder based in Python
    805
  2. Ad marker: SCTE-35 enhanced
    578
  3. HTTP Proxy when your URL access is blocked with FFmpeg
    1,916
  4. Limit Maximum Resolution in HLS.js
    668
  5. Magic line when HLS video manifest is mixed with encrypted / unencrypted video chunks
    1,477
  6. Recovering a crashed HLS.js player
    1,289
  7. Machine Learning Models for Ad Detection from a Video Stream
    194
  8. Unlock Flawless HLS Audio Sync: The Power of #EXT-X-INDEPENDENT-SEGMENTS
    380
  9. NVIDIA CUDA library which can be integrated with C/C++
    377
  10. Approaches to Scene Detection in Video Processing
    651
  11. Building GPU as a Service aka Dockerized GPU
    1,595
  12. IAB Categories (a.k.a. OpenRTB Code)
    1,018
  13. FFmpeg library that can be directly integrated into C/C++/Rust/Python without CLI
    2,099
  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,085
  16. HLS.js options to support subtitle
    521
  17. When HLS.js need to load m3u8 URL redirecting to the different URL (302 Redirection)
    666
  18. HLS.js code to reload when user face bufferfull error
    705
  19. HLS.js code to reload video when levelLoadTimeOut occurs
    714
  20. Change the manifest loading timeout in HLS.js
    1,046
  21. HLS.js Custom Error Handler to load Main Manifest from unstable HLS Live Stream
    1,436
  22. Mastering Audio Sync: Keyframes, GOP, FFmpeg, and HLS Explained
    547
  23. How do I display trickplay images with hls.js that elaborated at EXT-X-IMAGE-STREAM-INF in m3u8
    812
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    28
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    55
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    49
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    271
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    103
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    168
  7. Array of arguments passed to script in PHP
    97
  8. Invalid Auction Storms in Ad Tech
    106
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    207
  10. The Two Clocks of Ad Server Architecture
    77
  11. Frequency Cap Architecture Overview
    526
  12. Collecting Proof-of-Play from 100,000 Screens
    152
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    302
  14. What is RedisVL?
    114
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    246
  16. TPU & GPU Cluster Management Tools
    257
  17. The Concept of Scaffolding in AI Agents
    244
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    596
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    267
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    353
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    206
  22. Machine Learning: Training vs. Ranking
    229
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    228
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    202
  25. Designing a Data Curation System Around a Vector Database
    230
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    671
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    200
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    232
  30. Understanding Data Lineage
    271