Hardware Transcoding Issue

I know, I know, there are a ton of issues about hardware transcoding not working correctly, but I haven't been able to resolve my issue even after working through all of them I could find.

Log is below. I have a hardware transcoding option in the settings, but can't seem to get it to actually work. Software transcoding works no problem.

2020/01/30 13:05:40 [ENC] Encoder stopped for College Football Big Ten Championship Ohio State vs Wisconsin 2019-12-07-2000.mpg in /DVR/Streaming/file719-ip127.0.0.1/encoder-0-903273940 after starting from 0 without encoding any segments
2020/01/30 13:05:40 [ENC] Starting encoder for College Football Big Ten Championship Ohio State vs Wisconsin 2019-12-07-2000.mpg in /DVR/Streaming/file719-ip127.0.0.1/encoder-0-047441187 at 0 (0.000000) (encoder=h264_vaapi, resolution=720, deinterlacer=blend, bitrate=9488 segment_size=1)
[AVHWDeviceContext @ 0x2ae2e80] No VA display found for device /dev/dri/card0.
Device creation failed: -22.
Failed to set value 'vaapi=intel:/dev/dri/card0' for option 'init_hw_device': Invalid argument
Error parsing global options: Invalid argument
2020/01/30 13:05:40 [ENC] Encoder stopped for College Football Big Ten Championship Ohio State vs Wisconsin 2019-12-07-2000.mpg in /DVR/Streaming/file719-ip127.0.0.1/encoder-0-047441187 after starting from 0 without encoding any segments
2020/01/30 13:05:40 [ENC] Starting encoder for College Football Big Ten Championship Ohio State vs Wisconsin 2019-12-07-2000.mpg in /DVR/Streaming/file719-ip127.0.0.1/encoder-0-621491750 at 0 (0.000000) (encoder=h264_vaapi, resolution=720, deinterlacer=blend, bitrate=9488 segment_size=1)
[AVHWDeviceContext @ 0x26efe80] No VA display found for device /dev/dri/card0.
Device creation failed: -22.
Failed to set value 'vaapi=intel:/dev/dri/card0' for option 'init_hw_device': Invalid argument
Error parsing global options: Invalid argument

Not sure what else to provide, please let me know.

What does the OS/CPU section of the DVR settings page show? What distribution on linux are you running?

It sounds like your kernel is too old, and /dev/dri/renderD128 doesn't exist.

OS: Gigabyte Technology B365M DS3H Linux Ubuntu *19.10 (kernel: 5.3.0-29-generic)*

CPU: 8 cores / Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz

ls /dev/dri
by-path  card0  card1  renderD128  renderD129

Can you run the HWE test as described on the FAQ thread in the forum

Here is what I'm getting.

2020/01/30 17:12:49 [HWE] Cannot access /dev/dri/renderD129: permission denied
2020/01/30 17:12:49 [HWE] Cannot access /dev/dri/renderD128: permission denied
2020/01/30 17:12:49 [HWE] Cannot access /dev/renderD128: no such file or directory
2020/01/30 17:12:49 [HWE] Cannot access /dev/dri/card0: permission denied

The user is part of the video group, I just double checked.

What does this show:

ls -alh /dev/dri

and this as the user you're running the dvr with:

id

Here is the output from that command.

drwxr-xr-x   2 root root        120 Jan 29 20:11 by-path
crw-rw----+  1 root render 226,   0 Jan 30 12:55 card0
crw-rw----+  1 root render 226,   1 Jan 30 12:55 card1
crw-rw----+  1 root render 226, 128 Jan 30 12:55 renderD128
crw-rw----+  1 root render 226, 129 Jan 30 12:55 renderD129

And I'm running the channels dvr under a channels user that I created.

➜  dri id channels
uid=111(channels) gid=118(channels) groups=118(channels),44(video)

And the systemd file to show that it is running it as the correct user.

➜  dri cat /etc/systemd/system/channels-dvr.service 
[Unit]
Description=Channels DVR
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=channels
Group=channels
WorkingDirectory=/srv/channels-dvr/data
ExecStart=/bin/sh -c 'exec /srv/channels-dvr/latest/channels-dvr >> /srv/channels-dvr/data/channels-dvr.log 2>&1'
Restart=always
RestartSec=10
LimitNOFILE=8192
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

Adding the channels user to the render group did change the output I'm getting to.

2020/01/30 17:30:02 [HWE] Trying /srv/channels-dvr/2019.12.05.0128/ffmpeg /srv/channels-dvr/2019.12.05.0128/ffmpeg -hide_banner -nostats -loglevel warning -loglevel verbose -init_hw_device vaapi=intel:/dev/dri/renderD129 -f lavfi -t 0.1 -i color=black:640x480 -f null -y /dev/null
[AVHWDeviceContext @ 0x2da1dc0] libva: VA-API version 1.5.0
[AVHWDeviceContext @ 0x2da1dc0] libva: va_getDriverName() returns 0
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [22]
param: 4, val: 0
[AVHWDeviceContext @ 0x2da1dc0] libva: driver init failed
[AVHWDeviceContext @ 0x2da1dc0] libva: va_openDriver() returns -1
[AVHWDeviceContext @ 0x2da1dc0] Failed to initialise VAAPI connection: -1 (unknown libva error).
Device creation failed: -5.
Failed to set value 'vaapi=intel:/dev/dri/renderD129' for option 'init_hw_device': Input/output error
Error parsing global options: Input/output error
2020/01/30 17:30:02 [HWE] Failure: exit status 1
2020/01/30 17:30:02 [HWE] Trying /srv/channels-dvr/2019.12.05.0128/ffmpeg /srv/channels-dvr/2019.12.05.0128/ffmpeg -hide_banner -nostats -loglevel warning -loglevel verbose -init_hw_device vaapi=intel:/dev/dri/renderD128 -f lavfi -t 0.1 -i color=black:640x480 -f null -y /dev/null
[AVHWDeviceContext @ 0x300adc0] libva: VA-API version 1.5.0
[AVHWDeviceContext @ 0x300adc0] libva: va_getDriverName() returns 0
[AVHWDeviceContext @ 0x300adc0] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x300adc0] Initialised VAAPI connection: version 1.5
[AVHWDeviceContext @ 0x300adc0] VAAPI driver: Intel i965 driver for Intel(R) Coffee Lake - 2.4.0.pre1 (2.4.0.pre1).
[AVHWDeviceContext @ 0x300adc0] Driver not found in known nonstandard list, using standard behaviour.
[Parsed_color_0 @ 0x301b140] size:640x480 rate:25/1 duration:-1.000000 sar:1/1
Input #0, lavfi, from 'color=black:640x480':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo, 1 reference frame (I420 / 0x30323449), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 0x3047f80] w:640 h:480 pixfmt:yuv420p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2
Output #0, null, to '/dev/null':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: wrapped_avframe, 1 reference frame, yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 wrapped_avframe
No more output streams to write to, finishing.
frame=    3 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.12 bitrate=N/A speed=98.6x    
video:2kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (color=black:640x480):
  Input stream #0:0 (video): 4 packets read (1843200 bytes); 4 frames decoded; 
  Total: 4 packets (1843200 bytes) demuxed
Output file #0 (/dev/null):
  Output stream #0:0 (video): 3 frames encoded; 3 packets muxed (1608 bytes); 
  Total: 3 packets (1608 bytes) muxed
2020/01/30 17:30:02 [HWE] Trying /srv/channels-dvr/2019.12.05.0128/ffmpeg /srv/channels-dvr/2019.12.05.0128/ffmpeg -hide_banner -nostats -loglevel warning -loglevel verbose -init_hw_device vaapi=intel:/dev/dri/renderD128 -f lavfi -t 0.1 -i color=black:640x480 -filter_hw_device intel -vf format=nv12,hwupload,deinterlace_vaapi -f null -y /dev/null
[AVHWDeviceContext @ 0x24e6dc0] libva: VA-API version 1.5.0
[AVHWDeviceContext @ 0x24e6dc0] libva: va_getDriverName() returns 0
[AVHWDeviceContext @ 0x24e6dc0] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x24e6dc0] Initialised VAAPI connection: version 1.5
[AVHWDeviceContext @ 0x24e6dc0] VAAPI driver: Intel i965 driver for Intel(R) Coffee Lake - 2.4.0.pre1 (2.4.0.pre1).
[AVHWDeviceContext @ 0x24e6dc0] Driver not found in known nonstandard list, using standard behaviour.
[Parsed_color_0 @ 0x24f7100] size:640x480 rate:25/1 duration:-1.000000 sar:1/1
Input #0, lavfi, from 'color=black:640x480':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo, 1 reference frame (I420 / 0x30323449), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> wrapped_avframe (native))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 0x2525380] w:640 h:480 pixfmt:yuv420p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2
[auto_scaler_0 @ 0x2528f80] w:iw h:ih flags:'bicubic' interl:0
[trim_in_0_0 @ 0x2526100] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 0:0' and the filter 'trim_in_0_0'
[auto_scaler_0 @ 0x2528f80] w:640 h:480 fmt:yuv420p sar:1/1 -> w:640 h:480 fmt:nv12 sar:1/1 flags:0x4
[Parsed_deinterlace_vaapi_2 @ 0x25247c0] Picking 4 (MotionCompensated) as default deinterlacing mode.
Output #0, null, to '/dev/null':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: wrapped_avframe, 1 reference frame, vaapi_vld, 640x480 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 wrapped_avframe
No more output streams to write to, finishing.
frame=    2 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.12 bitrate=N/A speed=39.4x    
video:1kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (color=black:640x480):
  Input stream #0:0 (video): 4 packets read (1843200 bytes); 4 frames decoded; 
  Total: 4 packets (1843200 bytes) demuxed
Output file #0 (/dev/null):
  Output stream #0:0 (video): 2 frames encoded; 2 packets muxed (1072 bytes); 
  Total: 2 packets (1072 bytes) muxed
2020/01/30 17:30:06 [IDX] Pruned 281 expired airings from USA-OTA46278 in 24.544644ms.

Which appears to have also made the hardware transcoding start working. Not sure if Canonical changed something in the Ubuntu configuration, but it appears that it is using render instead of video now for the group that is needed.

1 Like

Wonder if it's tied in with the change of Intel's drivers. They have changed the VAAPI drivers, and while there is overlap, newer chipsets are supposed to use a different driver.

(The specifics escape me at the moment, but one set of drivers was for Sandy Bridge and later, and the new drivers are for Broadwell and newer. I do remember that on my distro for my laptop when I installed the drivers I had to manually set an environment variable to get VAAPI working because it defaulted to the older driver; this was with a Kaby Lake Refresh on Arch.)

Yes new distro versions appear to be doing this. I have updated our docs to match.

1 Like

Would this have any impact on getting hardware transcoding working in this scenario?

No, this is a permissions issue specific to Linux. Linux hardware transcoding works on all Intel hardware without problem, whereas some versions of Windows seem to have issues when combined with some types of hardware.