Skip to main content

Jellyfin

Jellyfin เป็น Media Server ที่ถือว่าดีตัวหนึ่ง สามารถใช้ Hardware acceleration ลดภาระของ CPU ให้การ์ดจอ  encode หรือ decode ไฟล์ video แทนได้โดยไม่ต้องเสียเงินแบบ Plex แต่ปัญหาหนึ่งของ Jellyfin คือ ตั้งค่า Hardware acceleration ยากพอสมควร และเช็คยากด้วยว่าใช้อยู่หรือไม่ แต่ถ้าเปิดใช้ก็จะช่วยลดภาระในการแปลงไฟล์ลงไปเยอะ คือจากกิน CPU 60-70% เหลือ 18-30% บน DS918+

เท่าที่ลองหาวิธีเปิด Hardware acceleration ส่วนมากจะเป็นการให้สิทธ์ root กับ Jellyfin เพื่อให้เข้าถึงการ์ดจอใน NAS ได้ ซึ่งดูแล้วเหมือนจะให้สิทธ์เยอะเกินไปหน่อย ซึ่งวิธีที่ถูกต้องควรจะทำเหมือน Plex มากกว่าคือ ขอสิทธ์ใช้การ์ดจอเท่านั้นก็พอ ดังนั้นสิ่งที่ต้องทำก็จะย้อนรอย Plex นิดหน่อย (Plex ทำมาให้อัติโนมัติแล้ว) คือ

  1. สร้าง ID User ใหม่ใน DSM เป็นของ Jellyfin โดยเฉพาะ เพื่อใช้ใน Docker
  2. ให้สิทธ์ User Jellyfin ในการเข้าถึง folder ต่าง ๆ เพื่อดึง Media ของเรามาใช้
  3. ให้สิทธ์ User Jellyfin เข้าถึงการ์ดจอเพื่อใช้ในการทำ Hardware acceleration


วิธีสร้าง User ใหม่ให้รองรับ Hardware acceleration

สร้าง ID User ใหม่ใน DSM เป็นของ Jellyfin โดยเฉพาะ เพื่อใช้ใน Docker

คุณจะใช้ ID อื่นที่ใช้เชื่อมต่อ Docker อยู่แล้วก็ได้ ถ้าจะใช้ ID เดิม ข้ามไป ส่วน "ให้สิทธ์ User Jellyfin เข้าถึงการ์ดจอ" ได้เลย

ไปที่ Control Panel > User & Group > User > Create สร้าง user Jellyfin ขึ้นมาให้ แล้วอย่าลืมให้สิทธ์ read write folder docker และ folder media อื่น ๆ ของคุณด้วย ไม่งั้นเวลาเปิด media folder ที่ไม่มีสิทธิ์มันจะไม่เห็นไฟล์อะไรเลย

image.png


ให้สิทธ์ User Jellyfin เข้าถึงการ์ดจอเพื่อใช้ในการทำ Hardware acceleration

ส่วนนี้ต้องใช้ SSH ในการเข้าไปจัดการสิทธิ์ ถ้าไม่เป็น อ่านเพิ่มได้ที่ SSH พื้นฐานเพื่อเชื่อมต่อ NAS และการติดตั้งโปรแกรมผ่านวิธีต่าง ๆ

เมื่อเข้ามาใน SSH แล้ว ก่อนอื่นเราต้องหา UID ของ Jellyfin ก่อนเพื่อใช้เป็น user ใน Jellyfin ทำได้โดยใช้คำสั่ง

id Jellyfin


จด UID ไว้ให้เรียบร้อย หลังจากนั้นเช็คกลุ่มการ์ดจอดูว่าเลขเป็นอะไรเพื่อใช้เป็น GID  และมี user ไหนอยู่ในกลุ่มบ้างโดยพิมพ์

sudo synogroup -get videodriver

image.png

ถ้าขึ้นจอให้กรอกรหัสผ่านให้กรอกไปอีกรอบ ก็จะเห็นว่า Plex อยู่ในกลุ่มอยู่แล้วทีนี้มาทำ Jellyfin บ้าง

