LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-19-2009, 01:23 PM   #16
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[567] x86_64, Ubuntu 17.10 x86_64
Posts: 221

Original Poster
Rep: Reputation: 36

Quote:
Originally Posted by mrclisdue View Post
I'm pretty sure that it defines the author as a virgo, with libra on the horizon, then you turn left, go down three flights of stairs, take the elevator up 6 floors, to the lingerie department, look up, flick your left ear, leave via the fire exit, hail the 3rd burgundy cab that comes your way, and tell the driver to "fondle mine botox", or something eerily similar.

hth,
LOL. After a bit of delay due to having have lingered a bit too long in the lingerie department, the full s///g expression is:

Code:
s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p
The characters being searched for are:

Code:
]()|&;<>`'"'"'\\!$" [
And the replacement is to put all of the string (just one character in this case) that was matched right after a backslash. But since the backslash itself needs to be escaped, then there are two of them. The thing that is matched, represented by the "&" in the replacement, happens to only be one single character. Net result: escaping all characters that can be interpolated by the shell during evaluation.
 
Old 09-19-2009, 01:54 PM   #17
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[567] x86_64, Ubuntu 17.10 x86_64
Posts: 221

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by Shadow_7 View Post
ffmpeg -i file.mp3

file file.mp3

mediainfo file.mp3

and probably dozens of other ways.
I compared "ffmpeg", "file", and "mplayer" and got wildy different values. Now, granted, maybe I'm reading the values from output of those commands incorrectly, but try this Bash script on medium-sized random collection of .mp3 files and you are bound to see some differences like I do.

Code:
#!/bin/bash

# Description: Compare the output of commands that should presumably
# show the bitrate on MP3 files, but don't do so consistently. This
# finds all .mp3 files recursively through all subdirectories relative
# to the current working directory, extracts the kbps reading from
# commands that should report such a reading, and shows cases where
# they don't report the same value.

# Warning: Bash shell syntax below, not Bourne shell (so $()
# constructs will work, so don't try this on the Solaris OS's /bin/sh)

# Set $show_full_output to "1" to see the full output of the commands being compared
show_full_output=0

compare_measurements () {
    file="$1"
    ffmpeg -i "$file" >/tmp/ffmpeg.out 2>&1 
    ffmpeg_result=$(cat /tmp/ffmpeg.out | sed -n 's% *Stream.*Audio: mp3.*, \([0-9]*\) kb/s$%\1%gp')
    mplayer -vo null -ao null -frames 0 -identify "$file" > /tmp/mplayer.out 2>&1
    # mplayer reports them in bps, so we divide by 1000 to get kbps:
    mplayer_result=$(expr $(cat /tmp/mplayer.out | sed -n ' /ID_AUDIO_BITRATE/{ s%^ID_AUDIO_BITRATE=\(.*\)$%\1%gp; q; }') / 1000)
    file "$file" >/tmp/file.out 2>&1
    # sed's regular expression matcher gets fouled up by various types
    # of "file" output, so put each comma-separated value on separate
    # lines so that we can pull out the kbps reading:
    file_result=$(cat /tmp/file.out | tr , '\012' | sed -n '/kbps/{ s%^ *\([0-9]*\) kbps$%\1%gp; q; }')
    if [ "$ffmpeg_result" != "$mplayer_result" -o \
         "$file_result"   != "$mplayer_result" -o \
         "$file_result"   != "$ffmpeg_result"        ]
    then
        echo "ffmpeg_result==$ffmpeg_result mplayer_result==$mplayer_result file_result==$file_result     file==$file"
        if [ "$show_full_output" = 1 ]
        then
            echo
            echo
            cat /tmp/ffmpeg.out  | sed 's%^%   ffmpeg output: %g'
            echo
            echo
            cat /tmp/mplayer.out | sed 's%^%  mplayer output: %g'
            echo
            echo
            cat /tmp/file.out    | sed 's%^%     file output: %g'
            echo
            echo
        fi
    fi
    rm -f /tmp/ffmpeg.out /tmp/mplayer.out
}

find . -name '*.mp3' | sed 's%^\(.*\)$%compare_measurements "\1"%g' >/tmp/subscript.sh

. /tmp/subscript.sh
Sample output from that script on my end:

Code:
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_16_Merry-Go-Round.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_06_Woody 'n' you.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_07_Boplicity.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_09_Israel.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_10_Rouge.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_15_Move.mp3
ffmpeg_result==32 mplayer_result==192 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_08_Godchild.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_14_Jeru.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_04_Conception.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_03_Rocker.mp3
ffmpeg_result==32 mplayer_result==224 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_17_Perhaps.mp3
ffmpeg_result==32 mplayer_result==192 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_18_Marmaduke.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_02_Moon Dreams.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_12_The Squirrel.mp3
ffmpeg_result==32 mplayer_result==192 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_11_Venus De Milo.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_13_Budo.mp3
ffmpeg_result==32 mplayer_result==32 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_01_Deception.mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./The Great Miles Davis, Vol. 1/Miles Davis_05_Max Is Making Wax.mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/07 Half Nelson.mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/02 Four.mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/06 Ahmad's Blues.mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/01 It Never Entered My Mind.mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/03 In Your Own Sweet Way.mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/04 The Theme [take 1].mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/05 Trane's Blues.mp3
ffmpeg_result==320 mplayer_result==320 file_result==     file==./Workin' With The Miles Davis Quintet (1959)/08 The Theme [take 2].mp3
ffmpeg_result==32 mplayer_result==128 file_result==128     file==./Bags' Groove/Miles Davis_01_Bags' Groove (take 1).mp3
ffmpeg_result==32 mplayer_result==32 file_result==128     file==./Bags' Groove/Miles Davis_05_But Not for Me (take 2).mp3
ffmpeg_result==32 mplayer_result==32 file_result==128     file==./Bags' Groove/Miles Davis_04_Oleo.mp3
ffmpeg_result==32 mplayer_result==32 file_result==128     file==./Bags' Groove/Miles Davis_06_Doxy.mp3
ffmpeg_result==32 mplayer_result==32 file_result==128     file==./Bags' Groove/Miles Davis_07_But Not for Me (take 1).mp3
ffmpeg_result==224 mplayer_result==32 file_result==128     file==./Bitches Brew/(Disc 2) 03 - Miles Runs The Voodoo Down (Album Version).mp3
ffmpeg_result==32 mplayer_result==32 file_result==128     file==./Bitches Brew/01 - Pharaohs Dance (Album Version).mp3
ffmpeg_result==224 mplayer_result==32 file_result==128     file==./Bitches Brew/02 - Bitches Brew (Album Version).mp3
ffmpeg_result==224 mplayer_result==32 file_result==128     file==./Bitches Brew/(Disc 2) 02 - John McLaughlin (Album Version).mp3
ffmpeg_result==160 mplayer_result==32 file_result==128     file==./Bitches Brew/(Disc 2) 05 - Feio (Album Version).mp3
ffmpeg_result==32 mplayer_result==32 file_result==128     file==./Bitches Brew/(Disc 2) 01 - Spanish Key (Album Version).mp3
ffmpeg_result==224 mplayer_result==32 file_result==128     file==./Bitches Brew/(Disc 2) 04 - Sanctuary (Album Version).mp3
Oh, and notice that the "file" command doesn't always report a bitrate value. Perhaps that is a bug??

bg

Last edited by bgoodr; 09-26-2009 at 08:50 AM.
 
Old 09-25-2009, 11:14 AM   #18
AlphaLexman
LQ Newbie
 
Registered: Jun 2009
Posts: 8

Rep: Reputation: 0
I found a nice utility->

exiftool

will read:

File Types | Meta Information
--------------------------------------- | --------------------
3FR r ITC r PPM r/w | EXIF r/w/c
ACR r JNG r/w PPT r | GPS r/w/c
AI r JP2 r/w PS r/w | IPTC r/w/c
AIFF r JPEG r/w PSD r/w | XMP r/w/c
APE r K25 r QTIF r | MakerNotes r/w/c
ARW r KDC r RA r | Photoshop IRB r/w/c
ASF r M4A r RAF r/w | ICC Profile r/w/c
AVI r MEF r/w RAM r | MIE r/w/c
BMP r MIE r/w/c RAW r/w | JFIF r/w/c
BTF r MIFF r RIFF r | Ducky APP12 r/w/c
CR2 r/w MNG r/w RM r | CIFF r/w
CRW r/w MOS r/w SR2 r | AFCP r/w
CS1 r/w MOV r SRF r | JPEG 2000 r
DCM r MP3 r SVG r | DICOM r
DCR r MP4 r SWF r | Flash r
DIVX r MPC r THM r/w | FlashPix r
DNG r/w MPG r TIFF r/w | QuickTime r
DOC r MRW r/w VRD r/w/c | GeoTIFF r
EPS r/w NEF r/w WAV r | PrintIM r
ERF r/w OGG r WDP r/w | ID3 r
FLAC r ORF r/w WMA r | Kodak Meta r
FLV r PBM r/w WMV r | Ricoh RMETA r
FPX r PDF r/w X3F r | Picture Info r
GIF r/w PEF r/w XLS r | Adobe APP14 r
HDP r/w PGM r/w XMP r/w/c | APE r
HTML r PICT r | Vorbis r
ICC r/w/c PNG r/w | (and more)
 
Old 09-26-2009, 09:58 AM   #19
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[567] x86_64, Ubuntu 17.10 x86_64
Posts: 221

Original Poster
Rep: Reputation: 36
Adding exiftool to my bitrate.sh script

Quote:
Originally Posted by AlphaLexman View Post
I found a nice utility-> exiftool
Thanks AlphaLexman! I've updated my bitrate.sh script to compare exiftool's bitrate measurement against with the other tools.

At this point, I need an answer to why there are different values coming from different tools, and which tool is reporting the correct value. Until I get answers to that, I will just stick with, say, exiftool output and pretend it is correct.

Here is the updated bitrate.sh script (the forum refused to allow me to attach it to the post for some unexplained reason):

Code:
#!/bin/bash

# The bitrate.sh script (backlink: MusicFileBitRate)

# Description: Compare the output of commands that should presumably
# show the bitrate on MP3 files, but don't do so consistently. This
# finds all .mp3 files recursively through all subdirectories relative
# to the current working directory, extracts the kbps reading from
# commands that should report such a reading, and shows cases where
# they don't report the same value.

# Warning: Bash shell syntax below, not Bourne shell (so $()
# constructs will work, so don't try this on the Solaris OS's /bin/sh)

# Set $show_full_output to "1" to see the full output of the commands being compared
show_full_output=${show_full_output:=0}

validate_tool ()
{
    tool="$1"
    if ! which "$tool" >/dev/null 2>&1 
    then
        echo "ERROR: $tool not found in the PATH. Did you install the right package?"
        exit 1
    fi
}

validate_tool file
validate_tool ffmpeg
validate_tool mplayer
validate_tool exiftool

first=1
compare_measurements () {
    file="$1"
    tmp_files=""

    # Find the bitrate reported from ffmpeg:
    ffmpeg -i "$file" >/tmp/ffmpeg.out 2>&1 
    ffmpeg_result=$(cat /tmp/ffmpeg.out | sed -n 's% *Stream.*Audio: mp3.*, \([0-9]*\) kb/s$%\1%gp')
    tmp_files="$tmp_files /tmp/ffmpeg.out"
    [ "$ffmpeg_result" = "" ] && ffmpeg_result=-1

    # Find the bitrate reported from mplayer:
    mplayer -vo null -ao null -frames 0 -identify "$file" > /tmp/mplayer.out 2>&1
    # mplayer reports them in bps, so we divide by 1000 to get kbps:
    mplayer_result=$(expr $(cat /tmp/mplayer.out | sed -n ' /ID_AUDIO_BITRATE/{ s%^ID_AUDIO_BITRATE=\(.*\)$%\1%gp; q; }') / 1000)
    tmp_files="$tmp_files /tmp/mplayer.out"
    [ "$mplayer_result" = "" ] && mplayer_result=-1

    # Find the bitrate reported from file:
    file "$file" >/tmp/file.out 2>&1
    # sed's regular expression matcher gets fouled up by various types
    # of "file" output, so put each comma-separated value on separate
    # lines so that we can pull out the kbps reading:
    file_result=$(cat /tmp/file.out | tr , '\012' | sed -n '/kbps/{ s%^ *\([0-9]*\) kbps$%\1%gp; q; }')
    tmp_files="$tmp_files /tmp/file.out"
    [ "$file_result" = "" ] && file_result=-1

    # Find the bitrate reported from exiftool:
    exiftool "$file" > /tmp/exiftool.out
    exiftool_result=$(expr $(cat /tmp/exiftool.out | sed -n 's%^Audio Bitrate[^:]*: *\([0-9]*\)$%\1%gp') / 1000)
    tmp_files="$tmp_files /tmp/exiftool.out"
    [ "$exiftool_result" = "" ] && exiftool_result=-1

    # Find the minimum and maximum of the set of reported bitrate values:
    min=10000000
    max=-1
    for tool in ffmpeg mplayer file exiftool
    do
        eval value=\${${tool}_result}
        if expr $value \< $min >/dev/null
        then
            min=$value
        fi
        if expr $value \> $max >/dev/null
        then
            max=$value
        fi
    done

    # If the minimum and maximum are not equal, then one of the tools is reporting a different value:
    if [ "$min" != "$max" ]
    then
        awkscript='{printf("%10s %10s %10s %10s    %s\n",$1,$2,$3,$4,$5);}' 
        # Print the column header line the first time through, but always when show_full_output is set:
        if [ "$first" = 1 -o "$show_full_output" = 1 ]
        then
            echo "ffmpeg mplayer file exiftool Filename" | awk "$awkscript"
            first=0
        fi
        echo "$ffmpeg_result $mplayer_result $file_result $exiftool_result XXX" | awk "$awkscript" | sed 's%XXX%'"$file"'%g'
        if [ "$show_full_output" = 1 ]
        then
            for tool in ffmpeg mplayer file exiftool
            do
                echo
                echo
                cat /tmp/$tool.out  | sed 's%^%'"$tool"' output: %g'
            done
            echo
            echo ================================================================================
            echo
            echo
        fi
    fi
    rm -f $tmp_files
}

find . -name '*.mp3' | sed 's%^\(.*\)$%compare_measurements "\1"%g' >/tmp/subscript.$$.sh

. /tmp/subscript.$$.sh

rm -f /tmp/subscript.$$.sh
Here is the output of that script on my fileset (all of my Miles Davis music files) without show_full_output being turned on (note that "-1" is the value to indicate that no bitrate was reported from the tool):

Code:
$ bitrate.sh
    ffmpeg    mplayer       file   exiftool    Filename
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_16_Merry-Go-Round.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_06_Woody 'n' you.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_07_Boplicity.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_09_Israel.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_10_Rouge.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_15_Move.mp3
        32        192        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_08_Godchild.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_14_Jeru.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_04_Conception.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_03_Rocker.mp3
        32        224        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_17_Perhaps.mp3
        32        192        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_18_Marmaduke.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_02_Moon Dreams.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_12_The Squirrel.mp3
        32        192        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_11_Venus De Milo.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_13_Budo.mp3
        32         32        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_01_Deception.mp3
        32        128        128        128    ./The Great Miles Davis, Vol. 1/Miles Davis_05_Max Is Making Wax.mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/07 Half Nelson.mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/02 Four.mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/06 Ahmad's Blues.mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/01 It Never Entered My Mind.mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/03 In Your Own Sweet Way.mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/04 The Theme [take 1].mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/05 Trane's Blues.mp3
       320        320         -1        320    ./Workin' With The Miles Davis Quintet (1959)/08 The Theme [take 2].mp3
        32        128        128        128    ./Bags' Groove/Miles Davis_01_Bags' Groove (take 1).mp3
        32         32        128        128    ./Bags' Groove/Miles Davis_05_But Not for Me (take 2).mp3
        32         32        128        128    ./Bags' Groove/Miles Davis_04_Oleo.mp3
        32         32        128        128    ./Bags' Groove/Miles Davis_06_Doxy.mp3
        32         32        128        128    ./1Bags' Groove/Miles Davis_07_But Not for Me (take 1).mp3
       224         32        128        128    ./Bitches Brew/(Disc 2) 03 - Miles Runs The Voodoo Down (Album Version).mp3
        32         32        128        128    ./Bitches Brew/01 - Pharaohs Dance (Album Version).mp3
       224         32        128        128    ./Bitches Brew/02 - Bitches Brew (Album Version).mp3
       224         32        128        128    ./Bitches Brew/(Disc 2) 02 - John McLaughlin (Album Version).mp3
       160         32        128        128    ./Bitches Brew/(Disc 2) 05 - Feio (Album Version).mp3
        32         32        128        128    ./Bitches Brew/(Disc 2) 01 - Spanish Key (Album Version).mp3
       224         32        128        128    ./Bitches Brew/(Disc 2) 04 - Sanctuary (Album Version).mp3
Find the output for

Code:
show_full_output=1 bitrate.sh
at http://bgoodr.pastebin.com/f485e8109 and not attached because the forum refused to attach it.

bg
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to decrease the Bit Rate of MP3 files in Linux me4linux Linux - Software 6 08-11-2007 09:03 PM
MP2 to MP3. What bit rate? arubin General 5 05-25-2006 04:45 AM
increase mp3 bit-rate on old files Present Linux - Software 4 03-28-2005 10:35 PM
play audio mp3 files from command line? runlevel <5 carl0ski Linux - Software 3 12-02-2004 04:58 AM
Command line tool to print length of mp3 files? J_Szucs Linux - Software 3 05-04-2004 05:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration