RandomNinjaAtk / docker-lidarr-extended

lidarr-extended :: Lidarr application packaged with multiple scripts to provide additional functionality
GNU General Public License v3.0
275 stars 24 forks source link

[Feat]: Specify video filetype (MP4) to allow Plex to use local/embedded metadata. #233

Closed snorkrat closed 1 year ago

snorkrat commented 1 year ago

Is your feature request related to a problem? Please describe. Plex does not read embedded metadata from .mkv files, or from an inline .nfo file. Plex will only read embedded metadata from .mp4 or .m4v files (to the best of my knowledge). The current setup means that Plex does not receive any local/embedded metadata from the videos when using in a separate video library.

Describe the solution you'd like I would love the option of specifying an environment variable to change the filetype that the videos are saved as. Something similar to the audio format like:

videoFormat=mp4

Describe alternatives you've considered Modifying the video.sh myself to change from remuxing/endcoding from .mkv to .mp4. But I feel like this could break other things...

Additional context Currently the metadata options for use within Plex are useless as Plex does not recognise external/inline .nfo files or embedded metadata in .mkv files. Allowing the choice of .mp4 format would add external metadata functionality for Plex.

My specific use case I have a video library in Plex ONLY for music videos (I use this with dizqueTV for making music video Live TV channels) and when using the old AMVD (legacy script I believe) these were in .mp4 format. This automatically created categories in the Plex library for all the genres of videos and allowed me to create collections based on genre. For example, I could create a collection called "Rock" which would contain genres rock, hard rock, classic rock, etc. But as Plex does not get any genre info from the .mkv this does not work for me anymore.

Related additional functionality Maybe this deserves a separate request, but specifying the tags to include (or exclude?) in the finished file would be great as well. This could be used with .mkv or .mp4. Again using an environment variable with a comma separated list like:

videotagsinclude=genre,artist, or videotagsexclude=album

snorkrat commented 1 year ago

So I actually went ahead and got this working today, with the thought of having a docker environment variable such as videoFormat=mp4 to specify either mkv or mp4 which will be passed through to the files that require this.

The 2 files which needed modifying are sma.ini and Video.sh.

sma.ini

In the [Converter] section we need to change

output-format = mkv
output-extension = mkv

to

output-format = mp4
output-extension = mp4

Video.sh

I created a variable videoContainer=mp4 and used this value to replace all the extensions of .mkv throughout the script (apart from those that were matching either .mp4 or .mkv already).

I also needed to update the ffmpeg metadata tagging as there are different rules for tagging .mkv vs .mp4. The script checks if it is mkv and loops through tagging for mkv files, and if it is not mkv it then loops through tagging for mp4 files. I've tested and it tags correctly for both .mkv and .mp4.

Testing

Initially I had mapped my own local copy of sma.ini and Video.sh but I believe they get overwritten when the container starts, so I was testing by quickly overwriting the docker container versions before the script ran. Tested with both mkv and mp4 options set and metadata is present in both and video files play without issue.

The only thing left to do I guess is get an docker environment variable such as videoFormat=mp4 to pass through to the options in sma.ini and to the variable value in Video.sh

My Files I have attached a zip containing both sma.ini and my Video.sh script for you to compare side by side.

mp4_changes.zip

RandomNinjaAtk commented 1 year ago

MP4's have audio/video codec limitations, that is why it is not used. Also I'm fairly certain plex won't take advantage of it for music videos...

If you want the high quality youtube videos, you will not be able to get them without transcoding or forgoing the higher bitrate content because of codec limitations.

snorkrat commented 1 year ago

When using the global music video path in Plex (so they appear inline with the actual music in a dedicated music library), yes they don't use extra metadata - they just match to the music and which has already got metadata via Plex.

However, when in a separate "Music Videos" library Plex does use this metadata. It creates "Categories" based on the tags (specifically genre) and it also allows for searching using filters to create collections based on the metadata/tags. For example: I could make a "Rock" collection by filtering by a lot of different genres, or an "80s" collection by filtering by date. I think it could be quite useful.

