Remove Audio stream from XVID files

I have a bunch of Xvid files that each have an audio stream that I do not want. How can I strip the audio track I don't want using the Linux command line?

I don't need the whole script (loop), just what command I would use to process each avi file individually (unless the cmd itself has batch modification built into it).

I don't believe the file is in an mkv container, as mkvinfo doesn't find anything. Here is part of mplayer's output (thanks ~quack):

[aviheader] Video stream found, -vid 0
ID_AUDIO_ID=1
[aviheader] Audio stream found, -aid 1
ID_AUDIO_ID=2
[aviheader] Audio stream found, -aid 2
VIDEO:  [XVID]  512x384  12bpp  25.000 fps  1013.4 kbps (123.7 kbyte/s)

Solution 1:

Frankly, I think you'll prefer using the ffmpeg solution. But I figured mencoder (mplayer's encoder) could do this too ... and it can, but only as a side-effect -- since it's built on top of a player, it can only process one audio stream at a time. If you were reversing the process (adding a second audio stream to a file that only had one), you'd need a different tool.

The -aid X option selects the audio stream (replace X with the stream's ID number). It looks like the mplayer output you've quoted shows the proper ID numbers already, so try with those. This keeps the first audio stream (use -aid 2 if you want the second):

$ mencoder orig.avi -o new.avi -oac copy -ovc copy -aid 1

Other commandline AVI tools that might help are:

  • avidemux (you can script with -nogui)
  • transcode

Solution 2:

Using ffmpeg you can do the folowing

ffmpeg -i input -map 0:0 -map 0:1 -vcodec copy -acodec copy output

That should make a new film with video and first audio stream. To use second audio stream change -map 0:1 to -map 0:2. With copy for both -vcodec and -acodec you copy streams without reencoding.