stevezau / plex_generate_vid_previews

Speed up the process of generating preview thumbnails for your Plex media library.
62 stars 10 forks source link

Add support for GenerateBIFKeyframesOnly parameter #40

Closed boblickj closed 4 days ago

boblickj commented 3 months ago

Certain video files will not generate previews with the default Plex ffmpeg args if the encoded media has a lack of keyframes. This can be fixed by adding GenerateBIFKeyframesOnly="0" to parameters.xml. Essentially, this removes -skip_frame:v nokey from the argument list. This shouldn't be enabled by default as it can increase processing time, but in my experience, it now successfully generates previews for all media.

I can submit a PR if this is something you would be okay supporting.

https://www.reddit.com/r/PleX/comments/u2u5j1/generating_video_preview_thumbnails_keeps_redoing/ https://support.plex.tv/articles/201105343-advanced-hidden-server-settings/

stevezau commented 3 months ago

Hey @boblickj thanks for taking the time to create an issue for this.

That prob explains why I've seen it randomly fail, just never had the time to dig into why, partly due to my limited ffmpeg knowledge.

Yes, def open to a PR but what are you thinking on how to get it working? Can we somehow detect the lack of keyframes prior to running ffmpeg?

boblickj commented 2 months ago

@stevezau

Looked into this a bit — technically we can count the keyframes using ffprobe, but it’s essentially a linear scan over the file contents. This isn’t really an issue for small files, but kills processing for any large REMUX.

My two thoughts were to either just add a new on/off parameter similar to how plex does it, or we could add a check to count the number of images generated before creating the BIF. The only caveat to this is the number of keyframes can vary quite a bit depending on the motion in videos, so we would probably need to create an arbitrary threshold of expected vs actual.

stevezau commented 2 months ago

Hey @boblickj, hmm ok. I am not sure if i fully understand this but in my mind couldn't we just detect the error from FFMPEG and rerun without "-skip_frame:v "?

That way the user does not need to worry about any settings?

boblickj commented 2 months ago

Hey @stevezau,

We can get the count of keyframes with the below command, but its runtime scales with file size. This isn't an issue if your library is small -- however in my tests, processing a single ~80GB REMUX takes about 10 minutes on a high-speed enterprise HDD.

I think the best solution is a hybrid:

  1. Get target number of output jpgs (media duration / PLEX_BIF_FRAME_INTERVAL)
  2. Run existing process as normal
  3. Get count of output jpgs and compare to value from 1
  4. Rerun without -skip_frame:v nokey if necessary

ffprobe -loglevel error -hide_banner -select_streams v:0 -show_entries packet=pts_time,flags -of csv=print_section=0 <input file> | grep K | wc -l

stevezau commented 2 months ago

@boblickj, can I confirm my understanding of the problem before we choose a path forward.

Is this right?

You propose we add a setting that removes the flag "-skip_frame:v nokey" from the FFMPEG command.

From a user experience perspective

OR.. Are you saying it still succeeds, but because of the lack of keyframes, only a few video preview files are generated?

stevezau commented 2 months ago

@boblickj ^^?

stevezau commented 1 month ago

@boblickj haven't heard from you?

stevezau commented 4 days ago

Closing due to inactivity.