I've added a few screenshots to illustrate. The "Old Music Videos" Library is using mp4's and the "Music Videos" is using mkv's. You can see the categories and filter options present in the "Old Music Videos" library, and the absence of them in the "Music Videos" library. Coupling this with something like Plex Meta Manager it would be quite powerful at creating bespoke music video collections for use with other services.

The solution above works pretty well, and I don't believe it has broken anything, although obviously you will know for sure. But gives flexibility for those of us that want the metadata in Plex. All that's missing is allowing a docker environment variable to specify mp4 for those that would want that. Although I appreciate it is time spent that you may not have!

plex_music_mp4_categories

plex_music_mkv_categories

plex_music_mp4_filters

plex_music_mkv_filters

edit: got my mkv/mp4 for my library examples the wrong way round!

RandomNinjaAtk commented 1 year ago

Again, mp4s don't support the codecs required, unless you want only subpar quality videos. Jellyfin/Emby support nfos and can do what your looking for, same with kodi.

snorkrat commented 1 year ago

Yeah I understand the codec issue for the likes of FLAC etc. We’re talking YouTube videos here so not exactly expecting Blu-ray quality. Especially if we’re grabbing 1000’s of music videos going back 40,50 years - they majority aren’t going to be super high res anyway.

I guess I thought expanding functionality to give Plex users the metadata if they prefer having that vs a slight reduction in quality would be beneficial. After all Plex has a vastly bigger user base than Emby and Jellyfin and I’d rather not spin up emby/jellyfin alongside Plex. I understand if you don’t want to add it in, it’s your thing after all. I just thought it was very complimentary.

Maybe one day Plex will just read metadata from MKV’s and we’ll all win.

Edit: Just to be clear. I agree with you that MKV will give superior quality. My solution isn't asking to replace the use of MKV, but just to add the option for MP4 for those that want the metadata in Plex and to expand the functionality of lidarr-extended.

Yosh82 commented 1 year ago

I also think this would be a nice feature if it was possible to add as a variable. I use Plex for everything other than music videos, due to Plex not being able to read mkv metadata / nfo's.

snorkrat commented 1 year ago

@Yosh82 If you download my files in my comment above, and replace the 2 files in the docker config/extended/scripts folder after the container has started, but before the script has run... it will work. I'd be keen to get feedback from somebody else that it works as expected lol.

Yosh82 commented 1 year ago

@Yosh82 If you download my files in my comment above, and replace the 2 files in the docker config/extended/scripts folder after the container has started, but before the script has run... it will work. I'd be keen to get feedback from somebody else that it works as expected lol.

You read my mind, I was about to DM you to ask for what you changed specifically. Thanks mate.

snorkrat commented 1 year ago

@Yosh82 If you download my files in my comment above, and replace the 2 files in the docker config/extended/scripts folder after the container has started, but before the script has run... it will work. I'd be keen to get feedback from somebody else that it works as expected lol.

You read my mind, I was about to DM you to ask for what you changed specifically. Thanks mate.

@Yosh82 Just had a look around and the scripts are actually stored in /scripts inside the container, and then moved to /config/extended/scripts. So just map /scripts to a directory on the host, ensure all the script files are in there, including the modified sma.ini and Videos.sh from above, and start the container. This will persist through container restarts.

Yosh82 commented 1 year ago

Thanks again @snorkrat - Left it re-downloading videos as mp4's last night, and I have some functionality in plex now 👍

If using Plex, this is very useful, as it can then use genres, and more importantly for me, it shows related videos again :) -

image

snorkrat commented 1 year ago

Awesome! Glad it's working as intended.

Just FYI from around line 470 in the modified Videos.sh you can see the metadata being inserted for .mp4 files/

-metadata title="${1}" \
-metadata date="$3" \
-metadata artist="$lidarrArtistName" \
-metadata genre="$genre" \

So you could in theory add other options in there if you want. But I feel like this is enough for now. and for me anyway.

Yosh82 commented 1 year ago

Thanks. I've had a look from the docker logs this morning and no errors related to the change (Unraid docker, current versions of docker and LE).

Not too sure how easy it would be to be added to LE as a variable, but would definitely be a nice option for Plex users who are loving LE but are struggling with the music video tagging.

snorkrat commented 1 year ago

