Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm fed up with Vegas, Premiere, Pinnacle, SoundForge and all of the other editors I've tried.

I'm trying to modify the audio of an AVI file, but all of the editors I've tried insist on re-encoding the video when I save the changes, and either reduce the quality or take hours.

Is there a way to just extract the audio stream from a video with ffmpeg, edit it in an audio editor and then recombine the saved changes with the video?

share|improve this question
up vote 6 down vote accepted

First of all, make sure you install the latest version of FFmpeg from their download page. For Windows, Linux and OS X there are static builds available. On OS X you can also use Homebrew (with brew install ffmpeg).

Extract audio from a video

To extract the audio stream from a file, we export to PCM stereo audio in a WAV container, since it's lossless and won't be re-encoded:

ffmpeg -i input-file.avi audio.wav

Of course, you could use a number of other codecs, such as FLAC or ALAC. PCM content in WAV (or AIFF on Apple) would probably be best for editing though.

Now, apply any effects to your audio stream as necessary.

Recombine audio and video

To recombine an audio stream and a video file, run:

ffmpeg -i input-file.avi -i audio.wav -c copy -map 0:0 -map 1:0 output.avi


It is important that the video and audio files are in the correct order (-i video, -i audio) for the stream mapping. Might not work otherwise.

The -map 0:0 -map 1:0 option will map the audio from the second input file (the 1 in 1:0) to the AVI instead of using the original audio. This is the most important parameter here.

You could theoretically change the -c copy to just copy the video bitstream (-c:v copy) and use any other compressed audio codec, because copy will try to use the uncompressed PCM stereo audio. Similarly, you could of course just save the edited audio file to MP3 and use that instead, but keep copy.

To encode the PCM stereo WAV file to MP3, do something like this:

ffmpeg -i input-file.avi -i audio.wav -c:v copy -c:a libmp3lame -map 0:0 -map 1:0 output.avi

If your audio file is shorter than the video file, you might want to loop it. Supply the -loop 1 option to do this.

share|improve this answer
Thank you. The second command is giving me the error "unknown decoder 'copy'". If I leave it out it works but it's re-encoding the video at a lower quality instead of just passing it through. Any advice? – waitinforatrain Nov 22 '11 at 13:57
This is weird. I tried everything again before posting the answer and I've used this setup before. It should pass through just fine. Are you sure you use -acodec copy? – slhck Nov 22 '11 at 14:02
Yep. I think it's actually to do with not having a decoder for the codec I'm using (a camtasia custom one), so I'll just re-encode it – waitinforatrain Nov 23 '11 at 14:26
Placement of options is important. Anything before an "-i" is considered an input option, so ffmpeg is attempting to apply "-vcodec copy -acodec copy -scodec xsub" to the decoder of the input. Move appropriate options before your output. – user144457 Jul 6 '12 at 15:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.