[Howto] Odroid XU3/4 using the hardware encoder

Test and fix the Kernel 4.14 features

Moderators: mdrjr, odroid

[Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Mon Oct 31, 2016 9:33 pm

Regular users on the forum might already know that memeka has managed to use the hardware video encoder on the XU4 by using a mainline kernel (4.8.x) . Here are the steps on how you can achieve the same thing:

Before you begin - this is a tutorial designed for medium/advanced users and if things go wrong you might have an unbootable system. It might be wise to make a backup before beginning: viewtopic.php?t=22930 (shameless plug)

1. Install a mainline kernel that supports the MFC encoder. The instructions here use @elatllat's branch (https://github.com/Dmole/linux.git), but also mdrjr is working on a branch of his own (https://github.com/mdrjr/linux) and so is memeka (https://github.com/mihailescu2m/linux/c ... dxu3-4.9.y). You can use my kernel config (which tries to add all of HardKernel's modules), but you can modify it to fit your needs http://pastebin.com/7YnakKmP, or you can use whatever defconfig comes with the kernel you chose.
*** NOTE: the kernel does not support HMP (big.LITTLE extensions) and treats all cores as equal. This is because HMP patches are unstable and can lock up the system. Consequently, overall system performance will be lower than when using Kernel 3.10 ***
*** NOTE2: Also, for XU4 sound over HDMI will no longer work with this kernel! ***

I have added the kernel compilation procedure here for convenience, but you should read/discuss the official kernel compilation thread here: viewtopic.php?f=95&t=23163 or this guide: https://github.com/umiddelb/armhf/wiki/ ... ARM-device

a) Make a copy of your existing kernel, initrd, dtb and boot.ini:
Code: Select all
$ cd /media/boot
$ sudo -i
# cp zImage zImage-3
# cp uInitrd uInitrd-3
# cp exynos5422-odroidxu3.dtb exynos5422-odroidxu3-3.dtb
# cp boot.ini boot3.ini

Edit boot3.ini to point to the newly copied files by appending -3 to the name of the zImage, uInitrd and dtb. By replacing the stock boot.ini with this modified boot.ini you will be able to boot your old kernel in case of problems.

b) Download the new kernel
Code: Select all
$ sudo apt-get -y install bc curl gcc git libncurses5-dev lzop make u-boot-tools dos2unix
$ git clone --depth 1 -b odroidxu4-mihailescu2m-4.9 https://github.com/Dmole/linux.git linux
$ cd linux/
$ make odroidxu4_defconfig

Optionally get my config which supports most of the USB peripherals (TV tuners, sound cards, wifi cards) and a lot of networking modules (LXC support, VLANs, iptables).
Code: Select all
$ wget http://pastebin.com/raw/7YnakKmP -O .config
$ dos2unix .config

c) Next compile the kernel
Code: Select all
$ make menuconfig
$ make -j 8 zImage dtbs modules
$ kver=`make kernelrelease`
$ sudo cp arch/arm/boot/zImage arch/arm/boot/dts/exynos5422-odroidxu[34].dtb /media/boot
$ sudo cp .config /media/boot/config
$ sudo make INSTALL_MOD_STRIP=1 modules_install
$ sudo make firmware_install
$ sudo cp .config /boot/config-${kver}
$ cd /boot
$ sudo update-initramfs -c -k ${kver}
$ sudo mkimage -A arm -O linux -T ramdisk -a 0x0 -e 0x0 -n initrd.img-${kver} -d initrd.img-${kver} uInitrd-${kver}
$ sudo cp uInitrd-${kver} /media/boot/uInitrd

Next modify /media/boot/boot.ini and load exynos5422-odroidxu4.dtb instead of exynos5422-odroidxu3.dtb and save boot.ini.

d) Shut down and unplug HDMI and power. Without this step when you boot with the new kernel you will not have USB3 bus and onboard networking! This is needed only when switching between 3.x and 4.x kernels as far as I've seen.

Optionally - if you intend to run with a custom kernel from now on it's best to mark linux-image-xu3, linux-headers-xu3 and bootini as manual so that they won't be overwritten on subsequent package updates:
Code: Select all
sudo apt-mark hold linux-image-xu3 linux-headers-xu3 bootini


Using FFMPEG
2. Now that the kernel is ready, compile/install a custom ffmpeg which supports the hardware encoder
a) Compile your own ffmpeg
Code: Select all
#debian build tools
$ sudo apt-get install build-essential fakeroot devscripts libchromaprint-dev librubberband-dev libjs-bootstrap
#get the patched ffmpeg version
$ git clone -b v4l2_m2m-3.0.2 --depth=1 https://github.com/mihailescu2m/FFmpeg.git
# install ffmpeg's build dependencies (~190 packages)
$ sudo apt-get build-dep ffmpeg
#build ffmpeg as deb packages with no checks (some checks fail)
$ cd FFmpeg/
$ DEB_BUILD_OPTIONS="nocheck" debuild -b -uc -us

When building is done you should have 23 deb packages one level up (in the same directory as FFmpeg). You can download these packages pre-compiled from here: http://www.mediafire.com/?l39zeyy4r172m

b) Install the packages:
Code: Select all
$ cd ../
$ sudo dpkg -i *.deb

This should replace any system-installed ffmpeg build with this ffmpeg which supports the hardware encoder.

If you plan on keeping using these packages you should mark them as manual so that they are not overwritten by future system updates:
Code: Select all
sudo apt-mark hold ffmpeg-doc ffmpeg libav-tools libavcodec-dev libavcodec-extra57 libavcodec-extra libavcodec57 libavdevice-dev libavdevice57 libavfilter-dev libavfilter6 libavformat-dev libavformat57 libavresample-dev libavresample3 libavutil-dev libavutil55 libpostproc-dev libpostproc54 libswresample-dev libswresample2 libswscale-dev libswscale4


3. Use the hardware encoder when transcoding (examples):
Note, depending on what you want to transform with ffmpeg you might get better or worse framerate. For example, changing the output fps of a video cuts off about 20-30fps from encoding time. The examples below do not change the fps.
Code: Select all
# encode video only, about 50fps (max)
$ ffmpeg -i big_buck_bunny_720p_h264.mov -acodec aac -vcodec h264 -b:v 2M -pix_fmt nv21 bbb.mp4
# encode video only, about 110fps (max)
$ ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -r 24 -i - -an  -vcodec h264 -b:v 2M -profile:v 10 -pix_fmt nv21 bbb.mp4
#encode video and audio, about 75fps (max)
$ ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -r 24 -i - -i big_buck_bunny_720p_h264.mov -map 0:v:0 -vcodec h264 -b:v 2M -profile:v 10 -pix_fmt nv21  -map 1:a:0 -c:a:1 aac bbb.mp4

The encoder automatically selects h264_v4l2m2m which does the hardware encoding:
Code: Select all
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
  Stream #0:1 -> #0:1 (ac3 (native) -> aac (native))


If you get the error:
Code: Select all
[h264_v4l2m2m @ 0xf3fa0] H264 codec detected, init annexb converter
[h264_v4l2m2m @ 0xf3fa0] Device path not set, probing /dev/video*
[h264_v4l2m2m @ 0xf3fa0] exynos-gsc.1:m2m is not the one we want
[h264_v4l2m2m @ 0xf3fa0] exynos-gsc.0:m2m is not the one we want
[h264_v4l2m2m @ 0xf3fa0] s5p-mfc-dec is not the one we want
[h264_v4l2m2m @ 0xf3fa0] Could not find a valid device

Make sure the user you are running ffmpeg with is part of the video group:
Code: Select all
odroid@odroid:~$ id
uid=1000(odroid) gid=1000(odroid) groups=1000(odroid),4(adm),20(dialout),24(cdrom),27(sudo),30(dip),44(video),46(plugdev),115(lpadmin),116(lightdm)


Sample output:
Code: Select all
adrianp@odroid:~> ffmpeg -i Sintel.2010.720p.mkv -acodec aac -vcodec h264 -b:v 2M  -pix_fmt nv21 sintel-encoded.mp4                                                                                       
ffmpeg version 3.0.2-1ubuntu4 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.2) 20160609
  configuration: --prefix=/usr --extra-version=1ubuntu4 --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --cc=cc --cxx=g++ --enable-gpl --enable-shared --d
