Hardware acceleration on Pi in docker?

Hi, I'm successfully running my server in docker on my Pi4 - but noting that hardware transcoding is disabled. I'm mapping --device /dev/dri:/dev/dri --device /dev/vchiq:/dev/vchiq through to the container, the latter is what I believe is the device for access to the graphics hardware, but this does not seem to work. Any hints on how to get hardware acceleration going on transcoding?

It uses /dev/video*

Thanks, I've mapped them all through to the container - but channels is still not giving me the option to choose hardware for transcoding. Is there something specific the channels app is looking for to identify that hardware is available?

You can run a HWE test and see where it is failing. See the FAQ: Channels Support - Subscription FAQ

1 Like

Returns 'true', but no new entries are added to the log. I can see in the channels-dvr-http.log that the request is receive and returns 200; but nothing added to the log.

Are you using an arm64 image? Can you submit diagnostics from the DVR instance

Running the arm7 image you uploaded it to docker hub a few days ago. Just submitted diags: 0bfed89b-0744-4868-b053-dcbc979f5709 .

The container would need to have /opt/vc/lib/libopenmaxil.so. Maybe you can bind mount it into the container.

Personally I would run 64-bit OS and containers on PI4

OK, re-imaged to the Raspberry PI 64-bit Buster Beta and got everything back up using the arm64 channels-dvr image. Once I mapped all the video devices in, hardware encoding was enabled!!

Only issue now is transcoding via the browser is just suck with a spinning circle and no image. Forcing the check via curl shows '2021/10/27 22:11:34.002967 [HWE] Successfully encoded using v4l2m2m'. so looks promising, but something still not quite right. Will continue tomorrow.

So a little more troubleshooting:

Hardware transcoding is not working either using the Channels app (away from home) nor using "watch now" in the web browser (tried Safari & Chrome on Mac, Edge on Windows - same screen with spinning circle) EXCEPT when using Safari on my iPhone, in only this case it will work. Looking in the container, 1 or 2 ffmpeg processes are launched each time I attempt, so it is trying to transcode.

Tried changing the transcoding settings, including adaptive streaming on/off - no change. Going to Software works, but of course kills the CPU.

Any suggestions?

New diagnostics at 32ff6137-9315-409b-8b95-3d841f1710b4 if that helps.

Does it work with the official USB image we provide?

At first I had similar behavior with the official image with it not starting the stream for many shows/channels, but I did note on the official image it sometimes did work for some shows/channels. Booting back to my image and trying a wider set of channels from the guide, I also see that sometimes I can get it to work for certain stations - mostly SD stations and a few HD stations; not all the time with the HD, but sometimes. So similar between the official and docker - both unable to transcode and stream for most all HD stations, but both working for a few and for most SD stations.

More testing: Similar situation using channels iOS app remotely - transcoding will often 50%+ work on SD content, but never works on HD content. The following log entries show after a few minutes trying to stream HD if this helps:

