2

I have an app that runs ffmpeg/ffprobe as a child process (similar to running on the command line), and then parses the command output to retrieve metadata about a file and/or perform transcoding of the file. And my app needs to know whether or not a given file is DRM protected.

NOTE - I have looked at this question. It does not address programmatic parsing of output to determine DRM protection. It only addresses human parsing of output.

I already know that I can run ffprobe and if I scan through the output with my eyes and see something like "DRM protection detected ... decoding will likely fail" somewhere in the output, I know that the file is protected. See this sample output:

ffprobe -hide_banner CelticWoman-OnlyAWomansHeart.wma

[asf @ 0x7f9bab000000] DRM protected stream detected, decoding will likely fail!
Input #0, asf, from 'CelticWoman-OnlyAWomansHeart.wma':
Metadata:
...

However, there are two problems with the above output:

1 - It is not machine-friendly. I have to scan through a whole bunch of output to look for a few words. Parsing such output is inefficient, because it is intended for human consumption, not machine consumption.

2 - I don't know if the above output is consistent across different file types. In other words, the sample output above is for a WMA file in an ASF container. What if this were a FLAC or DTS or other kind of file ? Would the verbiage used be the same so my app could parse and detect it each time ?

What I need is some sort of output property that my app can reliably and predictably parse ... some key-value pair like "drm-protected=true" that is consistent across media file types

So, what options on ffprobe/ffmpeg will give me a machine-parseable key-value pair that tells me whether a file has DRM protection ?

Thanks a million !

1 Answers1

2

Use options like this

ffprobe -v quiet -print_format json -show_format -show_streams

This was first posted here https://gist.github.com/nrk/2286511
An example of this in use with "jq" to parse the json is:

ffprobe -v quiet -print_format json -show_format -show_streams songFile.mp3 | jq .streams[0].codec_tag_string

That will return the stream codec or "drms" for DRM protected streams. Please note this only returns output for the first stream as selected using "jq"

abear
  • 21