nicknsy / jellyscrub

Smooth mouse-over video scrubbing previews for Jellyfin.
MIT License
660 stars 25 forks source link

Create multiple file at same time #105

Closed Gauvino closed 2 months ago

Gauvino commented 1 year ago

Hello, do you think it's possible when hardware acceleration enables to encode multiple file at the same time to increase speed?

nicknsy commented 1 year ago

This was discussed in #77, but kura was unable to see any significant gain with multiple ffmpeg processes running in parallel on their Quadro card. Whether that's a limit of ffmpeg's implementation, mine, or if the overall usage reported did not accurately reflect the usage of encode/decode specifically is something I'm unsure of. For now, it looks to be something that would be difficult to implement for not much immediate value.

Gauvino commented 1 year ago

Oh ok no problem I should watch discussion before sorry

nicknsy commented 1 year ago

Oh ok no problem I should watch discussion before sorry

Don't worry about it. It was quite an old issue that had already been closed.

verbumfeit commented 5 months ago

Multiple ffmpeg processes do help with speed, at least on Intel HD integrated graphics:

With one ffmpeg process:

image

________________________________________________________
Executed in   80.68 secs    fish           external
   usr time   36.73 secs  441.00 micros   36.73 secs
   sys time   15.74 secs    0.00 micros   15.74 secs

With two ffmpeg processes:

image

process1
________________________________________________________
Executed in   89.73 secs    fish           external
   usr time   64.84 secs  596.00 micros   64.84 secs
   sys time   27.04 secs    0.00 micros   27.04 secs

process2
________________________________________________________
Executed in   90.83 secs    fish           external
   usr time   65.29 secs    0.00 micros   65.29 secs
   sys time   27.09 secs  717.00 micros   27.09 secs

Both executed with this command (copied from ps output): /usr/lib/jellyfin-ffmpeg/ffmpeg -loglevel error -init_hw_device vaapi=va:/dev/dri/renderD128,driver=iHD -filter_hw_device va -hwaccel vaapi -hwaccel_output_format vaapi -autorotate 0 -i "file:/mnt/nas/movie.mp4" -autoscale 0 -an -sn -vf fps=1/10,setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale_vaapi=w=320:h=180:format=nv12:extra_hw_frames=24,hwmap=mode=read,format=nv12 -threads 0 -c:v mjpeg -f image2 /tmp/img_%08d.jpg

It seems to me that the iGPU has two cores/threads and we only use one with our ffmpeg process. As we can see, the time per process takes a little bit longer (80 vs 90 seconds) when running two ffmpeg processes in parallel, probably because some other part of the GPU has a little more to do now, shifting things around.

Seeing as this basically doubles the speed, Jellyscrub could run with two ffmpeg processes as long as driver=iHD. Or the number of concurrent ffmpeg processes could/should be made configurable. With a hint that it may not increase speed when you're on a non-Intel HD graphics.

Bonus: The second process increases power usage only by 3W (according to intel_gpu_top).