July 30, 2013

How to remove unnecessary audio from a video file

Once in a while I encounter a video file which has more than one audio stream attached to it. Usually I’m only interested in one of those and want to get rid of the others. Specially if the first one is not the one I’m interested in. Xbox for example does provide an easy way to selecting some other stream besides the first one.

The wonderful open-source project libav provides the tools we need: avprobe and avconv. Let’s fire up avprobe first:

$ avprobe something_nice.avi

avprobe version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 
2007-2013 the Libav developers built on Apr  2 2013 17:00:59 
with gcc 4.6.3
Input #0, avi, from 'something_nice.avi':
  Metadata:
    encoder         : VirtualDubModRus 1.5.10.2 (build 2542/release)
    title           : Something Nice
    artist          : Released
    genre           : Action
    album           : Movie
    comment         : DVD
  Duration: 01:54:04.25, start: 0.000000, bitrate: 2738 kb/s
    Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p,
    720x304 [PAR 1:1 DAR 45:19], 23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s

I’m interested in the second audio stream, which is in the language I understand. avconv helps:

$ avconv -i something_nice.avi -map 0:0 -c:v copy -map 0:2 -c:a \
copy something_nice_eng.avi

Powered by Hugo & Kiss.