ถ้ามี user อื่นอยู่ในนั้น เช่น PlexMediaServer อย่าลืมพิมพ์ใส่กลับเข้าไปด้วย ไม่งั้นมันจะมีแค่ user เดียวที่เราพิมพ์เข้าไป

sudo synogroup --member videodriver PlexMediaServer Jellyfin

เสร็จเรียบร้อยในขั้นตอนสร้าง user ใหม่ให้รองรับ Hardware acceleration

ขั้นตอนติดตั้ง

จัดเตรียมไฟล์

save code ด้านล่างไปทำไฟล์ docker-compose.yaml

version: "3.5"
services:
  jellyfin:
    image: jellyfin/jellyfin
    container_name: jellyfin
    user: 1035:937    # <- PUID:PGID (videodriver group)
    ports:
      - 8096:8096
    volumes:
      - /volume1/docker/jellyfin/config:/config
      - /volume1/docker/jellyfin/cache:/cache
      - /volume1/docker/jellyfin/media:/media
    devices:
      # VAAPI Devices - Enable Transcode for QSV (less CPU) or VA API (Quality)
      - /dev/dri/renderD128:/dev/dri/renderD128
      - /dev/dri/card0:/dev/dri/card0
      - /dev/dri:/dev/dri
    restart: "unless-stopped"

ใช้ notepad หรืออะไรก็ได้เปิดไฟล์ docker-compose.yaml ขึ้นมา แล้วแก้ตรงส่วน PUID:PGID ให้เป็น user ที่เพิ่งสร้างหรือ user ที่มีสิทธิ์เข้าถึงการ์ดจอ ใส่ GID ให้ถูกต้องโดยใช้เลขกลุ่ม videodriver แก้ port ต้องกับความต้องการ แก้เสร็จหมดแล้วให้เซฟไฟล์


จัดเตรียม folder ติดตั้ง

ย้อนกลับไปดูไฟล์ docker-compose.yaml อีกครั้ง ในส่วนของ volume

    volumes:
      - /volume1/docker/jellyfin/config:/config
      - /volume1/docker/jellyfin/cache:/cache
      - /volume1/docker/jellyfin/media:/media

จะเห็นได้ว่าเราจะต้องมีการสร้าง 3 folder ย่อยใน docker หน้าตาก็จะได้ประมาณนี้

docker
│
└─── jellyfin
	│   docker-compose.yaml
    │
    └─── config
    │
    └─── cache
    │
    └─── media

media จะใช้นอก docker ก็ได้ ใส่ path ใน docker-compose.yaml ให้ถูกต้องพอ และต้องไม่ลืมว่า PUID ที่ใช้มีสิทธ์อ่านไฟล์นอก docker ด้วย


เข้าไปจัดการสร้าง folder ผ่าน File Station ใน DSM ให้เรียบร้อย

image.png


หลังจากนั้น copy ไฟล์ docker-compose.yml ที่ทำไว้แล้วไปใส่ไว้ใน paperless-ngx

SSH แล้วติดตั้งโปรแกรมตามขั้นตอนปกติ

cd /volume1/docker/jellyfin
docker-compose up -d

หาก error ในขั้นตอนไหนให้ดูแจ้ง error แก้ไขให้เรียบร้อยแล้ว docker-compose up -d อีกรอบติดตั้งต่อได้เลย

Source:
https://github.com/jellyfin/jellyfin
https://jellyfin.org/docs/general/quick-start.html
https://www.reddit.com/r/jellyfin/comments/phdz1a/need_help_setting_up_hardware_transcoding_in/


การใช้งาน Jellyfin

ตั้งค่า Hardware acceleration ก่อนใช้งาน

เริ่มจากใน Jellyfin ไปที่ Administration > Dashboard ดูในส่วน Server > Playback ดูตรง Hardware acceleration เลือกเป็น Intel Quick Sync หรือ VAAPI

อย่าลืมตั้ง Enable hardware decoding เพิ่มเติมเช่น H264 (อันนี้ก็ไม่รู้ว่า Jellyfin จะปิดไว้ทำไม) หรือ Throttle Transcodes

image.png

นอกนั้นให้ลองงม ๆ ดูตามสะดวก



วิธีเช็คว่า Jellyfin ใช้ Hardware acceleration หรือไม่