In the interest of completing this implementation for myself (and @Yosh82) I forked the repo and added in the docker environment variable.

I made a slight tweak to my original solution, in that I created a separate sma-mp4.ini to use when setting mp4 as the container. This will allow greater flexibility for specifying different ffmpeg options for mkv and mp4. Video.sh script has been updated to check for filteype before using either sma.ini (for mkv) or sma-mp4.ini (for mp4).

Anyway, my fork is here

And here is a snippet from my docker-compose.yml to show setup.

docker-compose.yml

version: "3.8"
services:
   docker-lidarr-extended:
      image: snorkrat/docker-lidarr-extended
      build:
         context: https://github.com/snorkrat/docker-lidarr-extended.git#main
         dockerfile: arm64v8.dockerfile #change this dockerfile to suit your device architecture
      container_name: docker-lidarr-extended
      environment:
         - videoContainer=mp4

----------- rest of compose goes here -----------

The default value for videoContainer is mkv, as set in Dockerfile. So if you want to use mp4 please specify as shown above.

Again I do feel that adding this into the main repo would be beneficial for Plex users wanting to take advantage of the metadata. I agree MKV can give higher quality if the source video has it, which is why I have set MKV as the default. However flexibility is always good if it adds value right? And I feel for Plex users this can add value.

RandomNinjaAtk commented 1 year ago

If you can make it backwards compatible, I'd review a PR for incorporating the changes.

Things to keep in mind, you need to probably incorporate the following things:

  1. Adjust yt-dlp to natively use mp4 output, including adjusting the video codecs/formats to something compatible
  2. Have a second SMA config file for mp4 versions
  3. Detect existing files for both extensions, so if you switch to mp4 you don't end up with duplicates.
  4. The default option, if not specified should continue to operate as is.

These are just a few thoughts. It also needs to be able to be enabled by simply changing a ENV variable like you stated.

Edit:

Also be prepared to provide support for the changes...

Yosh82 commented 1 year ago

Although the mp4's play fine on Plex, I noticed the "date" for all the videos changes to import dates in Plex, so I decided to go back to Emby, to discover that none on the new mp4 files will play in Emby via the Samsung TV app (they play the video but without audio). I went back to the mkv's and they now play fine on Emby. Worth noting in case you have the need to use both.

snorkrat commented 1 year ago

Going to have a look into this more next week when I have time and see about adding in release date metadata and also tweaking the yt-dlp and/or ffmpeg options for more consistent mp4 files. Thanks for the feedback tho, very useful.

snorkrat commented 1 year ago

Okay so I think I've got this pretty nailed now.

Docker ENV:

added videoContainer ENV to Dockerfile(s). Options are either mkv or mp4

FFMPEG Options:

New sma-mp4.ini file for ffmpeg options specific to mp4 files. This will make it easy to change settings going forward.

yt-dlp:

Command specific for mp4: the main arguments are --format-sort ext:mp4:m4a --merge-output-format mp4

Embedded metadata

This is actually quite limited. Plex doesn't recognise that much when using an "Other Videos" library. Mainly TITLE, ARTIST, GENRE. Unfortunately @Yosh82 , while the date (year) is successfully added to the mp4 metadata, as seen when using ffprobe, it is not picked up by Plex (to the best of my knowledge). I checked my old mp4 library and the date is also set to the import date. The main thing I was wanting was genre in order to filter and to have the categories automatically create.

Plex will pickup the ALBUM metadata, however it creates a collection tag with this which I didn't like as it gets extremely messy, so I have left that out. Also the lidarrAlbum info wasn't passed through to the Video.sh anyway (to the best of my knowledge).

Previously Downloaded:

Modified the check for presence of both mkv OR mp4 files in order to not download duplicates.

Note:

Default option if no ENV is set will always be MKV. Like you said, better overall quality and more embedded metadata.

Testing:

I have carried out the following tests:

Ran using both mkv, and mp4 variables and ended up with the same amount of videos (approx 2000).

Using these videos I mixed and matched approx 1000 mkvs and 1000 mp4s into one library. Ran the script again using both mp4 and mkv ENV and it successfully detected the videos were already downloaded each time. No duplicates.

