ffprobe – Using FFmpeg to detect alpha channel in PR4444 file

I wanted to comment on a thread that already exists on this topic in general, but I just signed up to SO and have not earned my contribution credits yet! If anyone has advice on how to better handle that in the future, I am all ears!!

None-the-less, here is that thread:

stackoverflow.com/questions/69029439/a-good-way-to-detect-alpha-channel-in-a-video-using-ffmpeg-ffprobe/69030041#69030041?newreg=ba5899a955914c74a99a2e8b4ce3d12c

I tried both the answers listed in that post to detect the presence of an alpha channel in a PR4444 video file.

For Gyan’s answer, I get the following pixel format from any PR4444 file (regardless if encoded with alpha or no alpha), when running part 1:

yuva444p12le

As you will see in Gyan’s notes, even if a FFprobe returns an “a” in the return string (for the call for pixel format), that does not equate to the presence of an alpha channel. Hence their note for the subsequent (part 2) call…

I then plugged that into the part 2 of Gyan’s answer, but that produced an empty from FFmpeg, and a message providing valid arguments to pair with grep. It seems as though -oP is not a valid arg for grep? Because it wasn’t listed in the returned list of options. This is the template I used (pulled verbatim from Gyan’s posted solution):

ffprobe -v 0 -show_entries pixel_format=name:flags=alpha -of compact=p=0 | grep “$PIX_FMT|” | grep -oP “(?<=alpha=)\d”

Where $PIX_FMT is to be replaced with yuva444p121e (per Gyan’s instructions).

I then tried Benji’s solution for part 2, but that just returns the following:

pix_fmt=yuva444p12le

Of course, this isn’t any more useful than part 1…

I suspect Gyan is on the right track as he mentions part 2 should produce a boolean result for the presence of an alpha channel. However, either I am misunderstanding the syntax of his template, or something has changed in FFprobe since. There is so limited information out there for this specific task. Hoping someone with more experience and knowledge can help shed some light for me??

Read more here: Source link