Get MP3 Length in Linux / FreeBSD - Super User most recent 30 from superuser.com 2010-03-21T18:37:32Z http://superuser.com/feeds/question/63399 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://superuser.com/questions/63399/get-mp3-length-in-linux-freebsd 1 Get MP3 Length in Linux / FreeBSD silent http://superuser.com/users/6579 2009-10-31T01:34:31Z 2009-10-31T04:07:49Z <p>Hi all,</p> <p>I have a bunch of mp3 files with various length. I want to cut it down to 50%-60% length. Says, from 1 minute down to 30 seconds. It should be trivial using ffmpeg. But, I don't know how to determine the original length of it as a base for processing using ffmpeg.</p> <p>Anyone have an idea?</p> http://superuser.com/questions/63399/get-mp3-length-in-linux-freebsd/63428#63428 1 Answer by nik for Get MP3 Length in Linux / FreeBSD nik http://superuser.com/users/263 2009-10-31T03:29:21Z 2009-10-31T03:29:21Z <p>Interestingly the <a href="http://www.sno.phy.queensu.ca/~phil/exiftool" rel="nofollow">EXIFTool</a> application gives MP3 duration as the last line!</p> <pre> $ exiftool somefile.mp3 ExifTool Version Number : 7.98 File Name : somefile.mp3 Directory : . File Size : 49 MB File Modification Date/Time : 2009:09:10 11:04:54+05:30 File Type : MP3 MIME Type : audio/mpeg MPEG Audio Version : 2.5 Audio Layer : 3 Audio Bitrate : 64000 Sample Rate : 8000 Channel Mode : Single Channel MS Stereo : Off Intensity Stereo : Off Copyright Flag : False Original Media : True Emphasis : None ID3 Size : 26 Genre : Blues Duration : 1:47:46 (approx) </pre> http://superuser.com/questions/63399/get-mp3-length-in-linux-freebsd/63430#63430 1 Answer by A Dwarf for Get MP3 Length in Linux / FreeBSD A Dwarf http://superuser.com/users/10971 2009-10-31T03:35:48Z 2009-10-31T03:35:48Z <p>With ffmpeg there's no way I know to get the length as a variable you can use on a script. But <a href="http://www.ibiblio.org/mp3info/" rel="nofollow">mp3info</a> does.</p> <pre><code>mp3info -p "%S" sample.mp3 // total time in seconds </code></pre> http://superuser.com/questions/63399/get-mp3-length-in-linux-freebsd/63438#63438 1 Answer by goldPseudo for Get MP3 Length in Linux / FreeBSD goldPseudo http://superuser.com/users/7201 2009-10-31T04:07:12Z 2009-10-31T04:07:12Z <p>I personally use <a href="http://www.mplayerhq.hu/" rel="nofollow">Mplayer</a> to extract the information, mostly because I already have it installed and can't be bothered to install new software unnecessarily. The advantage to this is that it isn't limited to mp3 files in particular, and should work with any media file that Mplayer can handle. The following one-liner will return the track length in seconds.</p> <pre><code>mplayer -identify -ao null -vo null -frames 0 Filename.mp3 | grep ^ID_LENGTH= | cut -d = -f 2 </code></pre> http://superuser.com/questions/63399/get-mp3-length-in-linux-freebsd/63440#63440 2 Answer by ~quack for Get MP3 Length in Linux / FreeBSD ~quack http://superuser.com/users/12786 2009-10-31T04:07:49Z 2009-10-31T04:07:49Z <p><code>ffmpeg</code> will print everything it knows about the file if you don't give it any other arguments. Use <code>grep</code> to strip out everything but the "Duration":</p> <pre><code>$ ffmpeg -i foo.mp3 2&gt;&amp;1 | grep Duration Duration: 01:02:20.20, start: 0.000000, bitrate: 128 kb/s </code></pre> <p>You could also use <code>mplayer</code>. Grep for line "ID_LENGTH=":</p> <pre><code>$ mplayer -ao null -identify -frames 0 foo.mp3 2&gt;&amp;1 | grep ID_LENGTH ID_LENGTH=3740.00 </code></pre>