isable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --
enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --
enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc139
4 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-chromaprint --enable-libx264
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=1ubuntu4 --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --cc=cc --cxx=g++ --enable-gpl --enabl
e-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-
libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-li
bopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-
libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --ena
ble-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-chromaprint --enable-libx264 --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avf
ormat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libvo_amrwbenc
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from 'Sintel.2010.720p.mkv':
  Metadata:
    encoder         : libebml v1.0.0 + libmatroska v1.0.0
    creation_time   : 2011-04-24 17:20:33
  Duration: 00:14:48.03, start: 0.000000, bitrate: 6071 kb/s
    Chapter #0:0: start 0.000000, end 103.125000
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 103.125000, end 148.667000
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 148.667000, end 349.792000
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 349.792000, end 437.208000
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 437.208000, end 472.075000
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 472.075000, end 678.833000
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 678.833000, end 744.083000
    Metadata:
      title           : Chapter 07
    Chapter #0:7: start 744.083000, end 888.032000
    Metadata:
      title           : Chapter 08
    Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709/unknown/unknown), 1280x544, SAR 1:1 DAR 40:17, 24 fps, 24 tbr, 1k tbn, 48 tbc
    Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb/s
    Metadata:
      title           : AC3 5.1 @ 640 Kbps
    Stream #0:2(ger): Subtitle: subrip
    Stream #0:3(eng): Subtitle: subrip
    Stream #0:4(spa): Subtitle: subrip
    Stream #0:5(fre): Subtitle: subrip
    Stream #0:6(ita): Subtitle: subrip
    Stream #0:7(dut): Subtitle: subrip
    Stream #0:8(pol): Subtitle: subrip
    Stream #0:9(por): Subtitle: subrip
    Stream #0:10(rus): Subtitle: subrip
    Stream #0:11(vie): Subtitle: subrip
Codec AVOption preset (Configuration preset) specified for output file #0 (sintel-encoded.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video
 streams) or that it is a private option of some encoder which was not actually used for any stream.
File 'sintel-encoded.mp4' already exists. Overwrite ? [y/N] y
[h264_v4l2m2m @ 0xf3fe0] H264 codec detected, init annexb converter
[h264_v4l2m2m @ 0xf3fe0] Device path not set, probing /dev/video*
[h264_v4l2m2m @ 0xf3fe0] exynos-gsc.1:m2m is not the one we want
[h264_v4l2m2m @ 0xf3fe0] exynos-gsc.0:m2m is not the one we want
[h264_v4l2m2m @ 0xf3fe0] Using device /dev/video1
Output #0, mp4, to 'sintel-encoded.mp4':
  Metadata:
    encoder         : Lavf57.25.100
    Chapter #0:0: start 0.000000, end 103.125000
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 103.125000, end 148.667000
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 148.667000, end 349.792000
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 349.792000, end 437.208000
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 437.208000, end 472.075000
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 472.075000, end 678.833000
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 678.833000, end 744.083000
    Metadata:
      title           : Chapter 07
    Chapter #0:7: start 744.083000, end 888.032000
    Metadata:
      title           : Chapter 08
    Stream #0:0(eng): Video: h264 (h264_v4l2m2m) ([33][0][0][0] / 0x0021), yuv420p, 1280x544 [SAR 1:1 DAR 40:17], q=2-31, 2000 kb/s, 24 fps, 12288 tbn, 24 tbc
    Metadata:
      encoder         : Lavc57.24.102 h264_v4l2m2m
    Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, 5.1(side), fltp, 341 kb/s
    Metadata:
      title           : AC3 5.1 @ 640 Kbps
      encoder         : Lavc57.24.102 aac
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
  Stream #0:1 -> #0:1 (ac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0xf3fe0] Performing useless memcpy() on output pool because buffers do not match
[h264_v4l2m2m @ 0xf3fe0] This could be avoided by using av_v4l_buffer_pool_get_buffer*() or av_v4l_buffer_pool_make_pipe()
[mp4 @ 0xb9c70] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 0xb9c70] Encoder did not produce proper pts, making some up.
[h264_v4l2m2m @ 0xf3fe0] No event occurred while waiting.01 bitrate=36881.3kbits/s speed=1.84x   
frame= 2027 fps= 44 q=-0.0 Lsize=  383559kB time=00:01:25.20 bitrate=36877.0kbits/s speed=1.84x   
video:379964kB audio:3551kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.011593%


Known issues
:

* All known issues have been solved. Yay!

Image


Using gstreamer
2. Compile gstreamer from memeka's branch
Code: Select all
$ apt-get install gstreamer1.0-plugins-bad
$ git clone https://github.com/mihailescu2m/gst-plugins-good
$ cd gst-plugins-good/
$ sudo apt-get install libgstreamer1.0-dev libgudev-1.0-dev libgstreamer-plugins-base1.0-dev dh-autoreconf automake autoconf libtool autopoint cdbs gtk-doc-tools libshout3-dev libaa1-dev libflac-dev libdv4-dev libdv-dev libgtk-3-dev libtag1-dev  libsoup2.4-dev gstreamer1.0-doc gstreamer1.0-plugins-base-doc
$ dpkg-buildpackage -us -uc -b -j4
$ cd ../
$ sudo dpkg -i gstreamer*.deb


Alternatively you can get the pre-built deb packages from here: https://www.mediafire.com/folder/5lz2po ... -odroidxu4
If you intend to keep these packages installed, mark them as manual so that they are not updated by apt:
Code: Select all
sudo apt-mark hold gstreamer1.0-plugins-good-dbg gstreamer1.0-plugins-good-doc gstreamer1.0-plugins-good gstreamer1.0-pulseaudio libgstreamer-plugins-good1.0-0 libgstreamer-plugins-good1.0-dev


To transcode something here's what you can try:
Identify which is the encoding and the decoding interfaces (they change after boot)
Code: Select all
$ decoder=`gst-inspect-1.0 | grep v4l2 | grep videodec | cut -d ":" -f 2`
$ encoder=`gst-inspect-1.0 | grep v4l2 | grep h264enc | cut -d ":" -f 2`
$ gst-launch-1.0 filesrc location=big_buck_bunny_720p_h264.mov ! qtdemux ! h264parse ! $decoder !  $encoder extra-controls="encode,h264_level=10,h264_profile=4,frame_level_rate_control_enable=1,video_bitrate=2097152" ! h264parse ! matroskamux ! filesink location=bbb.mkv
Last edited by mad_ady on Thu Dec 15, 2016 11:19 pm, edited 9 times in total.
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Mon Oct 31, 2016 10:41 pm

I will be participating, subscribed.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby OverSun » Tue Nov 01, 2016 2:59 am

