jkirkcaldy / plex-utills

Manage your Plex library automatically
MIT License
319 stars 24 forks source link

[Request] Extend Dolby Vision detection #65

Closed KnifeFed closed 2 years ago

KnifeFed commented 2 years ago

I just ran this on all my movies and none of the Dolby Vision files got a DV banner. Then I saw this on the "Recreate HDR Posters" page: "You will need to have "Dolby Vision" or "HDR10" included in your filename for this detection to work.".

I use the original filenames for all movie files so none of them have the exact term Dolby Vision in them, it's either DV or DoVi.

Would it be possible to add support for this type of naming scheme, e.g. with a regex like \b(dv|dovi|dolby.?vision)\b? Alternatively, allow for the user to supply their own regex to match.

jkirkcaldy commented 2 years ago

I've changed the way this works now. It uses MediaInfo to scan the files to find the HDR version.

Annoyingly the results it gives are slightly different on each platform. But I think I've sorted this now. It should work in the next release.

KnifeFed commented 2 years ago

That's great! Let me know if you need any help testing.

jkirkcaldy commented 2 years ago

That's great! Let me know if you need any help testing.

I have a script that you can test if you like.

If you download the :dev tagged docker container, then once it's up and running go to /api/data to start the script then /dev to see the results

The script will go through and scan all your HDR films and add them to a database. This should show you the film, what version HDR is being used, the resolution and the audio format. This should help make sure that the dolby vision detection is working.

I don't have any dolby vision files at the moment so it's difficult to test.

Note that the data will be added over and over again for each time you run the script. you can use /api/del_data to remove the table from the database then you can re-run the script with a fresh table.

image

KnifeFed commented 2 years ago

I just ran it and it didn't detect Dolby Vision for any of the files, only their HDR/HDR10+ fallbacks. Dolby Atmos/DTS:X detection seems to be working great though.

These are the unique HDR format strings I get when I run mediainfo on all my DV files (a mix of UHD Blu-ray remuxes/encodes and WEB-DL:s in MKV/MP4 containers):

$ mediainfo --version

MediaInfo Command line,
MediaInfoLib - v21.09

$ find . -type f -regextype egrep -iregex '.*\b(do?vi?|dolby.?vision)\b.*\.(mp4|mkv)$' -exec mediainfo --Inform="Video;%HDR_Format/String%" {} \; | sort | uniq

Dolby Vision, Version 1.0, dvhe.05.06, BL+RPU
Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible
Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2094 App 4, Version 1, HDR10+ Profile B compatible
Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible
Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible / SMPTE ST 2086, HDR10 compatible

