Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversBlack Friday PreviewAmazon USBlack Friday preview: compare before the rush hitsAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to the story
DocumentaryTubeTRUE STORIES, ON SCREEN.
  1. DocumentaryTube
  2. The Screening Room
  3. Blog

Blog

How to Use FFmpeg to Mix Background Music Under a Prerecorded YouTube Video

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use FFmpeg’s amix filter to blend a video’s existing speech or ambience with a separate music file. Lower the music before mixing, choose which audio input controls the mix length, and encode the filtered audio while copying the video stream when its codec is compatible with the output container.

Mix the original audio and music with FFmpeg

The command below keeps the video stream, mixes its first audio stream with a music file, and writes a new AAC audio stream in an MP4 container:

ffmpeg -i input.mp4 -i music.mp3 
  -filter_complex "[1:a:0]volume=0.25[music];[0:a:0][music]amix=inputs=2:duration=first:dropout_transition=0[mix]" 
  -map 0:v:0 -map "[mix]" -c:v copy -c:a aac -b:a 192k output.mp4

Replace input.mp4 and music.mp3 with your file names. FFmpeg’s filter documentation describes amix as combining multiple audio inputs into one output. This command is an illustrative pattern, not a guarantee that every source file has the same stream layout or compatible codecs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the command does

  • -i input.mp4 and -i music.mp3 load the video and music as inputs 0 and 1.
  • [1:a:0]volume=0.25[music] reduces the music input before the mix. The value is a starting point, not a universal voice-to-music setting; listen to the result and adjust for the material.
  • [0:a:0][music]amix=inputs=2:duration=first:dropout_transition=0[mix] combines the first audio stream from the video with the adjusted music. duration=first makes the first audio input determine the mix’s duration. A zero-second dropout transition disables the renormalization transition as an input ends.
  • -map 0:v:0 selects the first video stream, while -map "[mix]" selects the filtered audio output.
  • -c:v copy copies video without re-encoding it, if the source video codec is compatible with MP4. The filtered audio cannot be stream-copied, so -c:a aac encodes it as AAC; -b:a 192k sets the audio bitrate.

Check that the source has audio

This pattern expects an audio stream at [0:a:0]. If the video has no audio, there is nothing to preserve: mix the music input by itself and map that filtered result. If the file has multiple audio streams, confirm which one you want before choosing its stream index. The -map selections must match the streams and labels that actually exist in your inputs.

Popular on Amazon
Audio-Technica ATH-M20x Professional Studio Monitor Headphones, Black | 96dB Sensitivity, 15-20kHz Frequency Response, Suspension Headband, 6.3mm Adapter, for Monitoring, Tracking and Mixing
  • Advanced build quality and engineering; Designed for studio tracking and mixing
  • 40 mm drivers with rare earth magnets and copper clad aluminum wire voice coils
  • Tuned for enhanced low frequency performance
  • Circumaural design contours around the ears for excellent sound isolation in loud environments
  • Convenient single side cable exit

Choose how long the mix should run

The duration option determines when amix ends its output:

Setting When the mix ends Use it when
duration=first When the first audio input ends The original video audio should control the mix length, as in the example.
duration=shortest When the shortest audio input ends You do not want the mix to outlast whichever audio stream is shorter.
duration=longest When the longest audio input ends You want the longer audio input to continue after the shorter one ends.

These options concern the audio inputs, not necessarily the video’s end time. If the video ends before the mixed audio, consider output-level duration handling such as -shortest, then check the exported file. The result depends on the streams’ actual lengths, so review the end of the file rather than assuming the selected audio duration also sets the video duration.

