Question

I need to parse ffmpegs meta data output but it is different for some reason between a wav and a flac file.

Flac:

(int) 14 => '  Duration: 00:03:18.93, bitrate: 1045 kb/s',
(int) 15 => '    Stream #0:0: Audio: flac, 44100 Hz, stereo, s16',

Wav:

(int) 13 => '  Duration: 00:00:15.00, bitrate: 1411 kb/s',
(int) 14 => '    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s',

I could get the bitrate from the duration line too I think but why is it different? And will there be more differences in future releases? It really sucks that there is no better way to get the information from ffmpeg than to parse it's output. Any better ideas?

Here is my whole ffmpeg output and my parsed result:

http://pastebin.com/4qJfzZNL

Was it helpful?

Solution

I solved it finally by using ffprobe which comes with ffmpeg.

ffprobe -v quiet -show_streams -show_format -show_error -print_format <format> <file>

See the writers section of the documentation about the formats it supports, I've used json but xml, csv and ini are also supported.

OTHER TIPS

The stream line provides different information because each codec has different parameters. You will need to parse the line and depending on the audio type you will need to understand those parameters that come after it.

You could just use the bitrate in the duration line, but this may be misleading without knowledge of which codec is in use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top