52.634778 [ENC] Starting encoder for ch7.1 in /shares/DVR/Streaming/ch7.1-dANY-720b551dbd45-2708236864/encoder-65-2692234863 at 65 (111.901400) (encoder=h264_v4l2m2m, resolution=720, deinterlacer=blend, bitrate=4300 segment_size=0.01)
2021/10/29 09:30:52.782143 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: output VIDIOC_REQBUFS failed: Invalid argument
2021/10/29 09:30:52.782365 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: no v4l2 output context's buffers
2021/10/29 09:30:52.782420 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [Parsed_scale_v4l2m2m_1 @ 0x31c44240] can't configure encoder
2021/10/29 09:30:52.782463 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [Parsed_scale_v4l2m2m_1 @ 0x31c44240] Failed to configure output pad on Parsed_scale_v4l2m2m_1
2021/10/29 09:30:52.782986 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Error reinitializing filters!
2021/10/29 09:30:52.783151 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Failed to inject frame into filter network: Inappropriate ioctl for device
2021/10/29 09:30:52.783273 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Error while processing the decoded data for stream #0:0
2021/10/29 09:30:52.784454 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [aac @ 0x31bb4630] 2 frames left in the queue on closing
2021/10/29 09:30:52.784785 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [aac @ 0x31bb0dd0] 2 frames left in the queue on closing
2021/10/29 09:30:52.943903 [ENC] Encoder stopped for ch7.1 in /shares/DVR/Streaming/ch7.1-dANY-720b551dbd45-2708236864/encoder-65-2692234863 after starting from 65 without encoding any segments
2021/10/29 09:30:52.949545 [ENC] Starting encoder for ch7.1 in /shares/DVR/Streaming/ch7.1-dANY-720b551dbd45-2708236864/encoder-65-4226007625 at 65 (111.901400) (encoder=h264_v4l2m2m, resolution=720, deinterlacer=blend, bitrate=4300 segment_size=0.01)
2021/10/29 09:30:53.170695 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: output VIDIOC_REQBUFS failed: Invalid argument
2021/10/29 09:30:53.170806 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: no v4l2 output context's buffers
2021/10/29 09:30:53.170827 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [Parsed_scale_v4l2m2m_1 @ 0x37379240] can't configure encoder
2021/10/29 09:30:53.170847 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [Parsed_scale_v4l2m2m_1 @ 0x37379240] Failed to configure output pad on Parsed_scale_v4l2m2m_1
2021/10/29 09:30:53.171546 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Error reinitializing filters!
2021/10/29 09:30:53.171641 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Failed to inject frame into filter network: Inappropriate ioctl for device
2021/10/29 09:30:53.171660 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Error while processing the decoded data for stream #0:0
2021/10/29 09:30:53.172573 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [aac @ 0x372e9630] 2 frames left in the queue on closing
2021/10/29 09:30:53.172802 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-64-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [aac @ 0x372e5dd0] 2 frames left in the queue on closing
2021/10/29 09:30:53.347442 [ENC] Encoder stopped for ch7.1 in /shares/DVR/Streaming/ch7.1-dANY-720b551dbd45-2708236864/encoder-65-4226007625 after starting from 65 without encoding any segments. Marked segment as failed.
2021/10/29 09:30:54.634764 [ENC] Starting encoder for ch7.1 in /shares/DVR/Streaming/ch7.1-dANY-720b551dbd45-2708236864/encoder-66-546257514 at 66 (113.903400) (encoder=h264_v4l2m2m, resolution=720, deinterlacer=blend, bitrate=4300 segment_size=0.01)
2021/10/29 09:30:54.909538 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: output VIDIOC_REQBUFS failed: Invalid argument
2021/10/29 09:30:54.909655 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: no v4l2 output context's buffers
2021/10/29 09:30:54.909886 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [Parsed_scale_v4l2m2m_1 @ 0x354b79f0] can't configure encoder
2021/10/29 09:30:54.910006 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [Parsed_scale_v4l2m2m_1 @ 0x354b79f0] Failed to configure output pad on Parsed_scale_v4l2m2m_1
2021/10/29 09:30:54.911019 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Error reinitializing filters!
2021/10/29 09:30:54.911151 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Failed to inject frame into filter network: Inappropriate ioctl for device
2021/10/29 09:30:54.911170 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: Error while processing the decoded data for stream #0:0
2021/10/29 09:30:54.912388 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [aac @ 0x35407fd0] 2 frames left in the queue on closing
2021/10/29 09:30:54.912755 [HLS] ffmpeg: ch7.1-dANY-720b551dbd45-65-h264-aac-copy--4300-192-720-0-0--blend-false-false-0.01: [aac @ 0x35525530] 2 frames left in the queue on closing

Pretty certain I narrowed it down to HD content - the problem occurs regardless of running inside or outside container when ffmpeg is creating buffers. The only notable difference in two traces seems to be the size of the video stream - could this be something related to GPU memory?