Tested videos with Quicktime and VLC on macOS. Note: @Yosh82 I made significant changes to the way the videos were downloaded and processed since you lasted tested. I believe they should now work on Emby (and anywhere else), if you are still interested I'd be grateful if you would test that for me. Just for curiosity's sake - the issue here I believe was the embedded thumbnail. The default image was picked from youtube, which sometimes would be a webp file. I make sure the embedded thumbnail gets converted to jpeg.

Imported to Plex and can see metadata - albeit limited as Plex only picks out a few fields.

At least the main work here is done and should be pretty easy and clear to modify going forward.

PS - While we're at it, please consider voting for NFO support in Plex. It would be much better if Plex could support NFO files. I don't see the point of giving users the option of an "Other videos" library, but then not having a good way to organise these videos.

Yosh82 commented 1 year ago

Some feedback from my testing, as something will need changing on how it encodes I think for this to work properly.

I used your modified script to download as MP4, but this caused 2 issues:

  1. It corrupted my plex database, it got stock in a loop when scanning the mp4's, removed the mp4 library and put mkv back in, and all ok after a db scan.

  2. It seems the encoding to mp4 isn't working as expected, as any of the mp4's downloaded from the script play ok in Plex, but not Jellyfin or Emby. I then used handbrake to re-encode the mp4's to mp4's again, and this fixed the files playing on other platforms, so it seems it's related to the way it converts to mp4 in the video.sh.