If the colors on the top half are distorted (it's not really clear in this mostly black and white picture are they or not) - then the setup is wrong. Somewhere the codec is setup to receive YUV444 and YUV420 is fed. If colors are not distorted - the size of the UV planes during setup is wrong, should be two times bigger.
User avatar
OverSun
 
Posts: 1386
Joined: Mon Apr 29, 2013 5:12 pm
languages_spoken: english

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby elatllat » Tue Nov 01, 2016 3:22 am

  • The default /media/boot is kinda small, so I backup with cp /media/boot/* /boot/$(uname -r)/
  • Might as well use all cores with make -j 8

To make things more concise;
  • I just sudo -i for tasks that would otherwise be sudo heavy.
  • zImage dtbs modules is the default so not needed.
  • I'd use only one apt install commend
  • leave the kernel instructions on the kernel next thread.
elatllat
 
Posts: 1074
Joined: Tue Sep 01, 2015 8:54 am
languages_spoken: english
ODROIDs: XU4, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Tue Nov 01, 2016 3:42 am

Use gstreamer, ffmpeg code is not really ok atm :(
Bitrate - you need to pass a string with 2 values to v4l2. I figured out how to do that in gstreamer, don't know how to in ffmpeg...
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Tue Nov 01, 2016 3:58 am

@OverSun - I stopped looking at ffmpeg after I couldn't fix the annex-b h264 decoding issue.
I added the annex-b convertor here: https://github.com/mihailescu2m/FFmpeg/ ... dd52f421c3
But it's not working, can't figure out why :(
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Tue Nov 01, 2016 5:26 pm

elatllat wrote:
  • The default /media/boot is kinda small, so I backup with cp /media/boot/* /boot/$(uname -r)/
  • Might as well use all cores with make -j 8

To make things more concise;
  • I just sudo -i for tasks that would otherwise be sudo heavy.
  • zImage dtbs modules is the default so not needed.
  • I'd use only one apt install commend
  • leave the kernel instructions on the kernel next thread.


Thanks for the tips - I added them to the first post where applicable. However even if /media/boot is small, it's best suited for a backup kernel because it's easier to be accessed by a regular user who wants to recover and only has access to a Windows system.

OverSun wrote:If the colors on the top half are distorted (it's not really clear in this mostly black and white picture are they or not) - then the setup is wrong. Somewhere the codec is setup to receive YUV444 and YUV420 is fed. If colors are not distorted - the size of the UV planes during setup is wrong, should be two times bigger.

You were right. The encoder chose nv12 and produced an image like this:
Image

I forced a pix_fmt of nv21 and the image was correct:
Code: Select all
ffmpeg -i big_buck_bunny_720p_h264.mov -acodec aac -vcodec h264 -b:v 2M -pix_fmt nv21 bbb.mp4

Image
I updated the first post with this addition.

memeka wrote:Use gstreamer, ffmpeg code is not really ok atm :(
Bitrate - you need to pass a string with 2 values to v4l2. I figured out how to do that in gstreamer, don't know how to in ffmpeg...

I will try gstreamer as well. Unfortunately I don't "speak" gstreamer syntax and I could use a ffmpeg-to-gstreamer cheat sheet. :) Best I could find is this: http://wiki.oz9aec.net/index.php/Gstreamer_cheat_sheet

@memeka: I tried with your command referenced here: viewtopic.php?f=95&t=23163&start=50#p157279
but it fails:
Code: Select all
$ sudo apt-get install gstreamer1.0-plugins-bad
$ gst-launch-1.0 filesrc location=big_buck_bunny_720p_h264.mov ! qtdemux ! h264parse ! v4l2video2videodec !  v4l2video3h264enc extra-controls="encode,h264_level=10,h264_profile=4,frame_level_rate_control_enable=1,video_bitrate=2097152" ! h264parse ! matroskamux ! filesink location=bbb.mkv
WARNING: erroneous pipeline: no element "v4l2video2videodec"


I couldn't find anything related to v4l2video2videodec on the internets...
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Tue Nov 01, 2016 6:11 pm

You need my gst-plugins-good package.
Normally for decoding you only add a couple of flags to gst-plugins-good package in debian/rules
--enable-v4l2-probe
And
--without-libv4l2
Then make the gst-plugins-good package again with these new flags.
But for encoder there are more patches in my git repo...

Run gst-inspect-1.0 and you will see all available gst elements. It should dynamically create an element from /dev/video elements - MFC decoder can be assigned different number on boot. E.g. If mfc-dec is /dev/video0 then you have v4l2video0videodec
Gst-inspect-1.0 | grep v4l2 should show them all.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Tue Nov 01, 2016 6:14 pm

Erm I see I didn't put the gst sources on git...
Sorry will do tomorrow :)

Code: Select all
h264_level=10,h264_profile=4,frame_level_rate_control_enable=1,video_bitrate=209715

These are the v4l2 parameters for the encoder that need to be set... (there are even more actually, run v4l2-ctl on the encoder /dev/videoX to see them all)
If you can find a way to specify them in ffmpeg (should be a standard v4l2 thing inherited from source/sink v4l2) then you get a good compression... with ffmpeg :)
Last edited by memeka on Tue Nov 01, 2016 6:35 pm, edited 2 times in total.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Tue Nov 01, 2016 6:19 pm

Shouldn't that be
Code: Select all
v4l2 /dev/video2 h264enc ! v4l2 /dev/video3 videodec


*edit*
Ah you explained it.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Tue Nov 01, 2016 6:33 pm

@mad_ady can you try running v4l2-ctl -d /dev/videoENC --set-ctrl=h264_level=10
And then set-ctl for each control in that string, then try encoding again??
Maybe ffmpeg won't reset them ;)

Sorry for my formatting I'm on the phone :)
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Tue Nov 01, 2016 6:50 pm

Here goes:
Code: Select all
...
[h264_v4l2m2m @ 0xc1d50] H264 codec detected, init annexb converter
[h264_v4l2m2m @ 0xc1d50] Device path not set, probing /dev/video*
[h264_v4l2m2m @ 0xc1d50] exynos-gsc.1:m2m is not the one we want
[h264_v4l2m2m @ 0xc1d50] exynos-gsc.0:m2m is not the one we want
[h264_v4l2m2m @ 0xc1d50] Using device /dev/video1
...
$ sudo apt-get install v4l-utils
$ adrianp@odroid:~> v4l2-ctl -d /dev/video1  -l   

User Controls

error 22 getting ctrl Min Number of Output Buffers

Codec Controls

                 video_b_frames (int)    : min=0 max=2 step=1 default=0 value=0 flags=update
                 video_gop_size (int)    : min=0 max=65535 step=1 default=12 value=12
              video_gop_closure (bool)   : default=1 value=1
                  video_bitrate (int)    : min=1 max=1073741823 step=1 default=1 value=1
    number_of_intra_refresh_mbs (int)    : min=0 max=65535 step=1 default=0 value=0
frame_level_rate_control_enable (bool)   : default=0 value=0
           sequence_header_mode (menu)   : min=0 max=1 default=0 value=0
     h264_mb_level_rate_control (bool)   : default=0 value=0
       maximum_bytes_in_a_slice (int)    : min=1900 max=1073741823 step=1 default=1900 value=1900
       number_of_mbs_in_a_slice (int)    : min=1 max=65535 step=1 default=1 value=1
      slice_partitioning_method (menu)   : min=0 max=2 default=0 value=0
                vbv_buffer_size (int)    : min=0 max=65535 step=1 default=0 value=0
     horizontal_mv_search_range (int)    : min=16 max=128 step=16 default=32 value=32
       vertical_mv_search_range (int)    : min=16 max=128 step=16 default=32 value=32
                force_key_frame (button) : flags=write-only, execute-on-write
          h263_i_frame_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
          h263_p_frame_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
          h263_b_frame_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
          h263_minimum_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
          h263_maximum_qp_value (int)    : min=1 max=31 step=1 default=31 value=31
          h264_i_frame_qp_value (int)    : min=0 max=51 step=1 default=1 value=1
          h264_p_frame_qp_value (int)    : min=0 max=51 step=1 default=1 value=1
          h264_b_frame_qp_value (int)    : min=0 max=51 step=1 default=1 value=1
          h264_minimum_qp_value (int)    : min=0 max=51 step=1 default=1 value=1
          h264_maximum_qp_value (int)    : min=0 max=51 step=1 default=51 value=51
      h264_8x8_transform_enable (bool)   : default=0 value=0
           h264_cpb_buffer_size (int)    : min=0 max=65535 step=1 default=0 value=0
              h264_entropy_mode (menu)   : min=0 max=1 default=0 value=0
            h264_i_frame_period (int)    : min=0 max=65535 step=1 default=0 value=0
                     h264_level (menu)   : min=0 max=11 default=0 value=0
  h264_loop_filter_alpha_offset (int)    : min=-6 max=6 step=1 default=0 value=0
   h264_loop_filter_beta_offset (int)    : min=-6 max=6 step=1 default=0 value=0
          h264_loop_filter_mode (menu)   : min=0 max=2 default=0 value=0
                   h264_profile (menu)   : min=0 max=16 default=0 value=0
           vertical_size_of_sar (int)    : min=0 max=65535 step=1 default=0 value=0
         horizontal_size_of_sar (int)    : min=0 max=65535 step=1 default=0 value=0
        aspect_ratio_vui_enable (bool)   : default=0 value=0
           vui_aspect_ratio_idc (menu)   : min=0 max=17 default=0 value=0
         mpeg4_i_frame_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
         mpeg4_p_frame_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
         mpeg4_b_frame_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
         mpeg4_minimum_qp_value (int)    : min=1 max=31 step=1 default=1 value=1
         mpeg4_maximum_qp_value (int)    : min=0 max=51 step=1 default=51 value=51
                    mpeg4_level (menu)   : min=0 max=7 default=0 value=0
                  mpeg4_profile (menu)   : min=0 max=1 default=0 value=0
    quarter_pixel_search_enable (bool)   : default=0 value=0
       vpx_number_of_partitions (intmenu): min=0 max=3 default=0 value=0
vpx_intra_mode_decision_disable (int)    : min=0 max=1 step=1 default=0 value=0
     vpx_no_of_refs_for_p_frame (intmenu): min=0 max=1 default=0 value=0
    vpx_loop_filter_level_range (int)    : min=0 max=63 step=1 default=0 value=0
  vpx_deblocking_effect_control (int)    : min=0 max=7 step=1 default=0 value=0
vpx_golden_frame_refresh_period (int)    : min=0 max=65535 step=1 default=0 value=0
     vpx_golden_frame_indicator (menu)   : min=0 max=1 default=0 value=0
           vpx_minimum_qp_value (int)    : min=0 max=11 step=1 default=0 value=0
           vpx_maximum_qp_value (int)    : min=0 max=127 step=1 default=127 value=127
           vpx_i_frame_qp_value (int)    : min=0 max=127 step=1 default=10 value=10
           vpx_p_frame_qp_value (int)    : min=0 max=127 step=1 default=10 value=10
                    vpx_profile (int)    : min=0 max=3 step=1 default=0 value=0
              frame_skip_enable (menu)   : min=0 max=2 default=0 value=0
               force_frame_type (menu)   : min=0 max=2 default=0 value=0
         padding_control_enable (bool)   : default=0 value=0
        padding_color_yuv_value (int)    : min=0 max=33554431 step=1 default=0 value=0
        fixed_target_bit_enable (bool)   : default=0 value=0
    rate_control_reaction_coeff (int)    : min=1 max=65535 step=1 default=1 value=1
  h264_activity_reg_adaptive_rc (bool)   : default=0 value=0
      h264_dark_reg_adaptive_rc (bool)   : default=0 value=0
    h264_smooth_reg_adaptive_rc (bool)   : default=0 value=0
    h264_static_reg_adaptive_rc (bool)   : default=0 value=0
    the_number_of_ref_pic_for_p (int)    : min=1 max=2 step=1 default=1 value=1
$ v4l2-ctl -d /dev/video1  -l | grep bit
                  video_bitrate (int)    : min=1 max=1073741823 step=1 default=1 value=1
        fixed_target_bit_enable (bool)   : default=0 value=0
$ v4l2-ctl -d /dev/video1  -l | grep h264_level
                     h264_level (menu)   : min=0 max=11 default=0 value=0
$ sudo v4l2-ctl -d /dev/video1  --set-ctrl=h264_level=10
$ v4l2-ctl -d /dev/video1  -l | grep h264_level
                     h264_level (menu)   : min=0 max=11 default=0 value=0
$ sudo v4l2-ctl -d /dev/video1  --set-ctrl=video_bitrate=2048000
$ v4l2-ctl -d /dev/video1  -l | grep video_bitrate
                  video_bitrate (int)    : min=1 max=1073741823 step=1 default=1 value=1


It doesn't seem to stick... The encoded file is still high-bitrate... Maybe I'm doing something wrong when setting the parameters via v4l2-ctl
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Tue Nov 01, 2016 7:05 pm

I see for webcam is something like
v4l2-ctl --set-ctrl saturation=32

So try without the first "="? :D
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Tue Nov 01, 2016 7:48 pm

Code: Select all
adrianp@odroid:~> sudo v4l2-ctl -d /dev/video1  --set-ctrl video_bitrate=2048000
adrianp@odroid:~> v4l2-ctl -d /dev/video1  -l | grep video_bitrate
                  video_bitrate (int)    : min=1 max=1073741823 step=1 default=1 value=1
adrianp@odroid:~>
adrianp@odroid:~>
adrianp@odroid:~>
adrianp@odroid:~> sudo v4l2-ctl -d /dev/video1  --set-ctrl h264_level=10
adrianp@odroid:~> v4l2-ctl -d /dev/video1  -l | grep h264_level
                     h264_level (menu)   : min=0 max=11 default=0 value=0
adrianp@odroid:~> sudo v4l2-ctl -d /dev/video1  --set-ctrl h264_level 10
control 'h264_level' without '='
1 adrianp@odroid:~> v4l2-ctl -d /dev/video1  -l | grep h264_level
                     h264_level (menu)   : min=0 max=11 default=0 value=0
adrianp@odroid:~> sudo v4l2-ctl -d /dev/video1  --set-ctrl h264_level=3
adrianp@odroid:~> v4l2-ctl -d /dev/video1  -l | grep h264_level
                     h264_level (menu)   : min=0 max=11 default=0 value=0
adrianp@odroid:~> sudo v4l2-ctl -d /dev/video1  --set-ctrl h264_level=-4
VIDIOC_S_EXT_CTRLS: failed: Numerical result out of range
Error setting controls: Numerical result out of range
255 adrianp@odroid:~> sudo v4l2-ctl -d /dev/video1  --set-ctrl h264_level=10
adrianp@odroid:~> v4l2-ctl -d /dev/video1  -l | grep h264_level
                     h264_level (menu)   : min=0 max=11 default=0 value=0

No dice yet.
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 02, 2016 4:42 am

gstreamer code: https://github.com/mihailescu2m/gst-plugins-good

just run dpkg-buildpackage -us -uc -b -j4 and install.
initial commit is the ubuntu source; commits could pe picked on newer gstreamer, if interested.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 02, 2016 5:10 am

@mad_ady
I had a look at the ffmpeg code. Actually I think it can set the bit_rate from ffmpeg, BUT it doesn't know to set "frame_level_rate_control_enable=1", which means that it ignores the bit_rate you set :)
I will try to patch the code at some time in the future.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Wed Nov 02, 2016 6:24 am

memeka wrote:gstreamer code: https://github.com/mihailescu2m/gst-plugins-good

just run dpkg-buildpackage -us -uc -b -j4 and install.
initial commit is the ubuntu source; commits could pe picked on newer gstreamer, if interested.

How are you building this on Jessie? All the dev libs are too old.

*edit*
You are using Ubuntu apparently, disregard.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 02, 2016 6:55 am

Debian: apt-get source gstreamer1.0-plugins-good
Then apply all those patches then build deb.
Or just update the libs requirements from the Debian folder in my git
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Wed Nov 02, 2016 8:24 am

memeka wrote:Debian: apt-get source gstreamer1.0-plugins-good
Then apply all those patches then build deb.
Or just update the libs requirements from the Debian folder in my git

I'm beginning to find Jessie long in the tooth when it comes to any type of video related development, but it's great as a server.

I think I will dust off my old XU3 and install Ubuntu minimal on it to use for this.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 02, 2016 9:04 am

rooted wrote:
memeka wrote:Debian: apt-get source gstreamer1.0-plugins-good
Then apply all those patches then build deb.
Or just update the libs requirements from the Debian folder in my git

I'm beginning to find Jessie long in the tooth when it comes to any type of video related development, but it's great as a server.

I think I will dust off my old XU3 and install Ubuntu minimal on it to use for this.


I'm using Debian stretch atm on my XU4 for Gnome3 and video stuff. I moved to it from Ubuntu 16.10 since it has more updated packages, like Gnome 3.22 and you can test wayland RCs. I've been hunting for a long time for an EGL accelerated browser for wayland, but none is there yet :(. Gnome-web is almost there, but I think it hits a driver bug because it creates nested wayland compositors... other stuff on XU4 is almost there too... already got mpv working nicely, gst encoding (soon ffmpeg too), ...

Don't know how plex uses ffmpeg, but emby just creates a string with the parameters for it. So if you use emby, it's trivial to create a bash script named "ffmpeg" that calls gstreamer to do hw-accelerated transcoding on the fly :)
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Wed Nov 02, 2016 9:34 am

You have an image or did you just upgrade Jessie?
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 02, 2016 9:45 am

@mad_ady can you try this:

at https://github.com/mihailescu2m/FFmpeg/ ... _enc.c#L34 is a macro that is used to set v4l2 controls.
as you can see at https://github.com/mihailescu2m/FFmpeg/ ... enc.c#L102 it's actually setting bit_rate.

but it's not setting rc_enable.
so, before L102, can you add:
Code: Select all
if (avctx->bit_rate > 1) SET_V4L_EXT_CTRL(value, V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, 1, V4L2_CTRL_CLASS_MPEG, "enable bitrate control");
av_log(avctx, AV_LOG_ERROR, "Enabling bitrate control if required rate %d > 1\n", avctx->bit_rate);

Just to be sure, this will print out the selected bitrate that makes it into the encoder :D

One other note:
https://github.com/mihailescu2m/FFmpeg/ ... enc.c#L108 will set the H264 profile. See the list of profiles here: https://github.com/mihailescu2m/FFmpeg/ ... _enc.c#L48
I recommend V4L2_MPEG_VIDEO_H264_PROFILE_HIGH. Don't know how to set it with ffmpeg, check ffmpeg options :) This is equivalent to h264_profile=4 in the string above.
There's no level set there, so I recommend adding after https://github.com/mihailescu2m/FFmpeg/ ... enc.c#L112
Code: Select all
SET_V4L_EXT_CTRL(value, V4L2_CID_MPEG_VIDEO_H264_LEVEL, 10, V4L2_CTRL_CLASS_MPEG, "h264 profile");

which is the equivalent of h264_level=10. 10 is V4L2_MPEG_VIDEO_H264_LEVEL_3_2 => http://osxr.org:8080/linux/source/inclu ... controls.h line 395 has a list of levels, I think MFC supports max level 4.0 but I remember having some issues in gst with it, so maybe use 3.2. Maybe @mdrjr can help with some documentation about highest profile and level :)

After these changes, recompile, install and pray it works :)
Last edited by memeka on Wed Nov 02, 2016 9:56 am, edited 2 times in total.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 02, 2016 9:47 am

rooted wrote:You have an image or did you just upgrade Jessie?

I did one with debootstrap. I will release an image soon, just need to clean up some stuffs.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Wed Nov 02, 2016 11:23 am

memeka wrote:
rooted wrote:You have an image or did you just upgrade Jessie?

I did one with debootstrap. I will release an image soon, just need to clean up some stuffs.

Couldn't wait, trying an upgrade...fingers crossed.

I must have HW encoding, I'm in the US so my tvheadend recordings are mpeg2 and take up entirely too much room.

A single 30 minute show (720p) is 3.3 gigabyte.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Wed Nov 02, 2016 3:36 pm

Thank you memeka for your help. I will look into it and recompile ffmpeg with your changes.

However, it's strange that I can't set those controls with v4l2-ctl. I did a strace and it fails at some point:
Code: Select all
adrianp@odroid:~> sudo strace v4l2-ctl -d /dev/video3 --set-ctrl=frame_level_rate_control_enable=1                                                                                                             
execve("/usr/bin/v4l2-ctl", ["v4l2-ctl", "-d", "/dev/video3", "--set-ctrl=frame_level_rate_cont"...], [/* 16 vars */]) = 0
brk(NULL)                               = 0x5b000
uname({sysname="Linux", nodename="odroid", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f4a000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=132000, ...}) = 0
mmap2(NULL, 132000, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6f04000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0000\27\0\0004\0\0\0"..., 512) = 512
lseek(3, 21228, SEEK_SET)               = 21228
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1280) = 1280
lseek(3, 20844, SEEK_SET)               = 20844
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0644, st_size=22508, ...}) = 0
mmap2(NULL, 86544, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6eee000
mprotect(0xb6ef3000, 61440, PROT_NONE)  = 0
mmap2(0xb6f02000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4000) = 0xb6f02000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib/arm-linux-gnueabihf/libv4l2.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\30\23\0\0004\0\0\0"..., 512) = 512
lseek(3, 42448, SEEK_SET)               = 42448
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1000) = 1000
lseek(3, 42124, SEEK_SET)               = 42124
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0644, st_size=43448, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f49000
mmap2(NULL, 107696, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6ed3000
mprotect(0xb6eda000, 61440, PROT_NONE)  = 0
mmap2(0xb6ee9000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0xb6ee9000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib/arm-linux-gnueabihf/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\270\305\6\0004\0\0\0"..., 512) = 512
lseek(3, 1030776, SEEK_SET)             = 1030776
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1280) = 1280
lseek(3, 1030200, SEEK_SET)             = 1030200
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0644, st_size=1032056, ...}) = 0
mmap2(NULL, 1104000, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6dc5000
mprotect(0xb6ebb000, 61440, PROT_NONE)  = 0
mmap2(0xb6eca000, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf5000) = 0xb6eca000
mmap2(0xb6ed1000, 6272, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6ed1000
close(3)                                = 0                                                                                                                                                          [129/1605]
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\230\321\0\0004\0\0\0"..., 512) = 512
lseek(3, 98252, SEEK_SET)               = 98252
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1120) = 1120
lseek(3, 97920, SEEK_SET)               = 97920
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0644, st_size=99372, ...}) = 0
mmap2(NULL, 163512, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6d9d000
mprotect(0xb6db5000, 61440, PROT_NONE)  = 0
mmap2(0xb6dc4000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0xb6dc4000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\331i\1\0004\0\0\0"..., 512) = 512
lseek(3, 894132, SEEK_SET)              = 894132
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 2960) = 2960
lseek(3, 888324, SEEK_SET)              = 888324
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\3\f"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0755, st_size=897092, ...}) = 0
mmap2(NULL, 963968, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6cb1000
mprotect(0xb6d87000, 65536, PROT_NONE)  = 0
mmap2(0xb6d97000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xd6000) = 0xb6d97000
mmap2(0xb6d9a000, 9600, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6d9a000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\215F\0\0004\0\0\0"..., 512) = 512
lseek(3, 108304, SEEK_SET)              = 108304
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1640) = 1640
lseek(3, 70048, SEEK_SET)               = 70048
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0755, st_size=109944, ...}) = 0
mmap2(NULL, 143940, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6c8d000
mprotect(0xb6c9e000, 61440, PROT_NONE)  = 0
mmap2(0xb6cad000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10000) = 0xb6cad000
mmap2(0xb6caf000, 4676, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6caf000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0`\t\0\0004\0\0\0"..., 512) = 512
lseek(3, 8652, SEEK_SET)                = 8652
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1120) = 1120
lseek(3, 8328, SEEK_SET)                = 8328
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0644, st_size=9772, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f48000
mmap2(NULL, 73912, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6c7a000
mprotect(0xb6c7c000, 61440, PROT_NONE)  = 0
mmap2(0xb6c8b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0xb6c8b000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib/arm-linux-gnueabihf/libv4lconvert.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\360\34\0\0004\0\0\0"..., 512) = 512
lseek(3, 111440, SEEK_SET)              = 111440
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1040) = 1040
lseek(3, 111100, SEEK_SET)              = 111100
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0644, st_size=112480, ...}) = 0
mmap2(NULL, 513080, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6bfc000
mprotect(0xb6c16000, 61440, PROT_NONE)  = 0
mmap2(0xb6c25000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19000) = 0xb6c25000
mmap2(0xb6c28000, 332856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6c28000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0X<\0\0004\0\0\0"..., 512) = 512
lseek(3, 423356, SEEK_SET)              = 423356
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1200) = 1200
lseek(3, 422004, SEEK_SET)              = 422004
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\4\22"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0644, st_size=424556, ...}) = 0
mmap2(NULL, 487548, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6b84000
mprotect(0xb6beb000, 61440, PROT_NONE)  = 0
mmap2(0xb6bfa000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x66000) = 0xb6bfa000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/usr/lib/arm-linux-gnueabihf/libjpeg.so.8", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\220*\0\0004\0\0\0"..., 512) = 512
lseek(3, 160736, SEEK_SET)              = 160736
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1080) = 1080
lseek(3, 160384, SEEK_SET)              = 160384
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0057-A\0\6\n\7A\10\1\t\2\n\3\f"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0644, st_size=161816, ...}) = 0
mmap2(NULL, 225924, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6b4c000
mprotect(0xb6b73000, 61440, PROT_NONE)  = 0
mmap2(0xb6b82000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0xb6b82000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f47000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f46000
set_tls(0xb6f464c0, 0xb6f46bb8, 0xb6f4d050, 0xb6f464c0, 0xb6f4d050) = 0
mprotect(0xb6d97000, 8192, PROT_READ)   = 0
mprotect(0xb6b82000, 4096, PROT_READ)   = 0
mprotect(0xb6bfa000, 4096, PROT_READ)   = 0
mprotect(0xb6cad000, 4096, PROT_READ)   = 0
mprotect(0xb6f02000, 4096, PROT_READ)   = 0
mprotect(0xb6c25000, 8192, PROT_READ)   = 0
mprotect(0xb6c8b000, 4096, PROT_READ)   = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f45000
mprotect(0xb6eca000, 20480, PROT_READ)  = 0
mprotect(0xb6ee9000, 4096, PROT_READ)   = 0
mprotect(0x4d000, 4096, PROT_READ)      = 0
mprotect(0xb6f4c000, 4096, PROT_READ)   = 0
munmap(0xb6f04000, 132000)              = 0
set_tid_address(0xb6f46068)             = 527
set_robust_list(0xb6f46070, 12)         = 0
rt_sigaction(SIGRTMIN, {0xb6c911e5, [], SA_RESTORER|SA_SIGINFO, 0xb6cd6261}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0xb6c91285, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0xb6cd6261}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
ugetrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
brk(NULL)                               = 0x5b000
brk(0x80000)                            = 0x80000
open("/dev/video3", O_RDWR)             = 3
ioctl(3, VIDIOC_QUERYCAP, {driver="s5p-mfc", card="s5p-mfc-enc", bus_info="platform:11000000.codec:", version=4.8.6, capabilities=V4L2_CAP_VIDEO_M2M_MPLANE|V4L2_CAP_STREAMING|V4L2_CAP_DEVICE_CAPS|0x200000, d
evice_caps=V4L2_CAP_VIDEO_M2M_MPLANE|V4L2_CAP_STREAMING|0x200000}) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf038) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = 0
ioctl(3, VIDIOC_QUERY_EXT_CTRL, 0xbe9cf120) = -1 EINVAL (Invalid argument)
ioctl(3, VIDIOC_S_EXT_CTRLS, {ctrl_class=V4L2_CTRL_CLASS_MPEG, count=1, controls=[{id=0x9909d7 /* V4L2_CID_??? */, size=0, value=1, value64=1}]} => {ctrl_class=V4L2_CTRL_CLASS_MPEG, count=1, controls=[{id=0x
9909d7 /* V4L2_CID_??? */, size=0, value=1, value64=1}]}) = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++
adrianp@odroid:~> v4l2-ctl -L -d /dev/video3 | grep frame_level_rate_control_enabl
frame_level_rate_control_enable (bool)   : default=0 value=0



Setting it through ffmpeg might result in the same problem. But I will report back.
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Thu Nov 03, 2016 8:29 pm

A small update. I've added the patches mentioned by memeka into ffmpeg and recompiled it. This time the encoding respects the imposed bitrate (tested with 2Mbps), however video output is "black". Here are some commands tried for reference and some output:

Code: Select all
ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -i - -an  -vcodec h264 -b:v 2M -pix_fmt nv21 bbb.mp4
ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -i - -an  -vcodec h264 -b:v 2M -profile:v 10 -pix_fmt nv21 bbb.mp4

http://pastebin.com/K2jGALGx

Edit: I also tried compiling gst plugins from memeka's repo:
Code: Select all
$ git clone https://github.com/mihailescu2m/gst-plugins-good
$ cd gst-plugins-good/
$ sudo apt-get install libgstreamer1.0-dev libgudev-1.0-dev libgstreamer-plugins-base1.0-dev dh-autoreconf automake autoconf libtool autopoint cdbs gtk-doc-tools libshout3-dev libaa1-dev libflac-dev libdv4-dev libdv-dev libgtk-3-dev libtag1-dev  libsoup2.4-dev gstreamer1.0-doc gstreamer1.0-plugins-base-doc
$ dpkg-buildpackage -us -uc -b -j4

But it eventually fails with:
Code: Select all
/bin/bash ../../libtool  --tag=CC --tag=disable-static  --mode=compile gcc -DHAVE_CONFIG_H -I. -I../..   -Wdate-time -D_FORTIFY_SOURCE=2 -pthread -I/usr/include/gstreamer-1.0 -I/usr/lib/arm-linux-gnueabihf/g
streamer-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -pthread -I/usr/include/gstreamer-1.0 -I/usr/lib/arm-linux-gnueabihf/gstreamer-1.0/include -I/usr/include/glib-2.0
 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I../../gst-libs -pthread -I/usr/include/gstreamer-1.0 -I/usr/lib/arm-linux-gnueabihf/gstreamer-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnuea
bihf/glib-2.0/include -DGST_USE_UNSTABLE_API  -DG_THREADS_MANDATORY -DG_DISABLE_CAST_CHECKS -Wall -Wdeclaration-after-statement -Wvla -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes -Wredundant-d
ecls -Wwrite-strings -Wold-style-definition -Waggregate-return -Winit-self -Wmissing-include-dirs -Waddress -Wno-multichar -Wnested-externs   -g      -I/usr/include/gudev-1.0 -I/usr/include/glib-2.0 -I/usr/l
ib/arm-linux-gnueabihf/glib-2.0/include -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wno-error -c -o libgstvideo4linux2_la-gstv4l2videoenc.lo `test -f 'gstv4l2videoenc.c' || echo '
./'`gstv4l2videoenc.c
gstv4l2videodec.c:48:3: error: conflicting types for 'GstV4l2VideoCData'
 } GstV4l2VideoCData;
   ^
In file included from ./gstv4l2object.h:28:0,
                 from gstv4l2videodec.h:30,
                 from gstv4l2videodec.c:32:
./v4l2-utils.h:45:35: note: previous declaration of 'GstV4l2VideoCData' was here
 typedef struct _GstV4l2VideoCData GstV4l2VideoCData;
                                   ^
Makefile:873: recipe for target 'libgstvideo4linux2_la-gstv4l2videodec.lo' failed
make[4]: *** [libgstvideo4linux2_la-gstv4l2videodec.lo] Error 1



is it because I'm doing this on Ubuntu 16.04?
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Fri Nov 04, 2016 2:18 pm

It looks like my git misses one commit: http://paste.debian.net/892261/

For a few days, you can just download the ubuntu debs from:
https://transfer.sh/dFQpn/gstreamer1.0- ... -armhf.deb
https://transfer.sh/13Y26M/libgstreamer ... -armhf.deb
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Fri Nov 04, 2016 5:45 pm

A little update. I applied the patch and now gstreamer plugis compiles fine. However, after transcoding I get the same "black screen" result in the encoded video. This indicates that ffmpeg works and something else broke at the kernel level (I'm running 4.8.6-dmole-memeka-5-merged-g84b59b5). I will take the discussion up with the kernel maintainer to see if they can reproduce the issues.

I have updated the first post with information on how to get gstreamer working on the XU3/4 to use for transcoding.
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Mon Nov 07, 2016 5:36 pm

Another update: I reverted back to kernel 4.8.5 and tried encoding again with ffmpeg and gstreamer and again I get a black screen encoded.
Next I'll try to compile memeka's older kernel and see if I get correct output from that one.
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Mon Nov 07, 2016 10:34 pm

Another update: I've tried with memeka's kernel and my config and I still get black output with both ffmpeg and gstreamer. Also I tired with memeka's kernel and his config (http://paste.debian.net/plain/791598) and still get the same result. The kernel is 4.8.0-rc1-next-20160809-memeka2-g09f0834 for reference.

So, it doesn't look like a kernel issue, but a system/ffmpeg/gstreamer issue?
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Tue Nov 08, 2016 4:45 am

have you tried gstreamer after a fresh reboot? (such that ffmpeg will not try and set some encoder param?)
also, can you post the encoder parameters? (from v4l2-ctl); is there any that is not default value?
lastly, can you try and play the encoded video on some other computer? and can you run media-info on the encoded video and check the metadata?
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Tue Nov 08, 2016 7:48 pm

Ok, final update on the hardware encoding debacle. Well, it was all my fault. I transcoded on the XU4 and used scp to move the file to my work PC and view it from there. For some odd reason my PC decided to play back everything with a black screen and I figured that out only when the same problem appeared on C2 encodings as well. After I rebooted the PC I got great results with both memeka's original kernel and dmole's kernel.

Encoding with ffmpeg:
Code: Select all
$ uname -a
Linux odroid 4.8.6-dmole-memeka-5-merged-g84b59b5 #1 SMP PREEMPT Tue Nov 1 14:47:21 EET 2016 armv7l armv7l armv7l GNU/Linux
$ ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -i - -an  -vcodec h264 -b:v 2M -profile:v 10 -pix_fmt nv21 bbb.mp4


Encoding with gstreamer:
Code: Select all
$ uname -a
Linux odroid 4.8.6-dmole-memeka-5-merged-g84b59b5 #1 SMP PREEMPT Tue Nov 1 14:47:21 EET 2016 armv7l armv7l armv7l GNU/Linux
$ decoder=`gst-inspect-1.0 | grep v4l2 | grep videodec | cut -d ":" -f 2`; encoder=`gst-inspect-1.0 | grep v4l2 | grep h264enc | cut -d ":" -f 2`; gst-launch-1.0 filesrc location=big_buck_bunny_720p_h264.mov ! qtdemux ! h264parse ! $decoder !  $encoder extra-controls="encode,h264_level=10,h264_profile=4,frame_level_rate_control_enable=1,video_bitrate=2097152" ! h264parse ! matroskamux ! filesink location=bbb.mkv


Results:
Code: Select all
$ ls -lh bbb.*
-rw-rw-r-- 1 adrianp adrianp 129M Nov  8 11:27 bbb.mkv
-rw-rw-r-- 1 adrianp adrianp 169M Nov  8 11:19 bbb.mp4
$ mediainfo bbb.mkv
General
Unique ID                                : 153395687287752748989382642649008779630 (0x7366EF4BB16BFFD17446BC9B32E9316E)
Complete name                            : bbb.mkv
Format                                   : Matroska
Format version                           : Version 2
File size                                : 128 MiB
Duration                                 : 9mn 56s
Overall bit rate                         : 1 804 Kbps
Encoded date                             : UTC 2016-11-08 09:20:57
Writing application                      : GStreamer Matroska muxer
Writing library                          : GStreamer matroskamux version 1.8.2

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3.2
Format settings, CABAC                   : No
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=12
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 9mn 56s
Bit rate                                 : 1 768 Kbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.080
Stream size                              : 126 MiB (98%)
Title                                    : Video
Language                                 : English
Default                                  : Yes
Forced                                   : No

$ mediainfo bbb.mp4
General
Complete name                            : bbb.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 169 MiB
Duration                                 : 9mn 32s
Overall bit rate                         : 2 473 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf57.25.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L3.2
Format settings, CABAC                   : No
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=12
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 9mn 32s
Bit rate                                 : 2 472 Kbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.107
Stream size                              : 169 MiB (100%)
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00


I'll update the first post with links to the precompiled packages.
Thank you all for your help!

@memeka: don't forget to integrate those v4l2 patches in your git please.
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Tue Nov 08, 2016 9:22 pm

Ok, I'm reopening the discussion a bit about bitrates.
If I transcode big buck bunny with 4.5Mbps video bandwidth, I get about 4Mbps in the final file:
Code: Select all
ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -r 24 -i - -i big_buck_bunny_720p_h264.mov -map 0:v:0 -vcodec h264 -b:v 4500000 -profile:v 10 -pix_fmt nv21  -map 1:a:0 -c:a:1 aac bbb.mp4


But if I want to transcode it to 500kbps, I get about 1.7Mbps:
Code: Select all
ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -r 24 -i - -i big_buck_bunny_720p_h264.mov -map 0:v:0 -vcodec h264 -b:v 500000 -profile:v 10 -pix_fmt nv21  -map 1:a:0 -c:a:1 aac bbb.mp4


Is the profile somehow limiting the minimum bitrate? I thought lowering the bitrate causes the encoder to encode more aggressively (which is what I want for some content). Any ideas?
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 09, 2016 4:37 am

it might be some other settings hardcoded from ffmpeg.
if you want to test bitrates, profile and level, use gstreamer, and values from http://osxr.org:8080/linux/source/inclu ... controls.h
after this is done, if there's no equivalent result in ffmpeg, we have to check the code :) i've seen ffmpeg sets some values for the encoder, while gst uses the defaults.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Wed Nov 09, 2016 4:40 am

@mad_ady
I'm transcoding mpeg2 TS files, could you give me the proper ffmpeg usage?

This works but won't respect the set bit rate.

Code: Select all
ffmpeg -i Cleveland.ts -acodec copy -vcodec h264 -b:v 2M -pix_fmt nv21 Cleveland.mp4


I end up with a 4400kbits encoding rate, encode speed is 70fps or 2.36x which is good for a 1080i file. Just need it to respect set bit rate.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Wed Nov 09, 2016 4:30 pm

I've mentioned the lower bitrates a few posts above. ffmpeg doesn't seem to go below 1.7Mbps. I've tried with gstreamer, setting bitrate to 500kbps:
Code: Select all
decoder=`gst-inspect-1.0 | grep v4l2 | grep videodec | cut -d ":" -f 2`; encoder=`gst-inspect-1.0 | grep v4l2 | grep h264enc | cut -d ":" -f 2`; gst-launch-1.0 filesrc location=big_buck_bunny_720p_h264.mov ! qtdemux ! h264parse ! $decoder !  $encoder extra-controls="encode,h264_level=10,h264_profile=4,frame_level_rate_control_enable=1,video_bitrate=500000" ! h264parse ! matroskamux ! filesink location=bbb.mkv


And the output file is:
Code: Select all
adrianp@odroid:~> mediainfo bbb.mkv
General
Unique ID                                : 289097040450050046144615763978083991265 (0xD97E10906B13D112C7FC4E9CC62D7EE1)
Complete name                            : bbb.mkv
Format                                   : Matroska
Format version                           : Version 2
File size                                : 33.9 MiB
Duration                                 : 9mn 56s
Overall bit rate                         : 477 Kbps
Encoded date                             : UTC 2016-11-09 07:08:32
Writing application                      : GStreamer Matroska muxer
Writing library                          : GStreamer matroskamux version 1.8.2

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3.2
Format settings, CABAC                   : No
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=12
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 9mn 56s
Bit rate                                 : 468 Kbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 24.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.021
Stream size                              : 33.3 MiB (98%)
Title                                    : Video
Language                                 : English
Default                                  : Yes
Forced                                   : No



So, the kernel works and the encoder can go lower bitrates, but it seems ffmpeg does not honor them fully...
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Wed Nov 09, 2016 5:01 pm

My problem is I don't know how to use gstreamer for mpeg2 (TS)

My output of 'gst-inspect-1.0 | grep v4l2'

Code: Select all
odroid@odroid:~$ decoder=`gst-inspect-1.0 | grep v4l2 | grep videodec | cut -d ":" -f 2`          odroid@odroid:~$ echo $decoder                                                                    v4l2video0videodec v4l2video3videodec v4l2video5videodec


Code: Select all
                                         odroid@odroid:~$ gst-inspect-1.0 | grep v4l2                                                      video4linux2:  v4l2src: Video (video4linux2) Source                                               video4linux2:  v4l2sink: Video (video4linux2) Sink                                                video4linux2:  v4l2radio: Radio (video4linux2) Tuner                                              video4linux2:  v4l2deviceprovider (GstDeviceProviderFactory)
video4linux2:  v4l2video0videodec: V4L2 Video Decoder
video4linux2:  v4l2video1h264enc: V4L2 H.264 Encoder
video4linux2:  v4l2video3videodec: V4L2 Video Decoder
video4linux2:  v4l2video5videodec: V4L2 Video Decoder
odroid@odroid:~$


You see I have 3 video encoders, two are for jpeg.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Wed Nov 09, 2016 5:12 pm

Join us on irc (#odroid). It's strange that you have so many decoders :)
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Wed Nov 09, 2016 8:10 pm

i think some of them have stayed in the gstreamer cache ... you can delete the cache from the local folder .config/gstreamer (or something like that) and run gst-inspect again.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Wed Nov 09, 2016 10:58 pm

memeka wrote:i think some of them have stayed in the gstreamer cache ... you can delete the cache from the local folder .config/gstreamer (or something like that) and run gst-inspect again.

I have 5, excuse the length of this post...

Code: Select all
odroid@xu3:~$ ls /dev | grep video
video0
video1
video2
video3
video4
video5
odroid@xu3:~$ v4l2-ctl -d /dev/video0 -D
Driver Info (not using libv4l2):
        Driver name   : s5p-mfc
        Card type     : s5p-mfc-dec
        Bus info      : platform:11000000.codec:
        Driver version: 4.9.0
        Capabilities  : 0x84204000
                Video Memory-to-Memory Multiplanar
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04204000
                Video Memory-to-Memory Multiplanar
                Streaming
                Extended Pix Format
odroid@xu3:~$ v4l2-ctl -d /dev/video1 -D
Driver Info (not using libv4l2):
        Driver name   : s5p-mfc
        Card type     : s5p-mfc-enc
        Bus info      : platform:11000000.codec:
        Driver version: 4.9.0
        Capabilities  : 0x84204000
                Video Memory-to-Memory Multiplanar
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04204000
                Video Memory-to-Memory Multiplanar
                Streaming
                Extended Pix Format
odroid@xu3:~$ v4l2-ctl -d /dev/video2 -D
Driver Info (not using libv4l2):
        Driver name   : s5p-jpeg
        Card type     : s5p-jpeg encoder
        Bus info      : platform:11f50000.jpeg:
        Driver version: 4.9.0
        Capabilities  : 0x84208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
odroid@xu3:~$ v4l2-ctl -d /dev/video3 -D
Driver Info (not using libv4l2):
        Driver name   : s5p-jpeg
        Card type     : s5p-jpeg decoder
        Bus info      : platform:11f50000.jpeg:
        Driver version: 4.9.0
        Capabilities  : 0x84208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
odroid@xu3:~$ v4l2-ctl -d /dev/video4 -D
Driver Info (not using libv4l2):
        Driver name   : s5p-jpeg
        Card type     : s5p-jpeg encoder
        Bus info      : platform:11f60000.jpeg:
        Driver version: 4.9.0
        Capabilities  : 0x84208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
odroid@xu3:~$ v4l2-ctl -d /dev/video5 -D
Driver Info (not using libv4l2):
        Driver name   : s5p-jpeg
        Card type     : s5p-jpeg decoder
        Bus info      : platform:11f60000.jpeg:
        Driver version: 4.9.0
        Capabilities  : 0x84208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04208000
                Video Memory-to-Memory
                Streaming
                Extended Pix Format
odroid@xu3:~$ gst-inspect-1.0 | grep v4l2
video4linux2:  v4l2video5videodec: V4L2 Video Decoder
video4linux2:  v4l2video3videodec: V4L2 Video Decoder
video4linux2:  v4l2video1h264enc: V4L2 H.264 Encoder
video4linux2:  v4l2video0videodec: V4L2 Video Decoder
video4linux2:  v4l2deviceprovider (GstDeviceProviderFactory)
video4linux2:  v4l2radio: Radio (video4linux2) Tuner
video4linux2:  v4l2sink: Video (video4linux2) Sink
video4linux2:  v4l2src: Video (video4linux2) Source
odroid@xu3:~$ dmesg | grep video
[ *****snip*****]
[   14.669729] Linux video capture interface: v2.00
[   14.804376] s5p-mfc 11000000.codec:: decoder registered as /dev/video0
[   14.811271] s5p-mfc 11000000.codec:: encoder registered as /dev/video1
[   14.823189] s5p-jpeg 11f50000.jpeg:: encoder device registered as /dev/video2
[   14.834706] s5p-jpeg 11f50000.jpeg:: decoder device registered as /dev/video3
[   14.852921] s5p-jpeg 11f60000.jpeg:: encoder device registered as /dev/video4
[   14.860816] s5p-jpeg 11f60000.jpeg:: decoder device registered as /dev/video5
odroid@xu3:~$
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby memeka » Thu Nov 10, 2016 4:14 am

Right, forgot about jpeg, I disable them on my config.
You wanna use s5p-mfc-enc for encoder and s5p-mfc-dec for decoder, so video1 gst encoder is the one you want.
User avatar
memeka
 
Posts: 4055
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Thu Nov 10, 2016 4:18 am

I'll try to see if I can change the $encoder/$decoder detection to ignore those...
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby rooted » Thu Nov 10, 2016 6:16 am

memeka wrote:Right, forgot about jpeg, I disable them on my config.
You wanna use s5p-mfc-enc for encoder and s5p-mfc-dec for decoder, so video1 gst encoder is the one you want.

Yes I enabled them to see if they are usable in any meaningful way.
mad_ady wrote:I'll try to see if I can change the $encoder/$decoder detection to ignore those...

Don't worry about it, I can disable them in my kernel.
User avatar
rooted
 
Posts: 5676
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english
ODROIDs: C1, C1+, C2
XU3 Lite, XU4
N1
VU7+
HiFi Shield 2
Smart Power (original)

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Tue Nov 22, 2016 10:23 pm

Update: With memeka's help I was able to convince ffmpeg to accept lower bitrates than what I previously got (which was 1.7Mps). The problem was it was getting the max quantizer setting set to 31 when the encoder supports up to 51. I hardcoded the 51 (the higher the value the worse the quality) value in the encoder settings and recompiled ffmpeg. Now you can encode with very low bitrates (I got 285kbps, but you can go lower). You can get the updated ffmpeg from the link in the first post, or compile it yourselves (sent a push request to memeka to import it in his github).
Code: Select all
ffmpeg -i big_buck_bunny_720p_h264.mov -codec:v copy -codec:a none -bsf:v h264_mp4toannexb -f rawvideo - | ffmpeg -r 24 -i - -an  -vcodec h264 -crf 35 -profile:v 10 -pix_fmt nv21 bbb.mp4
...
Input #0, h264, from 'pipe:':ze=     293kB time=00:00:00.25 bitrate=9574.3kbits/s speed=0.478x   
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709), 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Codec AVOption crf (Select the quality for constant quality mode) specified for output file #0 (bbb.mp4) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option wit
h no video streams) or that it is a private option of some encoder which was not actually used for any stream.
[h264_v4l2m2m @ 0x39f2a0] H264 codec detected, init annexb converter
[h264_v4l2m2m @ 0x39f2a0] Device path not set, probing /dev/video*
[h264_v4l2m2m @ 0x39f2a0] exynos-gsc.1:m2m is not the one we want
[h264_v4l2m2m @ 0x39f2a0] exynos-gsc.0:m2m is not the one we want
[h264_v4l2m2m @ 0x39f2a0] Using device /dev/video1
[h264_v4l2m2m @ 0x39f2a0] gop_size: 12
[h264_v4l2m2m @ 0x39f2a0] Enabling bitrate control if required rate 1 > 1
[h264_v4l2m2m @ 0x39f2a0] Max b-frames: 0
[h264_v4l2m2m @ 0x39f2a0] Min/max quantizer scale: 2, 51
[h264 @ 0x70860] non-existing SPS 0 referenced in buffering period
Output #0, mp4, to 'bbb.mp4':
  Metadata:
    encoder         : Lavf57.25.100
    Stream #0:0: Video: h264 (h264_v4l2m2m) ([33][0][0][0] / 0x0021), nv21, 1280x720, q=2-51, 200 kb/s, 24 fps, 12288 tbn, 24 tbc
    Metadata:
      encoder         : Lavc57.24.102 h264_v4l2m2m
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
[h264_v4l2m2m @ 0x39f2a0] Performing useless memcpy() on output pool because buffers do not match
[h264_v4l2m2m @ 0x39f2a0] This could be avoided by using av_v4l_buffer_pool_get_buffer*() or av_v4l_buffer_pool_make_pipe()
[mp4 @ 0x39e7d0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 0x39e7d0] Encoder did not produce proper pts, making some up.
[h264_v4l2m2m @ 0x39f2a0] No event occurred while waiting29 bitrate=4917.9kbits/s speed= 4.7x     
frame=11315 fps=114 q=-0.0 Lsize=   16468kB time=00:07:51.50 bitrate= 286.1kbits/s speed=4.75x   

User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby fnoop » Fri Dec 09, 2016 5:43 pm

Is it possible for someone to provide easy to understand steps to patch and compile latest gstreamer? Or are the necessary patches in upstream, ala gsteamer-1.10.2?
fnoop
 
Posts: 67
Joined: Thu Apr 28, 2016 6:04 am
languages_spoken: english
ODROIDs: XU4, oCam

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Fri Dec 09, 2016 6:26 pm

Carefully read the first post
Alternatively you can get the pre-built deb packages from here: https://www.mediafire.com/folder/5lz2po ... -odroidxu4
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby fnoop » Fri Dec 09, 2016 6:39 pm

mad_ady wrote:Carefully read the first post
Alternatively you can get the pre-built deb packages from here: https://www.mediafire.com/folder/5lz2po ... -odroidxu4


I've downloaded those to test with, thanks very much. But I'd like to have a repeatable set of steps like I've made for the 4.x kernel:
https://github.com/fnoop/maverick/blob/ ... ernel4x.pp
fnoop
 
Posts: 67
Joined: Thu Apr 28, 2016 6:04 am
languages_spoken: english
ODROIDs: XU4, oCam

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby fnoop » Sat Dec 10, 2016 7:11 am

fnoop wrote:
mad_ady wrote:Carefully read the first post
Alternatively you can get the pre-built deb packages from here: https://www.mediafire.com/folder/5lz2po ... -odroidxu4


I've downloaded those to test with, thanks very much. But I'd like to have a repeatable set of steps like I've made for the 4.x kernel:
https://github.com/fnoop/maverick/blob/ ... ernel4x.pp


So ocam connected to usb2 I've got gstreamer YUV @640x480/60fps encoding to h264 through the MFC with negligable load on the system. Thanks for the packages :) Were these packages just built using the source instructions above, or are they a later patched gstreamer tree?
Edit: sorry the packages are versioned, I can see they're same version as the standard gstreamer

There's a bit of latency in the encoded video, are there any settings with the hardware encoder to reduce latency to an absolute minimum?
fnoop
 
Posts: 67
Joined: Thu Apr 28, 2016 6:04 am
languages_spoken: english
ODROIDs: XU4, oCam

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby mad_ady » Sat Dec 10, 2016 8:45 pm

Are you trying to do real-time encoding? You can see all the encoder parameters by running v4l2-ctl -l -d /dev/videoX (or something similar).
User avatar
mad_ady
 
Posts: 4707
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: [Howto] Odroid XU3/4 using the hardware encoder

Unread postby fnoop » Sun Dec 11, 2016 6:56 pm

mad_ady wrote:Are you trying to do real-time encoding? You can see all the encoder parameters by running v4l2-ctl -l -d /dev/videoX (or something similar).


I don't see much there:
Code: Select all
[dev] [mav@odroid ~]$ v4l2-ctl -l -d /dev/video4
                     brightness (int)    : min=-4 max=4 step=1 default=0 value=0
                       contrast (int)    : min=0 max=8 step=1 default=4 value=4
                     saturation (int)    : min=0 max=8 step=1 default=4 value=4
                            hue (int)    : min=0 max=11 step=1 default=6 value=6
              exposure_absolute (int)    : min=0 max=10 step=1 default=4 value=4


And I don't see much in the gst-inspect:
Code: Select all
[dev] [mav@odroid ~]$ gst-inspect-1.0 v4l2video3h264enc
Factory Details:
  Rank                     primary + 1 (257)
  Long-name                V4L2 H.264 Encoder
  Klass                    Codec/Encoder/Video
  Description              Encode H.264 video streams via V4L2 API
  Author                   ayaka <ayaka@soulik.info>

Plugin Details:
  Name                     video4linux2
  Description              elements for Video 4 Linux
  Filename                 /usr/lib/arm-linux-gnueabihf/gstreamer-1.0/libgstvideo4linux2.so
  Version                  1.8.2
  License                  LGPL
  Source module            gst-plugins-good
  Source release date      2016-06-09
  Binary package           GStreamer Good Plugins (Ubuntu)
  Origin URL               https://launchpad.net/distros/ubuntu/+source/gst-plugins-good1.0

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstVideoEncoder
                         +----GstV4l2VideoEnc
                               +----GstV4l2H264Enc
                                     +----v4l2video3h264enc

Implemented Interfaces:
  GstPreset

Pad Templates:
  SINK template: 'sink'
    Availability: Always
    Capabilities:
      video/x-raw
                 format: { NV12, NV21 }
                  width: [ 1, 32768 ]
                 height: [ 1, 32768 ]
              framerate: [ 0/1, 2147483647/1 ]

  SRC template: 'src'
    Availability: Always
    Capabilities:
      video/mpeg
            mpegversion: 4
           systemstream: false
      video/x-h263
                variant: itu
      video/x-h264
          stream-format: byte-stream
              alignment: au
      video/x-vp8


Element Flags:
  no flags set

Element Implementation:
  Has change_state() function: gst_v4l2_video_enc_change_state

Element has no clocking capabilities.
Element has no URI handling capabilities.

Pads:
  SINK: 'sink'
    Pad Template: 'sink'
  SRC: 'src'
    Pad Template: 'src'

Element Properties:
  name                : The name of the object
                        flags: readable, writable
                        String. Default: "v4l2video3h264enc0"
  parent              : The parent of the object
                        flags: readable, writable
                        Object of type "GstObject"
  device              : Device location
                        flags: readable
                        String. Default: "/dev/video3"
  device-name         : Name of the device
                        flags: readable
                        String. Default: "s5p-mfc-enc"
  device-fd           : File descriptor of the device
                        flags: readable
                        Integer. Range: -1 - 2147483647 Default: -1
  output-io-mode      : Output side I/O mode (matches sink pad)
                        flags: readable, writable
                        Enum "GstV4l2IOMode" Default: 0, "auto"
                           (0): auto             - GST_V4L2_IO_AUTO
                           (1): rw               - GST_V4L2_IO_RW
                           (2): mmap             - GST_V4L2_IO_MMAP
                           (3): userptr          - GST_V4L2_IO_USERPTR
                           (4): dmabuf           - GST_V4L2_IO_DMABUF
                           (5): dmabuf-import    - GST_V4L2_IO_DMABUF_IMPORT
  capture-io-mode     : Capture I/O mode (matches src pad)
                        flags: readable, writable
                        Enum "GstV4l2IOMode" Default: 0, "auto"
                           (0): auto             - GST_V4L2_IO_AUTO
                           (1): rw               - GST_V4L2_IO_RW
                           (2): mmap             - GST_V4L2_IO_MMAP
                           (3): userptr          - GST_V4L2_IO_USERPTR
                           (4): dmabuf           - GST_V4L2_IO_DMABUF
                           (5): dmabuf-import    - GST_V4L2_IO_DMABUF_IMPORT
  extra-controls      : Extra v4l2 controls (CIDs) for the device
                        flags: readable, writable
                        Boxed pointer of type "GstStructure"


It would be nice to see what options there are for the extra-controls:
extra-controls="encode,h264_level=10,h264_profile=4,frame_level_rate_control_enable=1,video_bitrate=2097152"

Glass to glass latency @640x480/120fps is down to 80ms which is absolutely fantastic. Would be great to get it down further than that if possible, it makes a big difference for realtime encoding.
fnoop
 
Posts: 67
Joined: Thu Apr 28, 2016 6:04 am
languages_spoken: english
ODROIDs: XU4, oCam

Next

Return to Linux Kernel 4.14 Debugging Party

Who is online

Users browsing this forum: No registered users and 1 guest