Jump to content

Cedrus on Armbian


divis1969

Recommended Posts

Hi,

Did anybody play with Cedrus on the recent kernels?

I'm going to play with it on Bananapi m1, kernel 5.4 and Ubuntu Bionic.

Should I just got step-by-step using this instructions http://linux-sunxi.org/Sunxi-Cedrus ?

The goal is to evaluate whether this is suitable solution for video surveillnace. I'd used kerberosio with an IP camera for couple years and this does not work good with motion detection.

Link to comment
Share on other sites

On 4/27/2020 at 11:13 AM, MacBreaker said:

Did you try out Zoneminder? I think about to try it in the next time when i've time.

Yes, I did. If was long time ago and I found kerberosio more attractive. There was also a performace issue with ZM on bananapi that time.
I've tested ZM recently again (on bananapi m3) and it seems using less CPU than kerberosio while movement detection. So, I would switch to ZM if it will be able to handle >1 cameras.
But I decided to first play with HW decoding on bananapi prior to migrating to ZM.

 

-----

Here are the results of my attempt to use cedrus.
- I've built libva-v4l2-request. There were few issues with it. It requires libva-dev and libdrm-dev, I've installed it with apt.
Version release-2019.03 of libva-v4l2-request failed on build due to libva-dev version mismatch (this package seems declared incorrect verion for pkg-config).
I've switched to a tip of the master branch was built successfully (but with small change in the /usr/include/linux/videodev2.h - I've added v4l2_timeval_to_ns which
is missing. BTW, I've also installed linux headers with apt, these headers contain v4l2_timeval_to_ns but libva-v4l2-request does not use these)

This lib is installed by default to /usr/lib/dri/, but libVA will search it under /usr/lib/arm-linux-gnueabihf/dri/ and I've just create a symbolic link. Maybe --prefic should be specified to autoconf instead.


- I've tried to use this lib with ffmpeg (default, installed with apt):

export LIBVA_DRIVER_NAME=v4l2_request
ffmpeg -v verbose -hwaccel vaapi -hwaccel_device /dev/video0 -hwaccel_output_format vaapi -i big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 -r 5 -an stream.mp4


It produces the following error:
 

[AVHWDeviceContext @ 0x1d7a820] libva: VA-API version 1.1.0
[AVHWDeviceContext @ 0x1d7a820] libva: va_getDriverName() returns -1
[AVHWDeviceContext @ 0x1d7a820] libva: User requested driver 'v4l2_request'
[AVHWDeviceContext @ 0x1d7a820] libva: Trying to open /usr/lib/arm-linux-gnueabihf/dri/v4l2_request_drv_video.so
[AVHWDeviceContext @ 0x1d7a820] libva: Found init function __vaDriverInit_1_1
[AVHWDeviceContext @ 0x1d7a820] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x1d7a820] Initialised VAAPI connection: version 1.1
[AVHWDeviceContext @ 0x1d7a820] Unknown driver "v4l2-request", assuming standard behaviour.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[h264 @ 0x1d77fc0] Reinit context to 1280x720, pix_fmt: vaapi_vld
v4l2-request: Unable to set control: Bad address
v4l2-request: Unable to queue media request: No such file or directory
[h264 @ 0x1d77fc0] Failed to end picture decode issue: 1 (operation failed).
[h264 @ 0x1d77fc0] hardware accelerator failed to decode picture

Kernel log also contains errors:
 

[94838.781065] cedrus 1c0e000.video-codec: Missing required codec control
[94838.785428] cedrus 1c0e000.video-codec: Missing required codec control
[94838.791230] cedrus 1c0e000.video-codec: Missing required codec control
[94838.794613] cedrus 1c0e000.video-codec: Missing required codec control

- I've built v4l2-request-test and play with it. Initially it complains "Unable to start display engine" so, I've commented this functionality (so it can decode, but does not try to display frames).
This suite contains several test packages (frames). MPEG2 tests works perfectly (decoding only, as I said).

H265 tests fail with error
Processing frame 1/50
Loaded 145064 bytes of video slice data
Unable to set control: Bad address

There was no kernel errors.
H264 tests are disabled because of absence of V4L2_PIX_FMT_H264_SLICE in the system headers (linux headers contain it but autoconf does not see those).

 

Any suggestions how to enable H264? Should I also rebuild the kernel? What's wrong with H265?

Edited by divis1969
Corrections
Link to comment
Share on other sites

I've found that the issue with h264 codec is caused by the size of the struct v4l2_ctrl_h264_slice_params defined in include/media/h264-ctrls.h (kernel) and include/h264-ctrls.h (libva-v4l2-request).

Kernel's version adds one more field start_byte_offset with commit

commit 5604be66a56867a784e162299a48c214921ffa1b
Author: Boris Brezillon <boris.brezillon@collabora.com>
Date:   Fri Aug 16 13:01:24 2019 -0300

    media: uapi: h264: Add the concept of decoding mode

I did not find any changes in libva-v4l2-request that match this change in kernel.

I'm going to revert the above commit to test whether this can fix the issue.

Link to comment
Share on other sites

I have reverted the following commits:
 

341772b82a3b media: cedrus: Specify H264 startcode and decoding mode
8cae93e09011 media: uapi: h264: Add the concept of start code
5604be66a568 media: uapi: h264: Add the concept of decoding mode

