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?

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

Extract audio from a video

To extract the audio stream from a file, we export to WAV, 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. 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 -vcodec copy -i audio.wav -acodec copy -map 0:0 -map 1:0

Remarks

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 file to the AVI instead of using the original audio. This is the most important parameter here.

You could theoretically change the -acodec copy to use any other compressed audio codec, because copy will try to use the uncompressed WAV codec. Similarly, you could of course just save the edited audio file to MP3 and use that instead, but keep copy.

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

link|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
feedback

Your Answer

 
or
required, but never shown

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