![]() |
Cloudflare Caching Rule and Worker for Jellyfin Video Transcoding – Configuration Rev - Printable Version +- Jellyfin Forum (https://forum.jellyfin.org) +-- Forum: Support (https://forum.jellyfin.org/f-support) +--- Forum: Troubleshooting (https://forum.jellyfin.org/f-troubleshooting) +---- Forum: Networking & Access (https://forum.jellyfin.org/f-networking-access) +---- Thread: Cloudflare Caching Rule and Worker for Jellyfin Video Transcoding – Configuration Rev (/t-cloudflare-caching-rule-and-worker-for-jellyfin-video-transcoding-%E2%80%93-configuration-rev) |
Cloudflare Caching Rule and Worker for Jellyfin Video Transcoding – Configuration Rev - Aksi - 2024-10-11 Hello everyone, I'm setting up a caching solution for Jellyfin video transcoding using Cloudflare, and I've come across some questions regarding the best practices for caching video transcoding with Cloudflare Workers. I noticed that the caching documentation for Jellyfin seems to have been removed or changed on the official site, so I’m seeking advice from the community. I’ve configured a Cloudflare Worker script to handle video caching for Jellyfin, specifically targeting requests to /videos/. The script normalizes the URL by removing various query parameters (e.g., api_key, DeviceId, PlaySessionId, etc.), and then attempts to fetch the requested resource from the cache. If not found, it fetches it from the origin server and caches the response. Here is the Cloudflare Worker code I’m using: Code: addEventListener('fetch', (event) => { Example Request Here's an example of a request that would be processed: Code: /videos/REDACTED/hls1/main/1.mp4?DeviceId=REDACTED&MediaSourceId=REDACTED&VideoCodec=av1,hevc,h264,hevc&AudioCodec=aac&AudioStreamIndex=2&VideoBitrate=59808000&AudioBitrate=192000&AudioSampleRate=44100&MaxFramerate=23.976025&PlaySessionId=REDACTED&api_key=REDACTED&TranscodingMaxAudioChannels=2&RequireAvc=false&Tag=REDACTED&SegmentContainer=mp4&MinSegments=2&BreakOnNonKeyFrames=True&hevc-level=153&hevc-videobitdepth=10&hevc-profile=main10&hevc-audiochannels=2&aac-profile=lc&av1-profile=main&av1-rangetype=SDR,HDR10,HLG&av1-level=19&hevc-rangetype=SDR,HDR10,HLG&hevc-deinterlace=true&h264-profile=high,main,baseline,constrainedbaseline,high10&h264-rangetype=SDR&h264-level=52&h264-deinterlace=true&TranscodeReasons=ContainerNotSupported,%REDACTED&runtimeTicks=75080000&actualSegmentLengthTicks=136800000 Questions 1. Is this configuration optimal for caching transcoded video streams from Jellyfin? Are there any parameters that should not be removed from the cache key? 2. Are there any specific considerations or settings I should apply for Cloudflare's cache rules to avoid issues with video playback or session handling? 3. Since the Jellyfin documentation regarding caching is no longer available, does anyone have updated best practices for caching video streams or transcoding results? RE: Cloudflare Caching Rule and Worker for Jellyfin Video Transcoding – Configuration Rev - TheDreadPirate - 2024-10-11 Caching of video is not really suggested for Jellyfin, which was why we removed the documentation for it. There is only one situation I can think of to justify video caching. 1) Your reverse proxy is located at a VPS/hosting service you rented/purchased 2) Your actual jellyfin server is located somewhere else from the proxy (your home?) 3) You use syncplay a lot with a lot of simultaneous watchers If all 3 are true, caching of video makes sense. And, in this setup, the caching would be on a host you likely own/control. HAVING SAID THAT, since you would be using CF's services, it is against Cloudflare's TOS to serve video on their free tier proxy/caching services. They have a separate service, NOT free, for serving/caching video. https://developers.cloudflare.com/support/more-dashboard-apps/cloudflare-stream/delivering-videos-with-cloudflare/ I know you are using CF Workers, but the same TOS applies. https://community.cloudflare.com/t/tos-for-workers-kv-hosted-content/228259 As such, we cannot assist with violating CF's TOS. https://forum.jellyfin.org/t-jellyfin-forum-rules Rule 2-7. Quote:Post information that may violate the ToS (Terms of Service) of other services; if a ToS is unclear, you should assume that it is against the ToS. RE: Cloudflare Caching Rule and Worker for Jellyfin Video Transcoding – Configuration Rev - Aksi - 2024-10-12 Thanks for the info! I'm only using a rented VPS and utilizing rclone from Google Drive. The caching is needed because sometimes rclone works slowly, and for 4K videos, the processing time can be long due to the weak CPU on my server. I understand now that caching may not be the best solution given the situation with Cloudflare’s TOS. I’ll keep it without caching for now but will adjust the transcoding Encoding preset to ultrafast, as it helps to play the video without throttling. Thanks again for the clarification! |