Also popular on Amazon
OneOdio Wired DJ Hi-Res Over-Ear Headphones for PC, Keyboard Guitar - Black | headphone with 50mm drivers, dual 3.5mm and 6.35mm jacks for studio monitoring, recording, podcasting, mixing and DJ use.
  • Bass Sound: Enjoy clear sound and superior comfort with the OneOdio Studio Monitor Headphones. Equipped with large 50mm speaker drivers and neodymium magnets, pro-10 deliver powerful bass, clear vocals, and crisp highs for a balanced stereo sound.
  • Built for Comfort: The soft, padded ear cushions are designed to provide long-lasting comfort and effective noise isolation. The adjustable, stretchable headband allows you to easily find the perfect fit and angle for your listening pleasure.
  • Single-side Monitoring: The 90° swiveling ear cups allow for single-ear monitoring, making it ideal for DJing or mixing. The self-adjusting and flexible headband ensures a fatigue-free listening experience, even during extended sessions, making these headphones perfect for mastering and mixing.
  • Compatibility: Pro-10 wired headphones work exclusively in wired mode and are compatible with a wide range of devices, including smartphones, laptops, tablets, desktop computers, audio interfaces, DJ mixers, amplifiers, and any device that features either a 3.5mm or 6.35mm audio jack.
  • Share Audio Port: With a shared audio port, easily connect another pair to share music or videos—no splitters or special cables needed.

Set the music level and avoid clipping

The example applies volume=0.25 to the music alone, so the original sound is not turned down by that filter. Adjust the gain by listening to the exported mix: speech should remain intelligible, while music should sit at the prominence you intend. No single gain value suits every recording.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

amix normalization is enabled by default. If you disable it, FFmpeg warns that clipping can be heavy unless you manage input levels. Listen for distortion and check that the mix remains clear, especially where loud speech, ambience, or musical peaks overlap.

Also popular on Amazon
Sale
Sony MDR7506 Professional Large Diaphragm Headphone
  • Neodymium magnets and 40 millimeter drivers for powerful, detailed sound.Specific uses for product : Professional audio system,Home audio system
  • Closed ear design provides comfort and outstanding reduction of external noises
  • 9.8 foot cord ends in gold plated plug and it is not detachable; 1/4 inch adapter included
  • Folds up for storage or travel in provided soft case
  • Frequency Response: 10 Hertz to 20 kilohertz

The dropout_transition option controls how long volume renormalization takes when an input ends; its documented default is two seconds. Use dropout_transition=0 to avoid that transition, or omit the option if you want the documented default behavior. amix is for summing audio inputs; amerge serves a different purpose, combining channels rather than making this kind of background mix.

Check the export before uploading

  • Play the file from beginning to end, including the last seconds, to check audio intelligibility, clipping, and whether the mix ends as intended.
  • Confirm that the video is present and that its duration is not unexpectedly shorter than the audio.
  • If stream-copying the video fails because the source codec is unsuitable for the target container, choose a compatible output/container or encode the video instead of using -c:v copy.
  • If FFmpeg reports a missing stream, inspect the input’s stream layout and correct the audio index or mapping; a video without an audio stream cannot use the example’s original-audio label.

Check music rights before publishing on YouTube

Technical ability to mix a track into a video does not establish permission to publish it. YouTube says music and sound effects in its Audio Library in YouTube Studio are royalty-free, and identifies tracks from that library as the music it knows to be copyright-safe. Some Audio Library tracks use Creative Commons licenses and require attribution in the video description; check the selected track’s terms and provide the required credit.

Also popular on Amazon
Audio-Technica ATH-M50X Professional Studio Monitor Headphones, Black, Professional Grade, Critically Acclaimed, with Detachable Cable
  • Critically acclaimed sonic performance praised by top audio engineers and pro audio reviewers
  • Proprietary 45 millimeter large aperture drivers with rare earth magnets and copper clad aluminum wire voice coils
  • Exceptional clarity throughout an extended frequency range, with deep, accurate bass response
  • Circumaural design contours around the ears for excellent sound isolation in loud environments
  • 90 degree swiveling earcups for easy, one ear monitoring, and professional grade earpad and headband material delivers more durability and comfort