straces of ffmpeg on an HD (fail) and SD (success) shows:

  1. ioctl(5, VIDIOC_S_FMT, {type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, fmt.pix_mp={width=1920, height=1080, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') /* V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=V4L2_COLORSPACE_REC709, plane_fmt=[{sizeimage=1536, bytesperline=32}], num_planes=1} => fmt.pix_mp={width=1920, height=1080, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') / V4L2_PIX_FMT_YUV420 */, field=V4L2_FIELD_NONE, colorspace=V4L2_COLORSPACE_REC709, plane_fmt=[{sizeimage=3110400, bytesperline=1920}], num_planes=1}}) = 0

  2. ioctl(5, VIDIOC_S_FMT, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, fmt.pix_mp={width=1920, height=1080, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') /* V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=0 / V4L2_COLORSPACE_??? /, plane_fmt=[{sizeimage=1536, bytesperline=32}], num_planes=1} => fmt.pix_mp={width=1920, height=1080, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') / V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=0 / V4L2_COLORSPACE_??? */, plane_fmt=[{sizeimage=3110400, bytesperline=1920}], num_planes=1}}) = 0

  3. ioctl(5, VIDIOC_G_FMT, {type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, fmt.pix_mp={width=1920, height=1080, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') /* V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=0 / V4L2_COLORSPACE_??? */, plane_fmt=[{sizeimage=3110400, bytesperline=1920}], num_planes=1}}) = 0

  4. ioctl(5, VIDIOC_REQBUFS, {type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, memory=V4L2_MEMORY_MMAP, count=6}) = -1 EINVAL (Invalid argument)

Similar section from SD content:

  1. ioctl(5, VIDIOC_S_FMT, {type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, fmt.pix_mp={width=704, height=480, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') /* V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=V4L2_COLORSPACE_REC709, plane_fmt=[{sizeimage=1536, bytesperline=32}], num_planes=1} => fmt.pix_mp={width=704, height=480, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') / V4L2_PIX_FMT_YUV420 */, field=V4L2_FIELD_NONE, colorspace=V4L2_COLORSPACE_REC709, plane_fmt=[{sizeimage=506880, bytesperline=704}], num_planes=1}}) = 0

  2. ioctl(5, VIDIOC_S_FMT, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, fmt.pix_mp={width=704, height=480, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') /* V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=0 / V4L2_COLORSPACE_??? /, plane_fmt=[{sizeimage=1536, bytesperline=32}], num_planes=1} => fmt.pix_mp={width=704, height=480, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') / V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=0 / V4L2_COLORSPACE_??? */, plane_fmt=[{sizeimage=506880, bytesperline=704}], num_planes=1}}) = 0

  3. ioctl(5, VIDIOC_G_FMT, {type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, fmt.pix_mp={width=704, height=480, pixelformat=v4l2_fourcc('Y', 'U', '1', '2') /* V4L2_PIX_FMT_YUV420 /, field=V4L2_FIELD_NONE, colorspace=0 / V4L2_COLORSPACE_??? */, plane_fmt=[{sizeimage=506880, bytesperline=704}], num_planes=1}}) = 0

  4. ioctl(5, VIDIOC_REQBUFS, {type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, memory=V4L2_MEMORY_MMAP, count=6 => 6}) = 0

dmesg might show some more errors from the bcm codec

What kernel are you running? You may need to rpi-update

Been there, done that :wink:

Linux luxray 5.10.76-v8+ #1474 SMP PREEMPT Thu Oct 28 13:44:16 BST 2021 aarch64 GNU/Linux

Not much in dmesg:

0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 video=HDMI-A-1:3840x2160M@30,margin_left=48,margin_right=48,margin_top=48,margin_bottom=48 smsc95xx.macaddr=DC:A6:32:DB:C1:7E vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  console=ttyS0,115200 console=tty1 root=PARTUUID=6c67300f-02 rootfstype=ext4 elevator=deadline fsck.repair=yes cma=512M rootwait quiet splash plymouth.ignore-serial-consoles

[ 0.116290] bcm2835-mbox fe00b880.mailbox: mailbox enabled
[ 0.163085] bcm2835-dma fe007000.dma: DMA legacy API manager, dmachans=0x1
[ 1.352252] gpiomem-bcm2835 fe200000.gpiomem: Initialised: Registers at 0xfe200000
[ 1.500253] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer
[ 1.504229] mmc-bcm2835 fe300000.mmcnr: could not get clk, deferring probe
[ 1.536804] bcm2835-power bcm2835-power: Broadcom BCM2835 power domains driver
[ 1.537739] mmc-bcm2835 fe300000.mmcnr: mmc_debug:0 mmc_debug2:0
[ 1.537754] mmc-bcm2835 fe300000.mmcnr: DMA channel allocated
[ 4.312015] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.340619] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[ 4.368077] bcm2835_audio bcm2835_audio: card created with 8 channels
[ 4.553845] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.554369] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.614411] bcm2835_isp: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.619820] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.623469] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.675172] bcm2835-isp bcm2835-isp: Device node output[0] registered as /dev/video13
[ 4.675663] bcm2835-isp bcm2835-isp: Device node capture[0] registered as /dev/video14
[ 4.675764] bcm2835-codec bcm2835-codec: Device registered as /dev/video10
[ 4.675805] bcm2835-codec bcm2835-codec: Loaded V4L2 decode
[ 4.676342] bcm2835-isp bcm2835-isp: Device node capture[1] registered as /dev/video15
[ 4.676708] bcm2835-isp bcm2835-isp: Device node stats[2] registered as /dev/video16
[ 4.676739] bcm2835-isp bcm2835-isp: Register output node 0 with media controller
[ 4.676759] bcm2835-isp bcm2835-isp: Register capture node 1 with media controller
[ 4.676777] bcm2835-isp bcm2835-isp: Register capture node 2 with media controller
[ 4.676794] bcm2835-isp bcm2835-isp: Register capture node 3 with media controller
[ 4.677018] bcm2835-isp bcm2835-isp: Loaded V4L2 bcm2835-isp
[ 4.685652] bcm2835-codec bcm2835-codec: Device registered as /dev/video11
[ 4.685701] bcm2835-codec bcm2835-codec: Loaded V4L2 encode
[ 4.703756] bcm2835-codec bcm2835-codec: Device registered as /dev/video12
[ 4.703803] bcm2835-codec bcm2835-codec: Loaded V4L2 isp
[ 4.720434] bcm2835-codec bcm2835-codec: Device registered as /dev/video18
[ 4.720492] bcm2835-codec bcm2835-codec: Loaded V4L2 image_fx