เริ่มจากใน Jellyfin ไปที่ Administration > Dashboard ดูในส่วน Advanced > Logs แล้วมองหา log ที่ขึ้นด้วย FFmgeg.Transcode

image.png

เปิดเข้าไปแล้วลงหาดูบรรทัดที่เริ่มด้วย /usr/lib/jellyfin-ffmpeg/ffmpeg ในนั้นจะมีบรรทัดประมาณว่า

-init_hw_device qsv=qs@va

สำหรับคนที่ใช้ Intel Quick Sync หรือ

-init_hw_device vaapi=va:/dev/dri/renderD128

สำหรับคนที่ใช้ VAAPI





Plex Jellyfin Sctucture

Movie - Inline
Plex Jellyfin
-trailer -trailer .trailer _trailer (space)trailer
-featurette -featurette
-behindthescenes -behindthescenes
-deleted -deleted
-interview -interview
-scene -scene
-short -short
-other

-clip

-sample .sample _sample (space)sample
Movies
 └─ Avatar (2009)
    ├─ Avatar (2009).mkv
    ├─ Arrival-scene.mp4
    ├─ Bar Fight-deleted.mp4
    ├─ Performance Capture-behindthescenes.mkv
    ├─ Sigourney Weaver-interview.mp4
    ├─ Stephen Lang-interview.mp4
    ├─ Teaser Trailer-trailer.mp4
    ├─ Theatrical Trailer #1-trailer.mp4
    └─ Theatrical Trailer #2-trailer.avi
Movies
└─ Best_Movie_Ever (2019)
   ├─ Best_Movie_Ever (2019) - 1080P.mp4
   ├─ That clip that I want everyone to see-clip.mp4
   ├─ Release Trailer-trailer.mp4
   ├─ Preview Trailer.trailer.avi
   ├─ Release Trailer 2_trailer.avi
   ├─ Teaser.sample.mp4
   ├─ Favorite Scene-scene.mp4
   ├─ The Best Ever-clip.mp4
   ├─ Making of The Best Movie Ever-behindthescenes.mp4
   ├─ Not the best scene-deleted.mp4
   ├─ Theme Song Music Video-featurette.mp4
   └─ Art of the Best Movie Ever-short.mp4
Movie - Subdirectories
Plex Jellyfin
Trailers Trailers
Featurettes Featurettes
Behind The Scenes Behind The Scenes
Deleted Scenes Deleted Scenes
Interviews Interviews
Scenes Scenes
Shorts Shorts
Other

Extras

Samples
Movies
└─ Avatar (2009)
   └─ Avatar (2009).mkv
      ├─ Behind The Scenes
      │  └─ Performance Capture.mkv
      │
      ├─ Deleted Scenes
      │  ├─ Bar Fight.mp4
      │  └─ Lost Sister.mkv
      │      
      ├─ Interviews
      │  ├─ Sigourney Weaver.mp4
      │  └─ Stephen Lang.mp4
      │      
      ├─ Scenes
      │  └─ Arrival.mp4
      │      
      └─ Trailers
         ├─ Teaser Trailer.mp4
         ├─ Theatrical Trailer #1.mp4
         └─ Theatrical Trailer #2.mp4
Movies
└─ Best_Movie_Ever (2019)
   ├─ Best_Movie_Ever (2019) - 1080P.mp4
   ├─ Best_Movie_Ever (2019) - 720P.mp4
   ├─ Best_Movie_Ever (2019) - Directors Cut.mp4
   │
   ├─ behind the scenes
   │  ├─ Making of the Best Movie Ever.mp4
   │  └─ Finding the right score.mp4
   │ 
   ├─ interviews
   │  └─ Interview with the Director.mp4
   │   
   └─ extras
      └─ Home recreation.mp4


Movie - Images


Subdirectories

Type
Plex Jellyfin
Poster

  • folder.ext
  • poster.ext
  • cover.ext
  • default.ext
  • movie.ext
Backdrop

  • backdrop.ext
  • fanart.ext
  • background.ext
  • art.ext
  • extrafanart/*.ext
Logo

  • logo.ext
  • clearlogo.ext