YouTube says it cannot give legal advice and is not responsible for issues with music from other libraries. An external source’s “royalty-free” label alone is not YouTube’s assurance. Check the applicable license and attribution requirements for the exact track before uploading.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or let it run in the cloud

FFmpeg prepares a prerecorded video file; it does not keep a YouTube live stream running. If your goal is to loop prerecorded videos as a 24/7 YouTube stream, StreamNeo is a separate cloud option: upload a recording or playlist, add your YouTube stream key, and go live. It plays uploaded videos, not a camera feed.

Quick Recap

Bestseller No. 1
Audio-Technica ATH-M20x Professional Studio Monitor Headphones, Black | 96dB Sensitivity, 15-20kHz Frequency Response, Suspension Headband, 6.3mm Adapter, for Monitoring, Tracking and Mixing
Audio-Technica ATH-M20x Professional Studio Monitor Headphones, Black | 96dB Sensitivity, 15-20kHz Frequency Response, Suspension Headband, 6.3mm Adapter, for Monitoring, Tracking and Mixing
Advanced build quality and engineering; Designed for studio tracking and mixing; 40 mm drivers with rare earth magnets and copper clad aluminum wire voice coils
$59.00
SaleBestseller No. 3
Sony MDR7506 Professional Large Diaphragm Headphone
Sony MDR7506 Professional Large Diaphragm Headphone
Closed ear design provides comfort and outstanding reduction of external noises; 9.8 foot cord ends in gold plated plug and it is not detachable; 1/4 inch adapter included
$98.00
Bestseller No. 4
Also popular on Amazon
Wired Headphones, Over Ear Headphones for Studio Monitor & Mixing DJ | 50mm Drivers, Stereo Sound, 1/4 to 3.5mm Jack, for Guitar AMP, Podcast, Keyboard & Computer Recording, Black
  • High-Resolution Sound Quality: Engineered with massive 50mm dynamic drivers, these wired headphones deliver punchy bass, balanced mids, and precise treble across a wide $20 ext{Hz} - 20 ext{kHz}$ frequency range. Ideal for DJ mixing, studio monitoring, and audiophile listening, they ensure accurate vocal self-monitoring during recording and tracking sessions.
  • Maximum Comfort & Portability: Weighing just 260g (9.1 oz), this over-ear headset features skin-friendly protein leather and plush memory foam for long-lasting comfort and passive noise isolation.
  • Single-Side Monitoring: Designed for live performing and mixing, the 90° swiveling earcups allow instant single-ear monitoring. The self-adjustable, flexible headband contours perfectly to any head size, ensuring a secure, fatigue-free fit during extended studio sessions.
  • Music & Audio Sharing Tech: Share your mix or media without a splitter. This unique feature allows you to daisy-chain multiple headphones: connect the main headset to your device via the 3.5mm jack, then bridge the 6.35mm output to another pair for seamless, zero-latency co-listening.
  • No Adapter Required: Equipped with a detachable 5.7ft - 6ft coiled cord, these headphones offer ultimate freedom of movement. Dual 3.5mm and 6.35mm plugs provide plug-and-play compatibility with audio mixers, interfaces, PCs, tablets, and smartphones.
  • Your computer and home connection do not have to stay on; StreamNeo runs the stream in the cloud and automatically recovers if YouTube drops it.
  • Videos stream as uploaded, up to 4K 60fps, at one flat price per slot with no quality tiers.
  • The first day is free with no card, one free day per account. Monthly pricing is $9.99 per month.

See StreamNeo or start the free first day.

Sources and further reading

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply. Prices as of November 18, 2026 10:49 am GMT+0530.

amixbackground musicFFmpegvideo editingYouTube

About the author

— The DocumentaryTube Team writes The Screening Room's guides, reviews and news, and keeps the directory's records of documentaries, their directors and where to watch them. How DocumentaryTube works.

More in Blog

Say something about this film

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.