Nanopi neo air ffmpeg with Cedrus H264


Recommended Posts

Hi all. 

I have a board nanopi neo air with armbian linux on it.   We with my colleague try to setting up ffmpeg with cedrus264 for hardware accelerated  capturing video from ov5640-like camera device. 

There is my  armbianmonitor.  

There are my v4l2-ctl -d /dev/videox -D out:

 

Spoiler

Driver Info:
    Driver name      : cedrus
    Card type        : cedrus
    Bus info         : platform:cedrus
    Driver version   : 5.4.51
    Capabilities     : 0x84208000
        Video Memory-to-Memory
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps      : 0x04208000
        Video Memory-to-Memory
        Streaming
        Extended Pix Format
Media Driver Info:
    Driver name      : cedrus
    Model            : cedrus
    Serial           : 
    Bus info         : platform:cedrus
    Media version    : 5.4.51
    Hardware revision: 0x00000000 (0)
    Driver version   : 5.4.51
Interface Info:
    ID               : 0x0300000c
    Type             : V4L Video
Entity Info:
    ID               : 0x00000001 (1)
    Name             : cedrus-source
    Function         : V4L2 I/O
    Pad 0x01000002   : 0: Source
      Link 0x02000008: to remote pad 0x1000004 of entity 'cedrus-proc': Data, Enabled, Immutable
 

Spoiler

Driver Info:
    Driver name      : sun6i-video
    Card type        : sun6i-csi
    Bus info         : platform:camera
    Driver version   : 5.4.51
    Capabilities     : 0x84200001
        Video Capture
        Streaming
        Extended Pix Format
        Device Capabilities
    Device Caps      : 0x04200001
        Video Capture
        Streaming
        Extended Pix Format
Media Driver Info:
    Driver name      : sun6i-csi
    Model            : Allwinner Video Capture Device
    Serial           : 
    Bus info         : 
    Media version    : 5.4.51
    Hardware revision: 0x00000000 (0)
    Driver version   : 5.4.51
Interface Info:
    ID               : 0x03000003
    Type             : V4L Video
Entity Info:
    ID               : 0x00000001 (1)
    Name             : sun6i-csi
    Function         : V4L2 I/O
    Pad 0x01000002   : 0: Sink, Must Connect
      Link 0x02000007: from remote pad 0x1000006 of entity 'Borei_VideoDriver 0-003c': Data, Enabled, Immutable
 

After some reconfiguration of dts, we can successfully capture video in low fps with 

ffmpeg -f v4l2 -framerate 25 -video_size 960x720 -i /dev/video1 output.mkv

but with 

ffmpeg -f v4l2 -channel 0 -video_size 960x720 -i /dev/video1 -pix_fmt nv12 -r 30 -b:v 64k -c:v cedrus264 test.mp4

ffmpeg failed: 

Spoiler

root@nanopiair:/home/pi# ffmpeg -f v4l2 -channel 0 -video_size 960x720 -i /dev/video1 -pix_fmt nv12 -r 30 -b:v 64k -c:v cedrus264 test.mp4 > ffmpeg_error.txt
ffmpeg version git-2015-01-22-f86a076 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 14 2020 09:02:41 with gcc 8 (Debian 8.3.0-6)
  configuration: --prefix=/usr --enable-nonfree --enable-gpl --enable-vdpau --enable-libx264 --enable-libv4l2
  libavutil      54.  6.100 / 54.  6.100
  libavcodec     56.  0.101 / 56.  0.101
  libavformat    56.  2.100 / 56.  2.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.102 /  5.  0.102
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, video4linux2,v4l2, from '/dev/video1':
  Duration: N/A, start: 1581.872201, bitrate: 248832 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 960x720, 248832 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
File 'test.mp4' already exists. Overwrite ? [y/N] y
[cedrus264 @ 0x241ff20] VE Open error.
Output #0, mp4, to 'test.mp4':
    Stream #0:0: Video: h264, q=2-31, 128 kb/s, 30 fps
    Metadata:
      encoder         : Lavc56.0.101 cedrus264
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (cedrus264))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
 

 

Ffmpeg was buided from FFmpeg-Cedrus, also we  try follow this and use this binaries - result haven't changed. 

 

After some inspecting sources of ffmpeg-cedrus we found that ffmpeg try to open /dev/cedar_dev device, which don't exists in our system.  Ffmpeg fails on opening device. If we replace /dev/cedar_dev by /dev/video0, where is our cedrus driver, ffmpeg fails on ioctl IOCTL_GET_ENV_INFO.  In source, it is 99 or 101 line.

We check kernel config for configuration, provided by Sunxi-Cedrus and determine that cedrus was configured right. 

 

Also we  have tried all described actions on official armbian buster image for nanopi neo air and we have got the same result. 

What we does wrong? 

 

Link to post
Share on other sites
Armbian is a community driven open source project. Do you like to contribute your code?
18 hours ago, @lex said:

Encoding using cedrus264 was for legacy kernel.

I think Uboborov has done some work with mainline kernel for encoding with cedrus. Search the forum for "encoding" or uboborov

Thank you for you answer. What kernel version do you mean as legacy kernel? In armbian build tool legacy kernel is 4.19 kernel and it has no cedrus at all, including /dev/cedar_dev. We found topic from Uboborov(this), and his driver  (this) with hardware h264 encoder (this). We build fresh 4.19 kernel, Uboborov's driver and install it to our system. Driver has loaded successfully (determine by lsmod). We change dts, as it changed in his github, but still there isn't /dev/cedar_dev. Also, as i already said in my first post, we also try to use Uboborov's ffmpeg (this), including precompiled binaries (found there).  

Link to post
Share on other sites
18 hours ago, gounthar said:

So does the hardware acceleration work for you @a.rodionov ?

Yes, it is.

On nanopi neo air with armbian 20.08.0 (5.7.8) it works.

 

FFmpeg with 960x720 input from our camera* encode mp4 by h264_omx with 15-20 fps.  If i use cedrus264 as codec, ffmpeg can easy provide 30 fps. With default cam500b  i get 60 fps 640x480 (that is maximum of the camera).  Fps numbers i get from ffmpeg log and i think  this results is accurate enough. 

* our camera  isn't ov5640 default camera and 30 fps likely it's maximum fps. We haven't camera's datasheet. 

Link to post
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...