I then edited the mp4's in musicbrainz which can pull down all the tags, but then Plex doesn't support the embedded tags for music videos anyway, even as mp4! (e.g I wanted the release year in the tags, but Plex cannot pull this info in as it doesn't hold a field for it in any library other than Audio).

I'm just going to use Emby for music videos until Plex dev team pulls their finger out!

snorkrat commented 1 year ago

Some feedback from my testing, as something will need changing on how it encodes I think for this to work properly.

I used your modified script to download as MP4, but this caused 2 issues:

  1. It corrupted my plex database, it got stock in a loop when scanning the mp4's, removed the mp4 library and put mkv back in, and all ok after a db scan.
  2. It seems the encoding to mp4 isn't working as expected, as any of the mp4's downloaded from the script play ok in Plex, but not Jellyfin or Emby. I then used handbrake to re-encode the mp4's to mp4's again, and this fixed the files playing on other platforms, so it seems it's related to the way it converts to mp4 in the video.sh.

I then edited the mp4's in musicbrainz which can pull down all the tags, but then Plex doesn't support the embedded tags for music videos anyway, even as mp4! (e.g I wanted the release year in the tags, but Plex cannot pull this info in as it doesn't hold a field for it in any library other than Audio).

I'm just going to use Emby for music videos until Plex dev team pulls their finger out!

That's strange. I've just set up an Emby server an imported all my mp4 videos that I re-downloaded this morning and they are playing fine on Emby web and also Apple TV app.

Are you sure you're using the latest version of Video.sh? The issues you're having sound like the original script. If you're pulling from my git repo, I believe you'll need to build the image again as it doesn't automatically pull the latest.

Yosh82 commented 1 year ago

Some feedback from my testing, as something will need changing on how it encodes I think for this to work properly. I used your modified script to download as MP4, but this caused 2 issues:

  1. It corrupted my plex database, it got stock in a loop when scanning the mp4's, removed the mp4 library and put mkv back in, and all ok after a db scan.
  2. It seems the encoding to mp4 isn't working as expected, as any of the mp4's downloaded from the script play ok in Plex, but not Jellyfin or Emby. I then used handbrake to re-encode the mp4's to mp4's again, and this fixed the files playing on other platforms, so it seems it's related to the way it converts to mp4 in the video.sh.

I then edited the mp4's in musicbrainz which can pull down all the tags, but then Plex doesn't support the embedded tags for music videos anyway, even as mp4! (e.g I wanted the release year in the tags, but Plex cannot pull this info in as it doesn't hold a field for it in any library other than Audio). I'm just going to use Emby for music videos until Plex dev team pulls their finger out!

That's strange. I've just set up an Emby server an imported all my mp4 videos that I re-downloaded this morning and they are playing fine on Emby web and also Apple TV app.

Are you sure you're using the latest version of Video.sh? The issues you're having sound like the original script. If you're pulling from my git repo, I believe you'll need to build the image again as it doesn't automatically pull the latest.

Have you tested a fair number yet? A few did play ok, then the rest played without audio. I had the issue on the windows emby app and samsung tv app (tizen). Originally I thought it was just the Samsung app, but have also seen it in the windows app. I thought they were corrupted files, but after re-encoding with handbrake, they then worked.

snorkrat commented 1 year ago

Some feedback from my testing, as something will need changing on how it encodes I think for this to work properly. I used your modified script to download as MP4, but this caused 2 issues:

  1. It corrupted my plex database, it got stock in a loop when scanning the mp4's, removed the mp4 library and put mkv back in, and all ok after a db scan.
  2. It seems the encoding to mp4 isn't working as expected, as any of the mp4's downloaded from the script play ok in Plex, but not Jellyfin or Emby. I then used handbrake to re-encode the mp4's to mp4's again, and this fixed the files playing on other platforms, so it seems it's related to the way it converts to mp4 in the video.sh.

I then edited the mp4's in musicbrainz which can pull down all the tags, but then Plex doesn't support the embedded tags for music videos anyway, even as mp4! (e.g I wanted the release year in the tags, but Plex cannot pull this info in as it doesn't hold a field for it in any library other than Audio). I'm just going to use Emby for music videos until Plex dev team pulls their finger out!

That's strange. I've just set up an Emby server an imported all my mp4 videos that I re-downloaded this morning and they are playing fine on Emby web and also Apple TV app. Are you sure you're using the latest version of Video.sh? The issues you're having sound like the original script. If you're pulling from my git repo, I believe you'll need to build the image again as it doesn't automatically pull the latest.

Have you tested a fair number yet? A few did play ok, then the rest played without audio. I had the issue on the windows emby app and samsung tv app (tizen). Originally I thought it was just the Samsung app, but have also seen it in the windows app. I thought they were corrupted files, but after re-encoding with handbrake, they then worked.

Do you have some specific artists/videos that aren't working? I can add them to my library and download to test.

Yosh82 commented 1 year ago

Typically, I was just seeing if I still had the mp4's but have deleted them. I'll setup a 2nd lidarr setup at some point and do some more testing and will let you know.

After spending a while looking into it yesterday, until Plex has music video support, it just can't do what I need it to do with the tags it can use for them. I tried to manipulate the tags it lists in Plex, e.g. composer, so added a tag in the mp4 for Composer as the Artist, and it ignores that too, so I gave up and went back to Emby. I just want to put on a "90s mix" for example, but Plex just doesn't support it.

snorkrat commented 1 year ago

A few videos that you have known issues with would be great so I can debug.

I feel you. The metadata support is limited, for me personally the genre categories will be enough. IIRC the Artist gets put in the "Actor" field/tag if that's any help. In my house, if it was just for me - I'd probably use Emby. But having everything in one place is nice for the others. I make "MTV" style live TV channels using dizqueTV, so getting them in Plex is key.

I appreciate the testing tho, good to see what works/doesn't work for others.

RandomNinjaAtk commented 1 year ago

You should use: https://ersatztv.org/

I believe dizquetv is no longer maintained.

snorkrat commented 1 year ago

You should use: https://ersatztv.org/

I believe dizquetv is no longer maintained.

I looked at ersatztv a long time ago and couldn’t get it doing what I wanted at the time. Will take another look. The dev of dizquetv still responds to issues etc, but I’m not sure if it’s very active either.

@Yosh82 - I had a video or two that wouldn’t play on Emby this afternoon (audio no video). Using ffprobe the codecs were the same, one was slightly higher bitrate but that was all (AV1 video). I dug around the Emby client settings (Apple TV) and found a strange issue. If I chose either MPV or Native as the player type the same video played without issue. But leaving it on auto I just got audio. Very strange…

Yosh82 commented 1 year ago

I've redownloaded some test files as mp4. I can't find any that won't play on Windows as yet.

Same issue on Tizen app, plays video, no audio.

Just tested on the Xbox One X, which does play the audio, but the picture jerks / lags, so it doesn't seem Emby related, especially as if you re-encode them to mp4 via handbrake, they play fine.

Yosh82 commented 1 year ago

I noticed it was transcoding the mp4's from the script, which it should direct play, and also trying to recover from error's which it never recovers from: image

I took the same video from the script as MKV, used handbrake and encoded to mp4 h264 (I forgot to change the audio codec to opus to match - I'll test that after, but in the snippet, it's the video transcoding). The mp4 from the mkv using handbrake plays fine, direct stream: image

I'll do some more testing, but it seems it's related to the encoding. I assume it's not just changing the container from mkv to mp4 and it is encoding to mp4? I've not checked the script myself.

Yosh82 commented 1 year ago

And lastly, I took the mp4 which had the issues, encoded to mp4 (from the mp4), and plays fine: image

I tried checking the file validation with ffmpeg tools but no useful info, it gave blank logs back for some reason. I think it's not encoding them to "real" mp4 format.

Edit: Handbrake doesn't have vp9 codec, but the mkv's use it, and direct stream fine, so it shouldn't need transcode? I'm not great with codecs, so best guess - Just trying to give as much info as possible. 👍

RandomNinjaAtk commented 1 year ago

Pretty sure VP9/opus is incompatible with MP4's... This goes back to my statements earlier about the limitations and problems with using mp4 as a container.....

snorkrat commented 1 year ago

@Yosh82 thanks for the info. I'll edit some of the yt-dlp/ffmpeg commands and make it more compatible. The reason they are playing after you convert seems like it could be due to changing codecs, so I will look at downloading a different version with yt-dl. I'll use the same music video as a test.

@RandomNinjaAtk VP9 and Opus are both definitely compatible with mp4. If they are not playing it is a client problem. That being said, these may not be widely supported by a lot of clients in an mp4 container. That I am unsure of.

Edit: After a very quick google search it seems like the issue is as suspected. While officially mp4 can support VP9, client support is limited for VP9 in mp4 container. Simple solution which I'll look at this week.

snorkrat commented 1 year ago

@Yosh82 Are you 100% sure for your tests that you have been using the newest update to the Video.sh script? The issues you were having sounded the same as my initial script which didn't really have great options for mp4.

I've just tested with the 50 Cent - Ayo Technology video. Using the OLD script the yt-dlp command is yt-dlp -f "bestvideo*+bestaudio/best" --no-video-multistreams --cookies "/path/to/folder/cookies.txt" -o "/path/to/folder/50 Cent - Ayo Technology - OLD.%(ext)s" --embed-subs --merge-output-format mp4 --remux-video mp4 --no-mtime --geo-bypass "https://www.youtube.com/watch?v=5RDSkR8_AQ0"

this basically downloads the same video as the mkv version and wraps it in an mp4 container. Using ffprobe on this video I get:

Duration: 00:04:08.80, start: 0.000000, bitrate: 1580 kb/s
  Stream #0:0[0x1](eng): Video: vp9 (Profile 0) (vp09 / 0x39307076), yuv420p(tv, bt709), 1920x1080, 1445 kb/s, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 16k tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Audio: opus (Opus / 0x7375704F), 48000 Hz, stereo, fltp, 126 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : English - en

Using the new script, the yt-dlp command is: yt-dlp --format-sort ext:mp4:m4a --merge-output-format mp4 --no-video-multistreams --cookies "/path/to/folder/cookies.txt" -o "/path/to/folder/50 Cent - Ayo Technology - NEW.%(ext)s" --embed-subs -- --no-mtime --geo-bypass "https://www.youtube.com/watch?v=5RDSkR8_AQ0"

ffprobe results for this are:

  Duration: 00:04:08.85, start: 0.000000, bitrate: 1910 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 1773 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc.
      vendor_id       : [0][0][0][0]
  Stream #0:2[0x3](eng): Subtitle: mov_text (tx3g / 0x67337874), 0 kb/s (default)
    Metadata:
      handler_name    : English - en

As you can see from the OLD script we get vp9/vp09 and opus/opus which are the same codecs you are having issues playing. But with the new script we get h264/avc1 and aac/mp4a which should be much more compatible.

You will need to build the image again with docker as this does not pull automatically. In the logs when the Video.sh script starts after the Lift off in... 5, 4, 3, 2, 1 it should print CONFIG :: yt-dlp format (mp4): --format-sort ext:mp4:m4a --merge-output-format mp4". This is how you know you're using the newest script.

Yosh82 commented 1 year ago

Doh, seems I've been mistakenly using the old script. Thanks @snorkrat - Will test it the latest script

RandomNinjaAtk commented 1 year ago

Merged the PR, thanks for the contribution.

Yosh82 commented 1 year ago

Is there a field we could use for the "year" metadata for the mp4, whic plex can filter by? Sorry, I should have mentioned this when it was added to the mkv nfo.

Killface1980 commented 1 year ago

You shouldn't use year. https://kodi.wiki/view/NFO_files/Music_videos image

snorkrat commented 1 year ago

Is there a field we could use for the "year" metadata for the mp4, whic plex can filter by? Sorry, I should have mentioned this when it was added to the mkv nfo.

AFAIK the "year" metadata field is not actually supported in mp4. The equivalent so to speak is the "date" tag. It does mention the year tag in some FFMPEG documentation, but I read in a number of places that this is actually incorrect, and the field used in mp4 is "date". See here for a list of tags, and those supported in mp4.

The date tag does get added in the script, but Plex overwrites their "originally available" field with the file modification date (which will be the import date) when using the "Personal Media" agent. To go a bit more in depth, lets look at the PersonalMedia.bundle code which is used when selecting the Personal Media Agent:

class PlexPersonalMediaAgentMovies(Agent.Movies):
  name = 'Personal Media'
  languages = [Locale.Language.NoLanguage]

  def search(self, results, media, lang):

    # Compute the GUID based on the media hash.
    part = media.items[0].parts[0]

    # Get the modification time to use as the year.
    filename = unicodize(part.file)
    mod_time = os.path.getmtime(filename)

    results.Append(MetadataSearchResult(id=part.hash, name=media.name, year=time.localtime(mod_time)[0], lang=lang, score=100))

  def update(self, metadata, media, lang):

    # Get the filename and the mod time.
    filename = unicodize(media.items[0].parts[0].file)
    mod_time = os.path.getmtime(filename)

    date = datetime.date.fromtimestamp(mod_time)

    # Fill in the little we can get from a file.
    try: title = os.path.splitext(os.path.basename(filename))[0]
    except: title = media.title

    metadata.title = title
    metadata.year = date.year
    metadata.originally_available_at = Datetime.ParseDate(str(date)).date()

As we can see metadata.year gets set to date.year, and the date here is set to the mod_time essentially. So without using a custom agent, this can't be done.

I am actually looking into creating a "music video" agent based off XBMCnfoMoviesImporter.bundle-for-Plex, or Plex-NFO-Import-Agent. This, however, defeats the purpose of tagging the mp4, as this will use an inline .nfo file, so in this case we may as well use .mkv. The linked XBMCnfoMoviesImporter.bundle-for-Plex and Plex-NFO-Import-Agent actually work pretty well as is using the generated nfo files from docker-lidarr-extended and adds the videos including the correct year, the only nitpick I have is that it adds the videos in as a "movies" library, instead of "other" and so the thumbnails are portrait instead of landscape and do not look as nice. Just a side note on this incase you want to try, I thought these weren't working at all as I was updating an existing library to use these agents, but creating a new library and choosing the agent to begin with worked well.

One interesting thing I noticed that when adding a large music video library to Plex using the Personal Media agent was that before the agent could finish processing all the videos I noticed the date was actually correct in Plex! But after finishing/updating metadata it changed to the modification/import date. Maybe if we just removed

metadata.year = date.year
metadata.originally_available_at = Datetime.ParseDate(str(date)).date()

it might work? I can test at some point - but thought I would share my findings so far...

To circle back to the start, I have added every metadata field available for mp4 containers to a test video file, with a year (1987) or a date (1987-01-01) to see if Plex would pick it up, but unfortunately it's a no from Plex.

RandomNinjaAtk commented 1 year ago

Closing this because the PR was merged that implemented the requested feature.