From 0228969117b60a51378724cacf6f2a6ee506fd84 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Mon, 20 Apr 2020 20:51:28 -0400 Subject: [PATCH] New Post --- content/blog/audioreplace.md | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 content/blog/audioreplace.md diff --git a/content/blog/audioreplace.md b/content/blog/audioreplace.md new file mode 100644 index 0000000..0668267 --- /dev/null +++ b/content/blog/audioreplace.md @@ -0,0 +1,55 @@ +--- +title: "Replace Audio in Video" +date: 2020-04-20T20:32:26-04:00 +draft: false +tags: [] +--- + +I recorded a video and wanted to touch up my audio in audacity. Here's how I used `ffmpeg` to extract the audio, and then replace it with a modified version. + +## Extract Audio + +If you know the format of the audio (mp3, ogg, aac) then it's possible to do a byte copy of the audio track into a file: + +```bash +ffmpeg -i input_video.mkv -vn -acodec copy output.aac +``` + +| Argument | Description | +| -------------- | -------------------------- | +| `-i` | Input | +| `-vn` | No Video | +| `-acodec copy` | Copy audio stream directly | + +If you don't know the audio codec and have `mediainfo` installed, then run + +```bash +mediainfo --Inform="Audio;%Format%" input_video.mkv +``` + +If you gave up, then you can transcode the audio (will take longer than direct copy) + +```bash +ffmpeg -i input_video.mkv -vn output.aac +``` + +## Replacing Audio + +Once you're done touching up the audio (`touchup.mp3`), you'll want to replace the existing audio with it. + +```bash +ffmpeg -i input_video.mkv \ + -i touchup.mp3 \ + -c:v copy \ + -map 0:v:0 \ + -map 1:a:0 \ + output_video.mp4 +``` + +| Argument | Description | +| ---------------------- | ------------------------------------------------------------ | +| `-i` | Inputs | +| `-c:v copy` | Make this a copy operation | +| `-c:v copy -map 0:v:0` | Map the video from the first input to the first video output | +| `-map 1:a:0` | Map the audio from the second input to the first video output | +