Other OS

HOWTO: Get a working hardware accelerated video with gstreamer.

18 23163
dizus  
Edited by dizus at Thu Jan 8, 2015 06:32

Preface:
I've spent a lot of days trying to get a working hardware accelerated video playback on my Banana Pi
using GStreamer. I've tested almost all available distros and boot images with no luck but finally was able
to get it working. I hope this HOWTO will save a lot of time and nerves for those who wish to use GStreamer
with hardware acceleration on their Banana Pi.

HOWTO:

Get latest Raspbian image here:
  1. http://www.lemaker.org/resources/9-271/raspbian_for_bananapro.html
Copy the Code
Install it on your SD card. /dev/sdX - is your SD card device.
  1. sudo dd bs=1m if=Raspbian_For_BananaPi_v1412.img of=/dev/sdX
Copy the Code
Boot your Banana Pi.
Login as: user/password: bananapi/bananapi
Become root. Password:  bananapi
  1. su
Copy the Code
Update system

  1. apt-get update
  2. apt-get upgrade
Copy the Code
Make sure Sunxi kernel modules get loaded after system reboot
Edit /etc/modules, make sure you have these lines:
  1. sunxi_cedar_mod
Copy the Code
Verify that Sunxi fbturbo driver is enabled in X
Check /var/log/Xorg.0.log, look for lines like:

  1. [    17.193] (II) LoadModule: "fbturbo"
  2. [    17.193] (II) Loading /usr/lib/xorg/modules/drivers/fbturbo_drv.so
  3. [    17.198] (II) Module fbturbo: vendor="X.Org Foundation"
Copy the Code
Turn on specific Sunxi optimizations for X
Edit /usr/share/X11/xorg.conf.d/99-fbturbo.conf

  1. # This is a minimal sample config file, which can be copied to
  2. # /etc/X11/xorg.conf in order to make the Xorg server pick up
  3. # and load xf86-video-fbturbo driver installed in the system.
  4. #
  5. # When troubleshooting, check /var/log/Xorg.0.log for the debugging
  6. # output and error messages.
  7. #
  8. # Run "man fbturbo" to get additional information about the extra
  9. # configuration options for tuning the driver.

  10. Section "Device"
  11.         Identifier      "Allwinner A10/A13 FBDEV"
  12.         Driver          "fbturbo"
  13.         Option          "fbdev" "/dev/fb0"

  14.         Option          "AccelMethod" "G2D"
  15.         Option          "DRI2HWOverlay" "true"
  16.         Option          "DRI2" "true"
  17.         Option          "DRI2_PAGE_FLIP" "true"
  18.         Option          "SwapbuffersWait" "false"
  19. EndSection
Copy the Code
Reboot
  1. reboot
Copy the Code
Login as: user/password: bananapi/bananapi
Become root. Password:  bananapi
  1. su
Copy the Code
Make sure Sunxi kernel modules have been loaded
Look for sunxi_cedar_mod, mali, and mali_drm
  1. lsmod
Copy the Code
Check /var/log/Xorg.0.log to see if there’s no errors and acceleration has indeed been turned on

  1. [    18.611] (II) FBTURBO(0): enabled G2D acceleration
  2. [    18.611] (==) FBTURBO(0): Backing store disabled
  3. [    18.613] (II) FBTURBO(0): using sunxi disp layers for X video extension
  4. [    18.613] (II) FBTURBO(0): using hardware cursor
Copy the Code
Install VDPAU packages
  1. apt-get install libvdpau-dev libvdpau1 vdpau-va-driver vdpauinfo
Copy the Code
Compile VDPAU driver for CedarX VPU

  1. git clone https://github.com/linux-sunxi/libvdpau-sunxi.git
  2. cd libvdpau-sunxi/
  3. make
  4. make install
  5. cd ..
Copy the Code
Verify that VDPA system is working

  1. export VDPAU_DRIVER=sunxi
  2. vdpauinfo
Copy the Code
Should get output similar to this:

  1. [VDPAU SUNXI] VE version 0x1623 opened.
  2. API version: 1
  3. Information string: sunxi VDPAU Driver

  4. Video surface:

  5. name   width height types
  6. -------------------------------------------
  7. 420     8192  8192  NV12 YV12

  8. Decoder capabilities:

  9. name               level macbs width height
  10. -------------------------------------------
  11. MPEG1                 0 32400  3840  2160
  12. MPEG2_SIMPLE          3 32400  3840  2160
  13. MPEG2_MAIN            3 32400  3840  2160
  14. H264_BASELINE        51 32400  3840  2160
  15. H264_MAIN            51 32400  3840  2160
  16. H264_HIGH            51 32400  3840  2160
  17. MPEG4_PART2_SP       51 32400  3840  2160
  18. MPEG4_PART2_ASP      51 32400  3840  2160
Copy the Code
Install VAAPI packages
  1. apt-get install libva1 libva-x11-1 vainfo libva-dev libdrm-dev libudev-dev mesa-common-dev
