I am a big, corpulent fan of thesauruses and mplayer. Mplayer has about a billion command line options, as any respectable linux staple should. Unfortunately, I’ve had some difficulty tracking down some of the more useful options. For instance, I was looking for a way to trim a sound file from the command line.
With mplayer you can specify output devices, so the command to play a song through your speakers and the command to write a new file often differ only by the output specification. Where this comes in is that the command I was looking for is also useful for playing a segment of a sound file.
I googled around for “mplayer trim audio file”, “mplayer crop audio file”, “mplayer start end command line options” (to see if the ones I wanted were in the main list), and “mplayer start end positions”. I think I ended up going through my own shell history until I found the commands I used for creating GIFs from movies (like I said mplayer/mencoder is great). There I found the elusive
-endpos command line arguments. Why
ss and not
startpos, I don’t know.
Next time you’re looking to trim anything or play anything, use the following commands as a template.
mplayer -ss 16 -endpos 1:21:33 [additional options] [input files]
endpos have the same input specification. So you can go by number of seconds, or mm:ss, or hh:mm:ss.
endpos is the number of seconds you want to capture/play, so ss=5 and endpos=10 will play the 10 seconds starting at the 5th second.
(Note here that I had some strange results on one file, but that could have just been mplayer.)
Anyway, I hope that was helpful. As a postscript, here are some other examples for you.
Create a trimmed wavefile from an input file, including ripping audio from video files:
mplayer -ss [time] -endpos [time] -ao pcm:file=output.wav [input_file]
If you want to trim a video, you’ll have to switch to mencoder. Don’t worry, ss and endpos still work:
mencoder -ss [time] -endpos [time] -ovc copy -oac copy -o mytrimmed.avi [input_file]
(There might be a way to do it with mplayer, but I don’t know how. This works fine though )