ffmpeg - How to check (programmatically) if a file has DRM protection?

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 !

waldenCalms

Posted 2018-12-18T00:19:46.637

Reputation: 75

DRM is a very broad term – there's no single mechanism in ffmpeg for detecting whether it's present or not. The string you found is only valid for ASF decoding. In your use case, are you talking about audio only? – slhck – 2018-12-18T08:14:23.570

Yes, audio only. Hmm, ok. – waldenCalms – 2018-12-18T10:31:48.600

I guess the real question is: Why does your app need to know that, and what kinds of files (containers, codecs) will you be handling? That said, I am not sure if there are really so many DRM formats for audio floating around. Probably iTunes (AAC/MP4), PlayReady (WMA/ASF), … – slhck – 2018-12-18T13:24:56.937

My app is an audio player, and cannot handle DRM files, so if DRM is detected, it will simply inform the user that it cannot be played. I noticed that ffmpeg transcoding actually appears to succeed (zero exit code) even though the file is protected, so I cannot always rely on the transcoding process exit code to detect an error, so I need some other way. Otherwise, ffmpeg will produce an empty file (a few KB) that actually plays silence for the duration of the track. This is not an ideal user experience for an audio player. I need to detect DRM protection so I can tell the user "Sorry". – waldenCalms – 2018-12-18T22:36:31.620

@waldenCalms Have you found a way to do this? I got the same problem. – RRN – 2019-05-09T14:58:23.430

@RRN Nope, I still haven't found a way to do this, sorry :( If I find something, I'll be sure to post an answer. – waldenCalms – 2019-06-02T09:39:00.913

No answers