# Extract a specific audio passage with Mplayer 1

This is basically a question involving parameters to mplayer (1). (Because I don't know where to look in the docs)

Given that one has a passage of audio starting at -ss 43:20, how does one extract an audio-dump (with -o pcm) starting at that point to a relative point ending at +1min, 30sec or ending at an absolute point at 44:50?

-
@Ganesh R. thank you for the very reasonable edits, man I wish I could think so objectively in everyday life. – Ярослав Рахматуллин Oct 19 '12 at 17:14

mplayer input.mp3 -ao pcm -ao pcm:file=tmp.wav -ss 5 -endpos 7

This will save from 5 to 7 seconds of the file to tmp.wav. I don't know how to do it with a relative end time, but if you put it in a script then you should be able to calculate that pretty easily.

Example script to convert a diff to an exact timestamp:

``````#!/usr/bin/env python

import sys
import datetime

start = sys.argv[1]
diff = sys.argv[2]

def parse_ts(x):
bits = [int(a) for a in x.split(":")]
while len(bits) < 3:
bits = [0] + bits
return datetime.timedelta(hours=bits[0],
minutes=bits[1],
seconds=bits[2])

end = datetime.datetime(2000, 1, 1) + parse_ts(start) + parse_ts(diff)

print end.strftime("%H:%M:%S")
``````

If you call that date.py, then this will save 42 minutes and 23 seconds of sound:

mplayer input.mp3 -ao pcm -ao pcm:file=tmp.wav -ss 1:23:5 -endpos \$(python date.py 1:23:5 42:23)

-
There it is! -endpos <[[hh:]mm:]ss[.ms]|size[b|kb|mb]> (also see -ss and -sb). Feel free to give us a couple of examples with both bytes and times. Thanks, buddy! – Ярослав Рахматуллин Oct 19 '12 at 17:07