(btw, I wasn't allowed to save the server config settings until I entered some dummy data for the Tautulli URL/API key)

jkirkcaldy commented 2 years ago

Yeah, I figured it out. What is really annoying, is Plex doesn't label Dolby Vision files as HDR.

Changing the script to search all files works and detects dolby vision. But it has the downside is having to scan your entire library to find the files.

mcqweb commented 2 years ago

Plex does store some information about Dolby Vision, but not in the main library calls, here is my hack to get Plex to tell me rather than MediaInfo

    full_info_url = f'{PLEX_URL}{i.key}?includeExternalMedia=1&checkFiles=1&asyncCheckFiles=0&X-Plex-Token={PLEX_TOKEN}'
    file_details = requests.get(full_info_url,headers={'Accept': 'application/json'}).json()
    for stream in file_details['MediaContainer']['Metadata'][0]['Media'][0]['Part'][0]['Stream']:
        if stream['streamType'] == 1:
            if 'DOVIPresent' in stream:
                poster_dv()
        continue
jkirkcaldy commented 2 years ago

Plex does store some information about Dolby Vision, but not in the main library calls, here is my hack to get Plex to tell me rather than MediaInfo

    full_info_url = f'{PLEX_URL}{i.key}?includeExternalMedia=1&checkFiles=1&asyncCheckFiles=0&X-Plex-Token={PLEX_TOKEN}'
    file_details = requests.get(full_info_url,headers={'Accept': 'application/json'}).json()
    for stream in file_details['MediaContainer']['Metadata'][0]['Media'][0]['Part'][0]['Stream']:
        if stream['streamType'] == 1:
            if 'DOVIPresent' in stream:
                poster_dv()
        continue

That's useful thanks, I have to use media info to scan for dolby atmos/dts:x anyway. Using media info also allows you to diferenciate between HDR10, HDR10+ and Dolby Vision.

KnifeFed commented 2 years ago

I just ran the latest script and now it detected Dolby Vision in 4 out of 30 DV movies.

The ones detected are all HMAX WEB-DL:s and have this HDR format string: Dolby Vision, Version 1.0, dvhe.05.06, BL+RPU. These 4 movies do not say that they're HDR in Plex since they don't have an HDR fallback.

All other DV movies are Blu-ray remuxes except one more WEB-DL that's from iTunes. That one also has the above-mentioned HDR format string. When I checked it on /api/data it says the HDR version is hdr10 / hdr10 but it's also DV without HDR fallback (doesn't say HDR in Plex), yet still got an HDR banner.

So, none of the other strings that I mentioned earlier were detected.

jkirkcaldy commented 2 years ago

Can you pull the latest plex-utills:dev container, connect to the console and run

python dv_test.py "name of film with dolby vision"

It should look like this:

root@3fc8f45bf6cb:/app# python dv_test.py "finch"
Finch - Dolby Vision - Dolby Digital Plus with Dolby Atmos

If that works then the bugs should be sorted. (restore posters script and HDR banners on 4K SDR content is fixed in the dev container too"

KnifeFed commented 2 years ago

It did not make any difference, the same 4 files were detected and now I realize why. You're checking HDR_Format_Commercial first and accepting that value if it exists. Here's what I get if I run that on my 30 DV movies:

$ find /films/movies/lib -type f -regextype egrep -iregex '.*\b(do?vi?|dolby.?vision)\b.*\.(mp4|mkv)$' -exec mediainfo --Inform="Video;%HDR_Format_Commercial%" {} \; | sort | uniq
Blu-ray / HDR10
Blu-ray / HDR10+
Dolby Vision
HDR10 / HDR10

If I use HDR_Format I get:

$ find /films/movies/lib -type f -regextype egrep -iregex '.*\b(do?vi?|dolby.?vision)\b.*\.(mp4|mkv)$' -exec mediainfo --Inform="Video;%HDR_Format%" {} \; | sort | uniq
Dolby Vision
Dolby Vision / SMPTE ST 2086
Dolby Vision / SMPTE ST 2094 App 4

And if I use HDR_Format/String (like I mentioned earlier) I get:

$ find /films/movies/lib -type f -regextype egrep -iregex '.*\b(do?vi?|dolby.?vision)\b.*\.(mp4|mkv)$' -exec mediainfo --Inform="Video;%HDR_Format/String%" {} \; | sort | uniq
Dolby Vision, Version 1.0, dvhe.05.06, BL+RPU
Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible
Dolby Vision, Version 1.0, dvhe.07.06, BL+EL+RPU, Blu-ray compatible / SMPTE ST 2094 App 4, Version 1, HDR10+ Profile B compatible
Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, Blu-ray compatible / SMPTE ST 2086, HDR10 compatible
Dolby Vision, Version 1.0, dvhe.08.06, BL+RPU, HDR10 compatible / SMPTE ST 2086, HDR10 compatible

So to determine all of…

  1. if it's HDR only
  2. if it's DV only
  3. if it's HDR10+ (always has HDR fallback, I think)
  4. if it's DV with HDR fallback
  5. if it's DV with HDR10+ (and HDR) fallback

…it seems you would need to parse the full HDR_Format/String.

Btw, I noticed you don't have the latest version of Mediainfo in the container. In the 21.03 changelog, they state "+ Matroska: add DV support". I'm not sure what exactly that entails though since for 20.09 (the version in your container) they state "+ MKV: support of Dolby Vision metadata".

jkirkcaldy commented 2 years ago

Ok that makes sense. The reason it was using HDR_format_Commercial is that if you as for HDR_Format, anything that wasn't dolby vision came back as SMPTE xxxx

I think I've sorted it now. The dv_test script will check for the HDR_Format_String which contains all of the HDR versions including dolby vision. Then if dolby isn't in the string it checks for other HDR versions.

I downloaded some dolby test files from their website which helped, as any profile 5 DV stuff worked as expected but the higher profiles with HDR fallback didn't.

If you could test it again, that would be great. dev docker has been pushed now.

KnifeFed commented 2 years ago

At first, I got:

$ python dv_test.py "Movie Name"
Traceback (most recent call last):
  File "/app/dv_test.py", line 17, in <module>
    films = plex.library.section("test-files")
  File "/usr/local/lib/python3.9/site-packages/plexapi/library.py", line 67, in section
    raise NotFound('Invalid library section: %s' % title) from None
plexapi.exceptions.NotFound: Invalid library section: test-files

I changed it to films = plex.library.section("Movies") and then it ran on the whole library. It seems like everything is working perfectly now, including 4K SDR! 👍

I assume /api/data wasn't supposed to work in this release? Because that data remained the same.

jkirkcaldy commented 2 years ago

I assume /api/data wasn't supposed to work in this release? Because that data remained the same. no, I didn't change any of that. I was just trying to get something together quickly.

I'll merge that into the poster script and then it should be good to go so I'll close this.

Thanks for the help.

KnifeFed commented 2 years ago

Thank you, great job!