9

Given a .flac file, how is it possible to query and display the technical info relating to the codec? I looked into man flac with no luck (the --analyze output is not humanly parseable). I'm specifically interested in the bit rate (say, 16 bits per sample), the sample rate (say, 44.1 KHz) and the number of channels.

Either GUI or CLI utilities are acceptable.

1
  • VLC player can show you all this information Aug 4, 2018 at 3:25

4 Answers 4

12

Easiest is to use the Unix command line utility file. For example:

file "example.flac" 
example.flac: FLAC audio bitstream data, 16 bit, stereo, 44.1 kHz, 2474304 samples
11

metaflac --list will display that information (and more) for all blocks in a FLAC file. You can additionally use --block-number=X, where X is the block you want to have information about, to only get information about that particular block.

2
  • metaflac is also very useful.
    – landroni
    Mar 26, 2014 at 10:20
  • 1
    The commands: metaflac --show-bps, metaflac --show-channels, metaflac --show-sample-rate, will do exactly what the OP poster wanted. Thanks for suggesting metaflac in the first place!
    – Ákos
    Jul 21, 2014 at 7:23
9

You can use the ffprobe CLI tool that's included with ffmpeg:

$ ffprobe -hide_banner 10\ Ivory\ Tower.flac
Input #0, flac, from '10 Ivory Tower.flac':
  Metadata:
    ARTIST          : Van Morrison
    TITLE           : Ivory Tower
    ALBUM           : No Guru, No Method, No Teacher
    DATE            : 1986
    track           : 10
    GENRE           : Rock
    disc            : 1
    TOTALDISCS      : 1
    TOTALTRACKS     : 10
  Duration: 00:03:36.71, start: 0.000000, bitrate: 946 kb/s
    Stream #0:0: Audio: flac, 44100 Hz, stereo, s16

Shows the duration, bitrate, and particulars about the FLAC encoding. ffmpeg/ffprobe use the term streams, so the file we gave it is considered Stream#0:0.

You can get just those details:

$ ffprobe -hide_banner 10\ Ivory\ Tower.flac |& grep Stream
    Stream #0:0: Audio: flac, 44100 Hz, stereo, s16

Or if you really want to get at all the data from the stream use the -show_streams:

$ ffprobe -hide_banner  -show_streams 10\ Ivory\ Tower.flac
Input #0, flac, from '10 Ivory Tower.flac':
  Metadata:
    ARTIST          : Van Morrison
    TITLE           : Ivory Tower
    ALBUM           : No Guru, No Method, No Teacher
    DATE            : 1986
    track           : 10
    GENRE           : Rock
    disc            : 1
    TOTALDISCS      : 1
    TOTALTRACKS     : 10
  Duration: 00:03:36.71, start: 0.000000, bitrate: 946 kb/s
    Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
[STREAM]
index=0
codec_name=flac
codec_long_name=FLAC (Free Lossless Audio Codec)
profile=unknown
codec_type=audio
codec_time_base=1/44100
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=s16
sample_rate=44100
channels=2
channel_layout=stereo
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/44100
start_pts=0
start_time=0.000000
duration_ts=9556764
duration=216.706667
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=16
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]

See references below for more examples etc.

References

0
4

From the man page,

# -a, --analyze
# Analyze a FLAC encoded file (same as -d except an analysis file is written) 
flac -a myfile.flac

EDIT

It might be easier to use soxi from the Sound eXchange project. On most Linux systems you need to install the sox package. On Debian derived distributions (including Ubuntu), you would use

sudo apt-get install sox
4
  • 1
    Yes, I tried that. But the output is completely bonkers to me.
    – landroni
    Mar 20, 2014 at 16:17
  • @landroni Okay. Edited to add soxi. Mar 20, 2014 at 16:21
  • Perfect. soxi does what I wanted.
    – landroni
    Mar 20, 2014 at 16:33
  • Try flac -ac file.flac | grep -E '(sample|channels)' for a quick 2 out of 3 answers. All those gui tools do is read from that sort of output... Also -a will create an .ana file with the output... -c allows output to stdout.
    – user44370
    Mar 20, 2014 at 16:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .