Saturday, January 28, 2012

Strip audio track from a video file using mplayer

Let's say there is a large file encoded into mp4 and the audio is what is of most interest. Because I am not very familiar with mplayer/mencoder/sox this was a problem in the sort of hard category. First, I tried using mencoder, but I think some frame synchronization data is included in the stream and causes a metronome-like ticking. I tried using mplayer instead, and finally found the right sequence with some googling and trial and error. I'll save my work here for future reference.

Command line sequence to strip audio from an mp4 using an intermediate named fifo buffer
$ mkfifo fifo.wav
$ mplayer -quiet t.mp4 -ao pcm:fast:file=fifo.wav -vc dummy -vo null -channels 2 &
$ cat fifo.wav | sox -t raw -r 44100 -e signed -b 16 -c 2 - -t ogg audio.ogg
$ rm fifo.wav

For my test file, the resulting ogg file was about 5% as big as the mp4 file that includes the video. YMMV

Also, in fooling around with sox, I stumbled upon this misc information. I think this may be equivalent to the "play" command:

$ sox audio.ogg -d

No comments:

Post a Comment