Now I can run decoding of H264:

$ export LIBVA_DRIVER_NAME=v4l2_request
$ time ffmpeg -hwaccel vaapi -hwaccel_device /dev/video0 -hwaccel_output_format vaapi -i big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 -f null /dev/null
...
real    0m15.255s
user    0m5.651s
sys    0m1.693s

Average speed is ~5.3x, fps ~130

There are some errors at the end though:
 

[AVHWFramesContext @ 0xae54cfe0] Failed to destroy surface 0x400000b: 6 (invalid VASurfaceID).

Here is the test of decoding without hardware:

$ time ffmpeg -i big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 -f null /dev/null
real    0m37.776s
user    0m57.906s
sys    0m1.983s

Average speed is ~2.0x, fps ~50

I also tried to decode in software and encode in hardware. This causes crash of ffmpeg (I was not able to get a stack with gdb yet):

ffmpeg -vaapi_device /dev/video0 -i big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 -vf 'format=nv12,hwupload' -c:v h264_vaapi -an stream.mp4
...
Segmentation fault

 

Link to comment
Share on other sites

Re-encoding from 25fps to 5fps (sw-to-sw and hw-to-sw) are almost identical though the second case takes more time (copying hw buffers?):

$ time ffmpeg -hwaccel vaapi -hwaccel_device /dev/video0 -i big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 -c:v libx264 -r 5 -an stream.mp4
...
real    6m45.657s
user    10m44.271s
sys    0m13.720s

$ time ffmpeg -i big_buck_bunny_720p_H264_AAC_25fps_3400K.MP4 -c:v libx264 -r 5 -an stream_sw.mp4
...
real    6m20.538s
user    10m19.009s
sys    0m3.729s

The video produced with hw decoder has small artifacts at the bottom-right corner.

Link to comment
Share on other sites

first, very interesting! thanks for your work here.

 

second, wouldn't it make more sense to update libva-v4l2-request? it is known to be out of date...

 

speaking as a rk3399 user (pbp) that would love to adapt it to include hantro and rkvdec.

Link to comment
Share on other sites

I've tried to ask a question in IRC channel (#cedrus on freenode) but did not get an answer (or maybe I've missed it while I was offline, do not know where to get backlog).

If you mean to update a library by myself, I do not have any experience with H264 (or other video codecs).

The goal was to get a quick estimation whether cedrus is good enough for video surveillance application.

Link to comment
Share on other sites

Hello. Thanks to you post, i've started VPU acceleration in H3 (OrangePI PC). For your SBC seems it will be the same.

 

On 5/29/2020 at 10:09 PM, divis1969 said:

I have reverted the following commits:

 

Seems, it will be better to upgrade backend headers, than downgrade kernel

 

On 5/29/2020 at 10:09 PM, divis1969 said:

[AVHWFramesContext @ 0xae54cfe0] Failed to destroy surface 0x400000b: 6 (invalid VASurfaceID).

 

Try this patch: https://github.com/bootlin/libva-v4l2-request/pull/30/files

 

Details:

https://forum.armbian.com/topic/11184-hardware-graphicvideo-acceleration-in-h3-mainline/?do=findComment&comment=105564

Link to comment
Share on other sites

Thanks for the tip!

 

BTW, I've got a crash stack for a segmentation fault I've mentioned above:

 

Thread 1 "ffmpeg" received signal SIGSEGV, Segmentation fault.
tiled_to_planar () at tiled_yuv.S:86
86        vld1.8    {d0 - d3}, [SRC :256], TSIZE
(gdb) bt
#0  tiled_to_planar () at tiled_yuv.S:86
#1  0xb6fc25b0 in copy_surface_to_image (driver_data=driver_data@entry=0x466960, surface_object=surface_object@entry=0x469f48, image=image@entry=0xbeffda44) at image.c:159
#2  0xb6fc280e in RequestDeriveImage (context=<optimized out>, surface_id=67108864, image=0xbeffda44) at image.c:200
#3  0xb5a5eb84 in ?? () from /usr/lib/arm-linux-gnueabihf/libavutil.so.55
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

@All Is that something known already?

Link to comment
Share on other sites

Hi,

I'm trying to build that v4l2-request source code, on OrangePi PC+ (H3) but it seems that there area lot of undefined macro from linux/videodev2.h . Looks like this file is outdated even if I get the last daily armbian image. How did you manage to compile it?

 

among others, missing defines are:

V4L2_PIX_FMT_SUNXI_TILED_NV12
V4L2_PIX_FMT_MPEG2_SLICES

 

inserted by https://github.com/torvalds/linux/commit/c27bb30e7b6d385c5bff26406089377d678f1a1d on mainline kernel source code

 

Cheers,

Will'

Edited by Chevremw
Link to comment
Share on other sites

On 11/14/2020 at 5:25 PM, Werner said:

All kernel and header packages for the sunxi family are built from https://github.com/megous/linux/tree/orange-pi-5.9

 

I'm running 5.10.12 on opi PC2 and gettin the same problem with V4L2_PIX_FMT_SUNXI_TILED_NV12 which is not defined in /usr/include/linux/videodev2.h

 

It is defined in that source tree

https://github.com/megous/linux/blob/orange-pi-5.10/include/uapi/linux/videodev2.h

 

How is it getting lost in the armbian build process?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines