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

  • Cisco Unified Communication Manager (CUCM) - How To Add Phones
  • pptp / pptpd not working in DD-WRT iptables / router
  • systemd-journald high memory usage solution
  • How to Install FreePBX in Linux Debian Ubuntu Mint Guide
  • How To Install Cisco's CUCM (Cisco Unified Communication Manager) 12 Guide
  • Linux Ubuntu Redhat How To Extract Images from PDF
  • Linux and Windows Dual Boot Issue NIC Won't work After Booting Windows
  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist
  • How to Install Any OS on a Physical Drive from Windows Using VMware Workstation (Linux, Windows, BSD)
  • CDN Cloudflare how to set and preserve the real IP of the client without modifying application code on Apache
  • CentOS 7 fix Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 -
  • Ubuntu Debian How To Install Recommended Packages Automatically
  • How to set Linux Ubuntu Redhat Debian Command Line http https socks proxy for yum apt