Just to check, how long does it take to create thumbnails for a movie? There are a few reasons this can become very slow even on fast systems. If it’s more than a few minutes per movie, something might be wrong.
This is doable but I’m not aware of anything already assembled. Using the GPU wouldn’t dramatically accelerate the process.
When Plex is extracting thumbnails you can see the command that it’s executing in the process table and in the logs. An ffmpeg equivalent is something like this:
Then they’re assembled together into index-sd.bif files. There are a few ways to do this. Relevant search keywords that may help are index-sd.bif, Roku and BIF.
Then you’d need to put the created index-sd.bif file in the correct location for Plex. Here’s a recent discussion about that.
It takes roughly 4-5mins per file, i think. Do you have links on what would cause it to run slow so i can check if that’s the case for me?
I noticed when it is generating the thumbs it calls “/usr/lib/plexmediaserver/Plex Transcoder” with various args. My script will need to figure out the codec as i noticed “-codec:v hevc” as an arg.
Can i assume all the other args don’t change per file?
5 minutes is slowish for 1080p on a modern computer. You could share server logs if you want.
Plex Transcoder is Plex’s version of ffmpeg with additional special sauce. You don’t need to specify -codec:v blah because ffmpeg will autodetect the codec. If autodetection doesn’t work, neither will specifying the codec.
The quality/size/aspect flags stay the same when Plex generates VPTs.
You could adjust the FPS. That can significantly speed up VPT generation and reduce VPT file size. I should have suggested this before:
@Volts I’ve managed to write a rough script and it seems to be working.
It processing time went from 3-4mins to 20-30 seconds… FFmpeg with hw accel processes file between 250x and 700x speed… Compared to the 70x using CPU. Huge speedup.
still makes me wonder why plex does not support this natively.
That’s significantly faster than I expected! Neat. I might guess that keyframe extraction just doesn’t parallelize well across multiple threads.
I wonder if there’s any way to speed up the jpeg encoding, too! I suspect that’s actually a majority of the CPU time now. At first glance I don’t think that’s accelerated in ffmpeg today.
As an alternative to assembling the .bif files and inserting them where Plex expects, you could instead create a wrapper around the Plex Transcoder process, altering only the JPG extraction step.
@Volts i’ll share the script once it is in an ok state.
I am not sure on the jpeg encoding, I’ve never used ffmpeg before so I’m kinda guessing. I did try make it use the GPU encoding but it threw errors then i got a bit lost.
What do you mean by creating the wrapper? I thought the Plex Transcoder tool generates the jpg then somewhere in the plex server code it converts those jpgs into a bif?
I haven’t investigated how Plex turns the jpegs into a bif. I assume that’s correct.
If you replaced the Plex Transcoder binary with a script, you could detect when Plex is extracting jpegs, and modify the command as desired.
For all other activity, pass the commands to the original Plex Transcoder binary for processing as usual.
That way you wouldn’t have to deal with assembling jpegs into bif files, or storing them in the right place.
Check out that second link - @imax’s wrapper. When it recognizes that audio is being downmixed. (via the rematrix_maxval string), it modifies the call to the Plex Transcoder.
Thinking about this, I bet Plex doesn’t use hardware acceleration for VPT extraction on purpose.
Different hardware can support different numbers of concurrent transcodes, and Plex has a slot-based budgeting system in place for transcoding.
I bet it just didn’t make sense to add these into that same framework. These happen “fast enough”, and it would be bad for a real-time transcoding request to fail just because a thumbnail extraction was using hardware resources.
lol, well it is only tested on my machine, required u to build a docker image for the biftool, works only with nvidia cards… but i am sure someone can figure out how to get the rest of it working for their purposes.
That would add complexity - identifying HDR media, and determining which VPTs to reprocess.
I haven’t checked if the Plex Transcoder/ffmpeg options Plex uses for video tone-mapping would also work for VPT generation. It might also be simpler to stay in software.
Another thought - backup & restore of .bif files, adjacent to media files.
@Volts took 2-3 days to process but it seems it worked. Plex is now detecting intro’s tho, that might take another few days but not worth my time adding that to the script.
I’m not planning to do any more work on the script, it served what I need it for. Anyone else is welcome to take it and enhance it tho.
Looks like it would be easy to add the bif code for python vs using docker.