Jump to content

ubobrov

Members
  • Posts

    20
  • Joined

  • Last visited

Posts posted by ubobrov

  1. 22 hours ago, P.P.A. said:

    his approach, which supports encoding of H.264 uses the libvdpau-sunxi API

    This is a bit incorrect. libvdpau-sunxi is using for decoding only.

    22 hours ago, P.P.A. said:

    if I understand it correctly, ubobrov ported a legacy feature to mainline

    The Cedrus legacy driver has been supported to run on mainline kernel as KLM.

  2. Here are the Armbian bionic images with installed RTSP streamer using H264 HW encoding on Allwinner H3 boards

    Orange Pi One

    Orange Pi Zero

    Images are able to run on any board with Allwinner H3

     

    Spoiler

    Description:
    The image is Armbian bionic 20.08 mainline kernel 5.7.15 with installed RTSP server sourced from the HW encoded H264 bitstream.

    H264 HW encoder uses sunxi cedrus driver and takes video from the video device /dev/videoN.
    Any USB camera with output format YUV 4:2:2 or NV12 can be used as the image source for the encoder.
    The system uses UCI from the OpenWrt project (https://openwrt.org/docs/guide-user/base-system/uci) to manage settings of the RTSP streamer.

    RTSP server is starting on boot as a service named supervisor (systemctl start/stop/restart supervisor)
    To watch RTSP stream from the board use mpv or vlc:

    mpv --profile=low-latency --no-cache --untimed rtsp://YUR_BOARD_IP/live.cam
    or
    vlc --sout-udp-caching=0 --clock-jitter=500 rtsp://YUR_BOARD_IP/live.cam

     

    Installation:
    1. Unpack the image
    2. Instal the image to the SD card (linux: sudo dd if=armbian_bionic_rtsp_h264_opi_one.img of=/dev/sdX bs=1M)
    3. Insert and power up

    username: root
    password: 123


    Settings:
    To display RTSP settings use uci show:

    uci show system.rtsp

      system.rtsp=rtsp
      system.rtsp.proto='udp'
      system.rtsp.device='/dev/video0'
      system.rtsp.format='YUYV'
      system.rtsp.port='554'
      system.rtsp.resolution='640x480'
      system.rtsp.channel='live.cam'
      system.rtsp.framerate='25'
      system.rtsp.server='rtsp'
      system.rtsp.uclnt='0.0.0.0'
     
    To change any settings use command uci set:
    ...
    uci set system.rtsp.device=/dev/video1
    uci set system.rtsp.format=UYVY
    ...

    To save changes use command uci commit:
    uci commit

    Settings description:
      system.rtsp.proto - rtsp server network protocol (udp/tcp)
      system.rtsp.device - input video device for h264 encoder (/dev/videoN)
      system.rtsp.format - input image format (YUYV, UYVY, H264, NV12) from the /dev/videoN
      system.rtsp.port - RTSP server port
      system.rtsp.resolution - input image resolution
      system.rtsp.framerate - input stream framerate
      system.rtsp.server - must be rtsp
      system.rtsp.uclnt - not used

    To apply config changes use restart service:
    systemctl restart supervisor
     
    Troubleshooting:
    If there is no RTSP stream after the board is started:
    * check the Ethernet cable connected
    * check the USB camera connected
    * check the USB camera valid name setting (/dev/video0,1,2...N)
    * check the USB camera image format supported (YUYV, UYVY, NV12, H264)
    * check your router RTSP port unblocked
    * check valid command line arguments for playing remote RTSP stream

     

  3. Your problem is in Pi Zero's memory. To make driver loaded without errors you should load it on startup.

    #! /bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          cedrus
    # Required-Start:    $syslog
    # Required-Stop:     $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start daemon at boot time
    # Description:       Enable service provided by daemon.
    ### END INIT INFO
    
    /sbin/insmod /lib/modules/sunxi_cedar.ko
    
    exit 0

     

  4. Decoding H264 and X11 rendering using vdpau_sunxi, libcedrus, kernel 4.20.17, mpv, vncserver and Armbian Bionic on Orange PI Zero

    libvdpau: https://github.com/uboborov/libvdpau-sunxi-H3.git

    libcedrus: https://github.com/uboborov/libcedrus-H3.git

    cedar_dev: https://github.com/uboborov/sunxi-cedar-mainline.git

     

    mpv, ffmpeg, x11 installed using apt

     

    It works extremely slow but it's just a beginning  )

    video: https://www.youtube.com/watch?v=9O7L_kaEDdk

    UPD:

    video on Orange PI One 1280x720 HDMI (works pretty fine)

    https://www.youtube.com/watch?v=8qPyOG-yJIw

     

  5. that happens because of the kernel you're using.

    be careful with the node:

    reserved-memory {
    		#address-cells = <1>;
    		#size-cells = <1>;
    		ranges;
    
    		cma_pool: cma@43c00000 {
    			compatible = "shared-dma-pool";
    			reusable;
    			reg = <0x43c00000 0x6000000>;
    			linux,cma-default;
    		};
    	};

    it should look like above.

    to check everything is alright with the CMA, you should check CMA on kernel boot:

     dmesg | grep CMA
    [    0.000000] Reserved memory: created CMA memory pool at 0x43c00000, size 96 MiB

    it must look like above

    good luck

  6. Here the step-by-step instruction how to build and test the encoder from scratch on Orange PI zero board

    it has been written and tested today.

    Spoiler

    1. download https://dl.armbian.com/_old/orangepizero/archive/Armbian_5.90_Orangepizero_Debian_buster_next_4.19.57.7z
    2. extract image
    3. write image to SD card:
        dd if=Armbian_5.90_Orangepizero_Debian_buster_next_4.19.57.img of=/dev/sdf_your_drive_letter bs=4096
    4. sudo apt update
    5. sudo apt-get install libpixman-1-dev libvdpau-dev libpulse-dev libv4l-dev libmp3lame-dev libx264-dev xvfb x11-xkb-utils xserver-xorg-core
    6. download the kernel from https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.20.17.tar.gz
    7. unpack the kernel to linux-4.20.17
    8. modify file linux-4.20.17/arch/arm/boot/dts/sun8i-h3.dtsi:
       comment out or remove node video-codec@01c0e000
       add nodes:
        reserved-memory {
            #address-cells = <1>;
            #size-cells = <1>;
            ranges;

            cma_pool: cma@4a000000 {
                compatible = "shared-dma-pool";
                size = <0x6000000>;
                reusable;
                linux,cma-default;
            };
        };
        
        ve: video-engine@01c0e000 {
                compatible = "allwinner,sunxi-cedar-ve";
                reg = <0x01c0e000 0x1000>,
                      <0x01c00000 0x10>,
                      <0x01c20000 0x800>;
                memory-region = <&cma_pool>;      
                syscon = <&syscon>;         
                clocks = <&ccu CLK_BUS_VE>, <&ccu CLK_VE>,
                         <&ccu CLK_DRAM_VE>;
                clock-names = "ahb", "mod", "ram";
                resets = <&ccu RST_BUS_VE>;
                interrupts = <GIC_SPI 58 IRQ_TYPE_LEVEL_HIGH>;
            };
    9. modify file linux-4.20.17/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dtsi:       
       add
           &ve {
              status = "okay";
           }

    10. install arm gnueabihf compiller for your build host
    11. build the kernel:
        cd linux-4.20.17
        make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sunxi_defconfig
        make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage dtbs uImage LOADADDR=0x40008000
        make modules ARCH=arm  CROSS_COMPILE=arm-linux-gnueabihf-
        make modules_install ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/your/path/to/modules
    12. clone cedrus repo
        git clone https://github.com/uboborov/sunxi-cedar-mainline
    13. build cedrus:
        cd sunxi-cedar-mainline
        make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- KDIR=../linux-4.20.17 -f Makefile.linux
    14. create the boot script template boot.cmd with content:
        setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rootwait panic=10
        load mmc 0:1 0x43000000 /boot/sun8i-h2-plus-orangepi-zero.dtb
        load mmc 0:1 0x42000000 /boot/zImage-4.20.17
        bootz 0x42000000 - 0x43000000
    15. build the boot script:
        mkimage -C none -A arm -T script -d boot.cmd boot.scr
    16. copy following files to the /boot directory on SD card:
        cp linux-4.20.17/arch/arm/boot/zImage SD/boot/zImage-4.20.17
        cp linux-4.20.17/arch/arm/boot/dts/sun8i-h2-plus-orangepi-zero.dtb SD/boot
        cp script.scr SD/boot
    17. copy cedrus driver to SD card:
        cp sunxi-cedar-mainline/sunxi_cedar.ko SD/lib/modules
    18. copy kernel modules to SD card:
        cp -R /your/path/to/modules/4.20.17 SD/lib/modules
    19. reboot the board to boot 4.20.17 kernel
    20. test CMA:
        dmesg | grep "Reserved memory:"
        the output must be like this: Reserved memory: created CMA memory pool at 0x43c00000, size 96 MiB
        if not -> something went wrong with CMA in dts file
    21. on the board build libcedrus:
        git clone https://github.com/linux-sunxi/libcedrus
        cd libcedrus
        sudo make && sudo make install
    22. on the board build libvdpau:
        git clone https://github.com/linux-sunxi/libvdpau-sunxi
        cd libvdpau-sunxi
        sudo make && sudo make install
    23. configure ldconfig
        cd /usr/local/lib/
        ldconfig
        cd /usr/lib/arm-linux-gnueabihf/vdpau/
        ldconfig
    25. on the board clone ffmpeg:
        git clone --depth=1 https://github.com/stulluk/FFmpeg-Cedrus.git
        git clone https://github.com/uboborov/ffmpeg_h264_H3.git
        cp /root/ffmpeg_h264_H3/cedrus264.c /root/FFmpeg-Cedrus/libavcodec/cedrus264.c
        cp -R /root/ffmpeg_h264_H3/sunxi /root/FFmpeg-Cedrus/libavcodec/arm
    26. configure ffmpeg (without libx264 due to probability of errors during building):
        cd FFmpeg-Cedrus
        ./configure --enable-nonfree --enable-gpl --enable-version3 --enable-vdpau --disable-libx264 \
                    --enable-libmp3lame --enable-libpulse --enable-libv4l2 --enable-shared --disable-static
        make -j2
        if you meet linking error like:
            libavcodec/xface.o: relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC
            collect2: error: ld returned 1 exit status
        just try to remove file libavcodec/xface.o and run make again
        
        make install
    27. configure ldconfig:
        cd /usr/local/lib
        ldconfig
    28. run ffmpeg:
        ffmpeg
        the output must be like:
        
        ffmpeg version git-2015-01-22-f86a076 Copyright (c) 2000-2014 the FFmpeg developers
        built on Nov 26 2019 17:40:47 with gcc 8 (Debian 8.3.0-6)
        configuration: --enable-nonfree --enable-gpl --enable-version3 --enable-vdpau --disable-libx264 --enable-libmp3lame --enable-libpulse --enable-libv4l2 --enable-shared --disable-static
        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
        Hyper fast Audio and Video encoder
        usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
    29. load cedrus driver:
        insmod /lib/modules/sunxi_cedar.ko
        on dmesg you must see lines like:
        [  253.966985] sunxi_cedar: loading out-of-tree module taints kernel.
        [  253.967968] sunxi cedar version 0.1
        [  253.968240] [cedar]: install start!!!
        [  253.968407] cedar_ve: cedar-ve the get irq is 40
        [  253.968437] sunxi-cedar 1c0e000.video-engine: assigned reserved memory node cma@43c00000
        [  254.046060] [cedar]: memory allocated at address 43D00000
        [  254.046072] [cedar]: install end!!!
        on lsmod you must see like:
        sunxi_cedar            20480  0
    30. download raw NV12 video 1280x720 from https://yadi.sk/d/48_t5f18aoZDsw
    31. run encoder test:
        ffmpeg -s 1280x720 -pix_fmt nv12 -f rawvideo -i video.nv12 -pix_fmt nv12 -c:v cedrus264 stream.h264
        output like:
        frame=   97 fps=9.0 q=30.0 Lsize=    5702kB time=00:00:03.88 bitrate=12038.7kbits/s
    32. build the standalone encoder app:
        git clone https://github.com/uboborov/cedrus.git  
        cd cedrus/h264enc
        make
        cp h264enc /root
    33. test standalone encoder:
        ./h264enc video.nv12 1280 720 out.h264
        output like:
        Runnig h264 encoding from file video.nv12...
        Done!

    play output *.h264 files on PC:

    mpv stream.h264

    mpv out.h264

     

     

  7. 3 hours ago, visitoid said:

    Which OS version should I use Ubuntu or Debian? What kernel? I just want to watch a movie? The steps are the same?

    i don't know what you should use. i can only tell you what i use. everything except ffmpeg and libvdpau-sunxi i build on

    Linux  4.15.0-70-generic #79~16.04.1-Ubuntu SMP Tue Nov 12 14:01:10 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
    arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.7-2013.04-20130415 - Linaro GCC 2013.04) 4.7.3 20130328 (prerelease) 4.3.3

    ffmpeg and libvdpau-sunxi i build on the target device (orange pi zero or pc in my case)
     

    Linux gateway 4.20.17 #3 SMP Tue Nov 12 17:19:54 MSK 2019 armv7l GNU/Linux
    gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
    BOARD=orangepizero
    BOARD_NAME="Orange Pi Zero"
    BOARDFAMILY=sun8i
    BUILD_REPOSITORY_URL=https://github.com/armbian/rkbin
    BUILD_REPOSITORY_COMMIT=51d55a4
    VERSION=5.90
    LINUXFAMILY=sunxi
    BRANCH=next
    ARCH=arm
    IMAGE_TYPE=stable
    BOARD_TYPE=conf
    INITRD_ARCH=arm
    KERNEL_IMAGE_TYPE=zImage

    if you want to watch a movie on your target board you have to build more tools than just ffmpeg. i don't know what exactly tools you do need.

  8. 11 minutes ago, gounthar said:
      Reveal hidden contents
    
    
    libavcodec/cedrus264.c: In function 'cedrus264_encode_init':
    libavcodec/cedrus264.c:242:16: error: implicit declaration of function 've_get'; did you mean 've_free'? [-Werror=implicit-function-declaration]
      c4->ve_regs = ve_get(VE_ENGINE_AVC, 0);
                    ^~~~~~
                    ve_free
    libavcodec/cedrus264.c:242:23: error: 'VE_ENGINE_AVC' undeclared (first use in this function); did you mean 'HAVE_INLINE_ASM'?
      c4->ve_regs = ve_get(VE_ENGINE_AVC, 0);
                           ^~~~~~~~~~~~~
                           HAVE_INLINE_ASM
    libavcodec/cedrus264.c:242:23: note: each undeclared identifier is reported only once for each function it appears in
    libavcodec/cedrus264.c:251:22: error: dereferencing pointer to incomplete type 'struct ve_mem'
      writel(c4->input_buf->phys, c4->ve_regs + VE_ISP_INPUT_LUMA);
                          ^~
    libavcodec/cedrus264.c: In function 'cedrus264_encode':
    libavcodec/cedrus264.c:296:2: error: too few arguments to function 've_flush_cache'
      ve_flush_cache(c4->input_buf);
      ^~~~~~~~~~~~~~
    In file included from libavcodec/cedrus264.c:42:
    libavcodec/arm/sunxi/ve.h:29:6: note: declared here
     void ve_flush_cache(void *start, int len);
          ^~~~~~~~~~~~~~
    libavcodec/cedrus264.c:299:2: error: too few arguments to function 've_flush_cache'
      ve_flush_cache(c4->output_buf);
      ^~~~~~~~~~~~~~
    In file included from libavcodec/cedrus264.c:42:
    libavcodec/arm/sunxi/ve.h:29:6: note: declared here
     void ve_flush_cache(void *start, int len);
          ^~~~~~~~~~~~~~
    libavcodec/cedrus264.c: In function 'cedrus264_close':
    libavcodec/cedrus264.c:357:2: error: implicit declaration of function 've_put'; did you mean 've_wait'? [-Werror=implicit-function-declaration]
      ve_put();
      ^~~~~~
      ve_wait
    cc1: some warnings being treated as errors
    make: *** [common.mak:49: libavcodec/cedrus264.o] Error 1
    make: *** Waiting for unfinished jobs....

     

    Regarding the ffmpeg build, I must have missed something, because this is what I got with gcc 8.3.0.

    perhaps you have lost some steps on building ffmpeg or done something wrong.

    on the target device:
    
    git clone https://github.com/stulluk/FFmpeg-Cedrus.git
    git clone https://github.com/uboborov/ffmpeg_h264_H3.git
    cp /root/ffmpeg_h264_H3/cedrus264.c /root/FFmpeg-Cedrus/libavcodec/cedrus264.c
    cp -R /root/ffmpeg_h264_H3/sunxi /root/FFmpeg-Cedrus/libavcodec/arm
    apt-get install libpulse-dev libv4l-dev libmp3lame-dev libx264-dev
    
    cd FFmpeg-Cedrus
    
    ./configure --prefix=/usr --enable-nonfree --enable-gpl --enable-version3 --enable-vdpau --enable-libx264 --enable-libmp3lame --enable-libpulse --enable-libv4l2 
    
    make -j 4
    make install

     

  9. 1 hour ago, gounthar said:

    So, I've built the kernel and you repo on the Zero, because I don't have an Armbian build machine anymore.
    Should I go the old x86 way of installing the kernel, like

    
    make modules_install && make install

    I guess it's way more subtle on an ARM SBC. :wacko:

    i build ffmpeg and libvdpau-sunxi on the target device.

    kernel and other tools i build on the host machine.

    i build kernel without modules.

    all drivers are builtin

    for my tests i use the armbian image on the SD card. i simply copy the kernel (zImage), device tree blob (dtb) and customized boot script (boot.scr) to the /boot folder on the SD and reboot the board

    boot script (script.cmd) looks like that:

    setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rootwait panic=10
    load mmc 0:1 0x43000000 /boot/sun8i-h2-plus-orangepi-zero-4.20.17.dtb
    load mmc 0:1 0x42000000 /boot/zImage-4.20.17
    bootz 0x42000000 - 0x43000000

     

  10. On 11/22/2019 at 7:38 PM, gounthar said:

    and get hardware acceleration for encoding h.264

    You won't get hardware acceleration for encoding h264 because v4l2_request api available for decoding only.

    If you want to get hardware acceleration for encoding you should:

    1. download mainline linux-4.20.17

    2. clone repo https://github.com/uboborov/sunxi-cedar-mainline

    3. replace or modify device tree files from folder 4.20.17 of the repo (add CMA node and VE node) in the kernel folder

    4. build the kernel following instructions from 4.20.17 folder

    5. build the cedrus driver from the stage 2

    6. clone repo https://github.com/uboborov/ffmpeg_h264_H3 and follow the instructions in the readme file to build ffmpeg with hw h264 support or

    7. clone repo https://github.com/uboborov/cedrus to build standalone h264 encoder and use it somehow like:

    insmod sunxi_cedar.ko
    ffmpeg -f v4l2 -video_size 640x480 -i /dev/video0 -pix_fmt nv12 -r 25 -f rawvideo pipe: | ./h264enc - 640 480 test.h264

     

  11. I've got ffmpeg working with v4l2_request api on Allwinner H3 (orange pi pc).

    It achieved in a few steps:

    1. Download FFmpeg https://github.com/xbmc/FFmpeg/archive/4.0.4-Leia-18.4.tar.gz

    2. Patch it with https://github.com/LibreELEC/LibreELEC.tv/tree/master/packages/multimedia/ffmpeg/patches

    3. Download mainline kernel 5.3.5

    4. Patch it with https://github.com/LibreELEC/LibreELEC.tv/tree/master/projects/Allwinner/patches/linux

    5. Copy linux headers on rootfs /usr/include after kernel built:

    make headers_install ARCH=arm INSTALL_HDR_PATH=/your/path/to/headers

    6. Install libdrm-dev and libudev-dev before configuring FFmpeg

    7. Configure FFmpeg with:

    /configure --enable-v4l2-request --enable-libudev --enable-libdrm --enable-shared --disable-static \
    --disable-openssl --disable-gray --disable-vaapi --disable-vdpau --disable-rkmpp

    8. Build FFmpeg on the target machine (orange pi pc in my case)

    That's it )

     

    ffmpeg -re -hwaccel drm -i Big_Buck_Bunny_720_10s_2MB.mp4 out.avi

    FFmpeg perfectly uses HW acceleration on decoding H264.

×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines