Sau khi cài đặt Plex lên máy ảo LXC (Linux Container), mình nghiên cứu tiếp đến cách cấu hình Hardware Transcoding cho Plex để giảm tải cho CPU máy chủ.
Mặc định, Plex sẽ sử dụng tài nguyên CPU cho tác vụ chuyển mã (Transcode) phim mỗi khi thiết bị phát không hỗ trợ mở trực tiếp (Direct Play) từ server. Việc này sẽ gây ảnh hưởng đến hiệu năng hoạt động của các máy ảo khác trong cùng hệ thống.
Nếu máy tính được trang bị GPU rời hay iGPU (đồ hoạ tích hợp trên CPU Intel), chúng ta có thể cấu hình cho Plex sử dụng tính năng Hardware Acceleration để transcode phim bằng card màn hình để giảm tải cho CPU.
Trong bài viết này, mình sẽ hướng dẫn cách cấu hình cho phép LXC Container sử dụng iGPU tích hợp trên CPU Intel để Plex tận dụng tính năng Quick Sync cho việc transcode phim.
Yêu cầu chuẩn bị
- Máy chủ trang bị CPU Intel đời Sandy Bridge (2011) trở về sau.
- Máy ảo LXC Container đã được cài đặt sẵn Plex Media Server.
- Tài khoản Plex Pass: để có thể sử dụng tính năng Hardward Transcoding trên Plex
Điều chỉnh thông số LXC
Mặc định Proxmox không cho phép LXC Container truy cập vào GPU của hệ thống. Chúng ta có thể kiểm tra bằng cách sử dụng lệnh vainfo
Cài đặt vainfo trong LXC
sudo apt install vainfoGõ lệnh vainfo, hệ thống sẽ phản hồi lỗi error như dưới đây
root@plex:~# vainfoerror: can't connect to X server!error: failed to initialize displayTrong khi đó, nếu chạy lệnh vainfo trực tiếp trên Proxmox host, kết quả trả về như sau
root@proxmox:~# vainfoerror: can't connect to X server!libva info: VA-API version 1.10.0libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.solibva info: va_openDriver() returns -1libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.solibva info: Found init function __vaDriverInit_1_8libva info: va_openDriver() returns 0vainfo: VA-API version: 1.10 (libva 2.10.0)vainfo: Driver version: Intel i965 driver for Intel(R) Skylake - 2.4.1vainfo: Supported profile and entrypoints VAProfileMPEG2Simple : VAEntrypointVLD VAProfileMPEG2Simple : VAEntrypointEncSlice VAProfileMPEG2Main : VAEntrypointVLD VAProfileMPEG2Main : VAEntrypointEncSlice VAProfileH264ConstrainedBaseline: VAEntrypointVLD VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP VAProfileH264ConstrainedBaseline: VAEntrypointFEI VAProfileH264ConstrainedBaseline: VAEntrypointStats VAProfileH264Main : VAEntrypointVLD VAProfileH264Main : VAEntrypointEncSlice VAProfileH264Main : VAEntrypointEncSliceLP VAProfileH264Main : VAEntrypointFEI VAProfileH264Main : VAEntrypointStats VAProfileH264High : VAEntrypointVLD VAProfileH264High : VAEntrypointEncSlice VAProfileH264High : VAEntrypointEncSliceLP VAProfileH264High : VAEntrypointFEI VAProfileH264High : VAEntrypointStats VAProfileH264MultiviewHigh : VAEntrypointVLD VAProfileH264StereoHigh : VAEntrypointVLD VAProfileVC1Simple : VAEntrypointVLD VAProfileVC1Main : VAEntrypointVLD VAProfileVC1Advanced : VAEntrypointVLD VAProfileJPEGBaseline : VAEntrypointVLD VAProfileJPEGBaseline : VAEntrypointEncPicture VAProfileVP8Version0_3 : VAEntrypointVLD VAProfileHEVCMain : VAEntrypointVLDĐể LXC có quyền truy cập vào iGPU, mình sẽ chỉnh sửa lại file cấu hình của LXC
Truy cập vào Terminal của Proxmox host và gõ lệnh sau
nano /etc/pve/lxc/<container id>.confBạn cần thay thế
Nội dung của file sẽ tương tự như sau
arch: amd64cmode: shellcores: 1features: nesting=1hostname: plexmemory: 1024net0: name=eth0,bridge=vmbr0,firewall=1,gw=192.168.0.1,hwaddr=E2:63:4F:3F:04:AC,ip=192.168.0.60/24,type=vethonboot: 1ostype: ubunturootfs: local-lvm:vm-103-disk-0,size=8Gswap: 1024unprivileged: 1Thay thế thông số unprivileged từ 1 thành 0
Thêm các dòng sau vào dưới cùng
Áp dụng cho Proxmox 7.0 về sau
lxc.cgroup2.devices.allow: c 226:0 rwmlxc.cgroup2.devices.allow: c 226:128 rwmlxc.cgroup2.devices.allow: c 29:0 rwmlxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dirlxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=fileÁp dụng cho Proxmox 6.4 hoặc cũ hơn
lxc.cgroup.devices.allow: c 226:0 rwmlxc.cgroup.devices.allow: c 226:128 rwmlxc.cgroup.devices.allow: c 29:0 rwmlxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dirlxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=fileToàn bộ nội dung sau khi chỉnh sửa sẽ như sau
arch: amd64cmode: shellcores: 1features: nesting=1hostname: plexmemory: 1024net0: name=eth0,bridge=vmbr0,firewall=1,gw=192.168.0.1,hwaddr=E2:63:4F:3F:04:AC,ip=192.168.0.60/24,type=vethonboot: 1ostype: ubunturootfs: local-lvm:vm-103-disk-0,size=8Gswap: 1024unprivileged: 0lxc.cgroup2.devices.allow: c 226:0 rwmlxc.cgroup2.devices.allow: c 226:128 rwmlxc.cgroup2.devices.allow: c 29:0 rwmlxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dirlxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=fileLưu lại và thoát ra.
Tiếp theo, mình sẽ truy cập vào LXC Container để tắt nó đi. Sau đó khởi động lại để các thay đổi cấu hình vừa chỉnh ở trên được áp dụng.
Tắt LXC Container (gõ trong Terminal của LXC)
sudo shutdown nowMở LXC Container (gõ trong Terminal của Proxmox)
pct start 103Trong đó 103 là id của LXC Container. Hoặc bạn có thể sử dụng giao diện Web UI của Proxmox để khởi động LXC.
Kiểm tra LXC có truy cập GPU chưa?
Sau khi LXC Container khởi động lại, mình sẽ truy cập vào Terminal của nó và kiểm tra lại lệnh vainfo
root@plex:~# vainfoerror: can't connect to X server!libva info: VA-API version 1.7.0libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.solibva info: Found init function __vaDriverInit_1_7libva info: va_openDriver() returns 0vainfo: VA-API version: 1.7 (libva 2.6.0)vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 20.1.1 ()vainfo: Supported profile and entrypoints VAProfileMPEG2Simple : VAEntrypointVLD VAProfileMPEG2Main : VAEntrypointVLD VAProfileH264Main : VAEntrypointVLD VAProfileH264Main : VAEntrypointEncSliceLP VAProfileH264High : VAEntrypointVLD VAProfileH264High : VAEntrypointEncSliceLP VAProfileJPEGBaseline : VAEntrypointVLD VAProfileJPEGBaseline : VAEntrypointEncPicture VAProfileH264ConstrainedBaseline: VAEntrypointVLD VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP VAProfileVP8Version0_3 : VAEntrypointVLD VAProfileHEVCMain : VAEntrypointVLDKết quả trả về giờ đã hiển thị các thông tin liên quan đến Intel iHD driver, cho thấy LXC đã có quyền truy cập vào GPU tích hợp trên CPU Intel để sử dụng tính năng Quick Sync khi Transcode.
Cấu hình Transcoder trên Plex
Truy cập vào phần cấu hình trên Plex: Plex —> Settings —> Transcoder và bấm chọn hai mục [x] Use hardware acceleration when available và [x] Use hardware-accelerated video encoding

Bấm Save Changes để lưu lại.
Lưu ý: 2 mục này chỉ xuất hiện nếu bạn đang sử dùng tài khoản Plex Pass trả phí. Còn sử dụng Plex miễn phí thì sẽ không thể kích hoạt tính năng Hardward Transcoding.
Kiểm tra Transcoder có sử dụng iGPU?
Để kiểm tra xem Plex có tận dụng tính năng Quick Sync trên Intel GPU cho tác vụ Transcoder không, mình sẽ mở 1 phim trên iPhone và truy cập vào mục Playback Settings → Quality → Chọn Convert to 1080p HD (High) để ép Plex thực hiện Transcoding thay vì Streaming trực tiếp.
Truy cập vào Plex Dashboard, nếu thấy xuất hiện chữ Transcode (hw) ở dòng Video nghĩa là Plex đang sử dụng tính năng Quick Sync của iGPU để chuyển mã phim

Kiểm tra CPU trên Proxmox, sẽ thấy CPU chạy nhẹ nhàng, không bị full load 90-100% như trước khi cấu hình chuyển mã bằng iGPU.

Vậy là yên tâm xem phim thoải mái. Không lo Proxmox bị sập vì CPU quá tải.
Chúc bạn thực hiện thành công!