Copy the Code
Install packages needed for compilation
  1. apt-get install libtool automake
Copy the Code
Get latest VDPAU backend driver for VAAPI:
driver that comes in vdpau-va-driver package is buggy, crashes with
vdpau_EndPicture: Assertion `obj_buffer' failed error

  1. git clone git://anongit.freedesktop.org/vaapi/vdpau-driver
  2. cd vdpau-driver/
  3. ./autogen.sh --prefix=/usr
  4. make
Copy the Code
Remove links which cause installation problems

  1. cd /usr/lib/arm-linux-gnueabihf/dri
  2. rm -f nvidia_drv_video.so s3g_drv_video.so
  3. cd -
Copy the Code
Install driver

  1. make install
  2. cd ..
Copy the Code
Verify that VAAPI system is working

  1. export LIBVA_DRIVER_NAME=vdpau
  2. vainfo
Copy the Code
Should get output similar to this:

  1. libva: VA-API version 0.32.0
  2. libva: User requested driver 'vdpau'
  3. libva: Trying to open /usr/lib/arm-linux-gnueabihf/dri/vdpau_drv_video.so
  4. libva: va_openDriver() returns 0
  5. [VDPAU SUNXI] VE version 0x1623 opened.
  6. vainfo: VA-API version: 0.32 (libva 1.0.15)
  7. vainfo: Driver version: Splitted-Desktop Systems VDPAU backend for VA-API - 0.7.5.pre1
  8. vainfo: Supported profile and entrypoints
  9.       VAProfileMPEG2Simple            : VAEntrypointVLD
  10.       VAProfileMPEG2Main              : VAEntrypointVLD
  11.       VAProfileMPEG4Simple            : VAEntrypointVLD
  12.       VAProfileMPEG4AdvancedSimple    : VAEntrypointVLD
  13.       VAProfileH264Baseline           : VAEntrypointVLD
  14.       VAProfileH264Main               : VAEntrypointVLD
  15.       VAProfileH264High               : VAEntrypointVLD
Copy the Code
Install gstreamer packages
  1. apt-get install gstreamer1.0-x gstreamer1.0-tools gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly
Copy the Code
Install gstreamer VAAPI dependencies
  1. apt-get install libglib2.0-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev
Copy the Code
Compile gstreamer VAAPI plugins. This will take awhile.

  1. git clone https://github.com/gbeauchesne/gstreamer-vaapi.git
  2. cd gstreamer-vaapi/
  3. ./autogen.sh --prefix=/usr
  4. make
  5. make install
  6. cd ..
Copy the Code
Make sure gstreamer VAAPI plugins are correctly installed
  1. gst-inspect-1.0 | grep -i vaapi
Copy the Code
Should get output similar to this:

  1. vaapiparse:  vaapiparse_h264: H.264 parser
  2. vaapi:  vaapidecode: VA-API decoder
  3. vaapi:  vaapipostproc: VA-API video postprocessing
  4. vaapi:  vaapisink: VA-API sink
Copy the Code
Make sure drivers for VDPA/VAAPI are configured
Add these variables in /etc/environment or /etc/profile or wherever you like

  1. export VDPAU_DRIVER=sunxi
  2. export LIBVA_DRIVER_NAME=vdpau
Copy the Code
To watch a video you should be either root or have sufficient permissions to read/write /dev/cedar_dev. You may find it convenient to change default permissions and make sure you are in the video group (by default bananapi user is)

  1. sudo chgrp video /dev/cedar_dev
  2. sudo 0660 /dev/cedar_dev
Copy the Code
Get a H264 video and play it with gstreamer. This pipeline is for video-only:
  1. gst-launch-1.0 filesrc location=my-video.mp4 ! qtdemux ! vaapidecode ! vaapisink
Copy the Code
To play video in fullscreen mode:
  1. gst-launch-1.0 filesrc location=my-video.mp4 ! qtdemux ! vaapidecode ! vaapisink fullscreen=true
Copy the Code
Thank you!

Edited by BananaJoe at Tue Jan 6, 2015 15:04

Thank you, for your good tutorial

I have used all your steps, but it doesen't work.
The only difference is that the file /var/log/X.0.log doesn't exist (only /var/log/Xorg.0.log).
All of the following requirements are met:
    [    17.193] (II) LoadModule: "fbturbo"
    [    17.193] (II) Loading /usr/lib/xorg/modules/drivers/fbturbo_drv.so
    [    17.198] (II) Module fbturbo: vendor="X.Org Foundation"

    [    18.611] (II) FBTURBO(0): enabled G2D acceleration
    [    18.611] (==) FBTURBO(0): Backing store disabled
    [    18.613] (II) FBTURBO(0): using sunxi disp layers for X video extension
    [    18.613] (II) FBTURBO(0): using hardware cursor

    sunxi_cedar_mod, mali, and mali_drm have been loaded

After vdpauinfo, it say:
root@lemaker:/home/bananapi# vdpauinfo
vdpauinfo: cannot connect to X server
root@lemaker:/home/bananapi# export DISPLAY=:0
root@lemaker:/home/bananapi# export VDPAU_DRIVER=sunxi
root@lemaker:/home/bananapi# vdpauinfo
No protocol specified
vdpauinfo: cannot connect to X server :0

Do you have any idea ?
Thank you

My solution:
sudo chmod 0777 /dev/cedar_dev
DISPLAY=:0 vdpauinfo




dizus  
BananaJoe replied at Tue Jan 6, 2015 09:10
Thank you, for your good tutorial

I have used all your steps, but it doesen't work.

I'm glad that my tutorial was helpful for you. As for the error - that's probably because I forgot to mention that the steps described in the tutorial should
be executed as root. It has to do with /dev/cedar_dev default permissions which are 0600 by default. Your solution fixes that, but it would be even more
correct to:
sudo chgrp video /dev/cedar_dev
sudo 0660 /dev/cedar_dev
This should work since by default bananapi user is in video group.
As for /var/log/X.0.log - it's an obvious erratum, thanks for mentioning.

michael  
Hello dizus:

First, thanks for your awesome tutorial. Finally, I can play 1080p video smoothly with Gstreamer + Vaapi.
I'm wondering if I can play Multi-Gstreamer with Vaapi, but seems like I can only play single-gstreamer.
I want to write some program on Banana Pi, so I installed Qt4.8, qt-gstreamer-1.2.0 library and seems everything done perfectly.
When I run a player which is in the qt-gstreamer-1.2.0/example directory, It works perfect without error.
But when I run two player, programs crash and seems like Vaapi can only be used by one player.
If I run two player, second one will show the message below:

AL lib: alsa_open_playback: Could not open playback device 'default' : Device or resource busy
libva: VA-API version 0.32.0
Xlib: extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns -1
libva: VA-API version 0.32.0
Xlib: extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns -1
libva: VA-API version 0.32.0
Xlib: extension "XFree86-DRI" missing on display ":0.0".
libva: va_getDriverName() returns -1
AL lib: alsa_open_playback: Could not open playback device 'default' : Device or resource busy
"The autoaudiosink element is not working."

Do you have any idea?
Thank you very much

Edited by OlegSuvorov at Mon Jan 26, 2015 07:35

Thanks for tutorial. I've done everything step by step, but still can't play accelerated video.

root@lemaker:~# DISPLAY=:1 gst-launch-1.0 filesrc location=testvideo.mp4 ! qtdemux ! vaapidecode ! vaapisink
libva: VA-API version 0.32.0
libva: User requested driver 'vdpau'
libva: Trying to open /usr/lib/arm-linux-gnueabihf/dri/vdpau_drv_video.so
[VDPAU SUNXI] VE version 0x1623 opened.
libva: va_openDriver() returns 0
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
Got context from element 'vaapidecode0': gst.vaapi.Display=context, display=(GstVaapiDisplay)NULL;
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:00.001004760
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...


Does anyone have an idea? I use BananaPi instead of BananaPro. Could it be a reason?
Thanks in advance.

P.S.
When I try to play the video via mplayer2
mplayer -vo vdpau testvideo.mp4


I recieve
vo: couldn't open the X11 display ()!
Error opening/initializing the selected video_out (-vo) device.

update
Mplayer works OK via
startx&
DISPLAY=:1 mplayer -vo vdpau -vc ffmpeg12vdpau,ffh264vdpau testvideo.mp4

I had to start a new X session for mplayer could use VDPAU.
But gstreamer pipeline still jams.

feraay  
can we use gstreamer or mplayer als external player for xbmc ?

Would be really cool

Everything worked fine until I got to the gstreamer vaapi plugin, when I run make I get the follwing:
gstvaapibufferproxy.c:24:29: fatal error: va/va_drmcommon.h: No such file or directory
compilation terminated.
Makefile:1115: recipe for target 'libgstvaapi_1.2_la-gstvaapibufferproxy.lo' failed
make[5]: *** [libgstvaapi_1.2_la-gstvaapibufferproxy.lo] Error 1
make[5]: Leaving directory '/home/bananapi/gstreamer-vaapi/gst-libs/gst/vaapi'
Makefile:947: recipe for target 'all' failed
make[4]: *** [all] Error 2
make[4]: Leaving directory '/home/bananapi/gstreamer-vaapi/gst-libs/gst/vaapi'
Makefile:357: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory '/home/bananapi/gstreamer-vaapi/gst-libs/gst'
Makefile:357: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/bananapi/gstreamer-vaapi/gst-libs'
Makefile:408: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/bananapi/gstreamer-vaapi'
Makefile:339: recipe for target 'all' failed
make: *** [all] Error 2

Same problem for me, all is ok until "fatal error" ...
So i'm waiting for help too

You have to log in before you can reply Login | Sign Up

Points Rules