How To Replace Audio Track of Video using ffmpeg

A very common use case is that you don't want to waste time using a video editor that requires you to open it up and manually import the video clip and audio clip, then manually delete the old audio track and import the video and new audio.  That's too much work and time since we don't want to go through the hassle.

ffmpeg is our solution, all we have to do is specify 3 variables and we're done!

-i Windows2019-Server-Noaudio.mp4 is our input / source file

-i Windows2019-Server-NoAudio.wav is our new audio file that we want to replace.

Windows2019-Server-NoAudio-audio-fix.mp4 is our final output file that will have our updated audio file

ffmpeg -i Windows2019-Server-NoAudio.mp4 -i Windows2019-Server-NoAudio.wav -c:v copy -map 0:v:0 -map 1:a:0 Windows2019-Server-NoAudio-audio-fix.mp4

 


ffmpeg version 2.8.17-0ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.12) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_aacenc --enable-libvo_amrwbenc
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Windows2019-Server-NoAudio.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2020-10-05 16:14:56
    encoder         : x264
  Duration: 00:02:28.60, start: 0.000000, bitrate: 258 kb/s
    Stream #0:0(eng): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 1282x958 [SAR 1:1 DAR 641:479], 127 kb/s, 15 fps, 15 tbr, 1500 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2020-10-05 16:14:56
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, mono, s16p, 127 kb/s (default)
    Metadata:
      creation_time   : 2020-10-05 16:14:56
      handler_name    : SoundHandler
Guessed Channel Layout for  Input Stream #1.0 : mono
Input #1, wav, from 'Windows2019-Server-NoAudio.wav':
  Duration: 00:02:28.56, bitrate: 705 kb/s
    Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s
[mp4 @ 0x1702ca0] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, mp4, to 'Windows2019-Server-NoAudio-audio-fix.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    encoder         : Lavf56.40.101
    Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv444p, 1282x958 [SAR 1:1 DAR 641:479], q=2-31, 127 kb/s, 15 fps, 15 tbr, 12k tbn, 1500 tbc (default)
    Metadata:
      creation_time   : 2020-10-05 16:14:56
      handler_name    : VideoHandler
    Stream #0:1: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, mono, s16, 128 kb/s
    Metadata:
      encoder         : Lavc56.60.100 libvo_aacenc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (libvo_aacenc))
Press [q] to stop, [?] for help
frame= 2229 fps=1183 q=-1.0 Lsize=    4701kB time=00:02:28.57 bitrate= 259.2kbits/s    
video:2320kB audio:2322kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.275361%

 


Tags:

audio, ffmpega, requires, manually, import, clip, delete, hassle, ffmpeg, specify, variables, server, noaudio, mp, input, wav, output, updated, ubuntu, copyright, developers, gcc, configuration, prefix, usr, suffix, toolchain, hardened, libdir, lib, _, linux, gnu, incdir, cc, cxx, enable, gpl, disable, stripping, decoder, libopenjpeg, libschroedinger, avresample, avisynth, gnutls, ladspa, libass, libbluray, libbs, libcaca, libcdio, libflite, libfontconfig, libfreetype, libfribidi, libgme, libgsm, libmodplug, libmp, libopus, libpulse, librtmp, libshine, libsnappy, libsoxr, libspeex, libssh, libtheora, libtwolame, libvorbis, libvpx, libwavpack, libwebp, libx, libxvid, libzvbi, openal, opengl, libdc, libiec, libzmq, frei, libopencv, mismatch, avcodec, programs, avdevice, avfilter, avformat, postproc, swscale, libopencore_amrnb, libopencore_amrwb, libvo_aacenc, libvo_amrwbenc, libavutil, libavcodec, libavformat, libavdevice, libavfilter, libavresample, libswscale, libswresample, libpostproc, mov, gp, mj, metadata, major_brand, minor_version, compatible_brands, isomiso, creation_time, encoder, duration, bitrate, kb, stream, eng, predictive, avc, yuv, sar, dar, fps, tbr, tbn, tbc, default, handler_name, videohandler, hz, mono, soundhandler, guessed, layout, pcm_s, channels, ca, codec, global, headers, container, format, lavf, aac, lavc, mapping, native, lsize, kbits, subtitle, streams, muxing, overhead,

Latest Articles

  • How to allow SSH root user access in Linux/Debian/Mint/RHEL/Ubuntu/CentOS
  • Ansible Tutorial - Playbook How To Install From Scratch and Deploy LAMP + Wordpress on Remote Server
  • Ceph Install Errors on Proxmox / How To Fix Solution
  • Proxmox Update Error https://enterprise.proxmox.com/debian/pve bullseye InRelease 401 Unauthorized [IP: 144.217.225.162 443]
  • QEMU/KVM How to Hot-add A Virtual Disk .raw/.qcow2 via QEMU Monitor Commands
  • Proxmox How To Enable Ceph Distributed Storage Cluster with OSD and Pools
  • pulseaudio issue on QEMU/KVM guest VM when microphone is replugged/unplugged pulseaudio: pa_threaded_mainloop_lock failed pulseaudio: Reason: Invalid argument
  • Ubuntu Linux Mint - Volume Control Stopped Working
  • Proxmox Services Won't Start Failed to start The Proxmox VE cluster filesystem. Proxmox VE firewall. PVE Status Daemon. Proxmox VE scheduler. PVE Cluster HA Resource Manager Daemon. PVE Local HA Resource Manager Daemon.
  • Proxmox Guide FAQ / Errors / Howto
  • Virtualbox Vbox Issue Cannot Enable Nested Virtualization Button is Grayed/Greyed Out and Unclickable HowTo Solution
  • Virtualbox VBOX Howto Port Forward To Guests
  • Linux Ubuntu Debian Centos Mint - How To Check if Intel VT-x or AMD-V Hardware Virtualization is Enabled?
  • Linux Howto Zip Multiple Files and Directories
  • Windows Cannot Format USB drive Device Media is Write Protected Error Solution
  • Linux Mint 20 cannot install snapd missing solution
  • Virtualbox VBOX How To Install Guest-Utils/GuestUtils so drag and drop and clipboard works Ubuntu Mint Debian Linux
  • How to install Kubernetes with microk8s and deploy apps on Debian/Mint/Ubuntu Linux
  • vi how to delete everything to the end of the line or the rest of the line from the cursor
  • Cisco Howto Configure Console Port/Terminal/Comm Server with Async Cable Setup