Strange.

I wonder if 6 is too many buffers for HD sized images?

If you're running ffmpeg manually to test, you can try adding -num_capture_buffers 3 -num_output_buffers 3 to see if there's any difference.

No, not testing manually - replaced ffmpeg with a shell script that wrapped it with strace. Just tried that forcing the buffers to three, but get other errors as I don't think that those are valid arguments for some ffmpeg commands.

Is there a good way to test manually? I have the ffmpeg commands with arguments, but how would I pipe in the stream from the HDHomeRun?

Those flags need to go after the -i <in>

Easiest for manual testing would be to either stream from the hdhr, or download a test video and operate on that.

ffmpeg -i http://x.x.x.x:5004/auto/v17.1

or

curl -o test.mpg http://x.x.x.x:5004/auto/v17.1?duration=30
ffmpeg -i test.mpg ..

OK, I have it repeatable manual: command and arguments captured are in the script below. Forcing the number of buffers made no change (strace still sees 6 being requested even with the change) Any thoughts on other arguments to change?

#!/bin/sh
args="-hide_banner -nostats -loglevel warning -noautoscale -fflags discardcorrupt+genpts -f mpegts -copyts -probesize 8000000 -i - -num_capture_buffe
rs 3 -num_output_buffers 3 -enc_time_base -1 -max_muxing_queue_size 4096 -muxdelay 0 -map 0:v:0? -map 0:a? -ignore_unknown -sn -c:v h264_v4l2m2m -g:v
 60 -force_key_frames:v source -profile:v high -filter:v fastdeint=blend,scale_v4l2m2m=-2:min(ih\,1080) -b:v 10000k -minrate 9000k -maxrate 11000k -b
ufsize 20000k -c:a aac -ac 2 -b:a 256k -filter:a aresample=async=1 -f hls -hls_time 0.010000 -hls_list_size 360000 -hls_delete_threshold 1 -hls_flags
 temp_file+delete_segments -start_number 1"
curl http://192.168.1.223:5004/auto/v5.1 | sudo /mnt/Media/dvr/config/2021.10.25.1801/ffmpeg ${args} /home/Justin/teststream.m3u8

./test
output VIDIOC_REQBUFS failed: Invalid argument #
no v4l2 output context's buffers
[Parsed_scale_v4l2m2m_1 @ 0x14eb89f0] can't configure encoder
[Parsed_scale_v4l2m2m_1 @ 0x14eb89f0] Failed to configure output pad on Parsed_scale_v4l2m2m_1
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
[aac @ 0x14b7f3f0] 2 frames left in the queue on closing
[aac @ 0x14d0ebf0] 2 frames left in the queue on closing

Changing from channel 5.1 (1080i) to 6.1 (720p) in the curl results in a success:

./test
[hls @ 0x18833f50] Non-monotonous DTS in output stream 0:0; previous: 5860186884, current: 0; changing to 5860186885. This may result in incorrect timestamps in the output file.
[hls @ 0x18833f50] Non-monotonous DTS in output stream 0:0; previous: 5860276974, current: 0; changing to 5860276975. This may result in incorrect timestamps in the output file.
[hls @ 0x18833f50] Non-monotonous DTS in output stream 0:0; previous: 5860367064, current: 0; changing to 5860367065. This may result in incorrect timestamps in the output file.