Recommended kernel for HW encoding (video transcoding)

Post Reply
trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Wed Dec 05, 2018 9:14 am

Hi, I am thinking of setting up a tvheadend server on my XU4 with support for transcoding.

I read in some (old) threads of this forum that kernel 4.9 is needed for HW encoding. Is this still true, or it is now possible to HW encode in 4.14? 4.9 is no longer supported by HK in favor of 4.14 so I rather use 4.14 for better stability.

Additionally, I am an odroid newbie so if someone could point me to a guide/tutorial for enabling hw encoding/transcoding it would be greatly appreciated. Thanks.

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

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by mad_ady » Wed Dec 05, 2018 2:36 pm

No, 4.14 supports hardware encoding as well.

trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Wed Dec 05, 2018 3:36 pm

mad_ady wrote:No, 4.14 supports hardware encoding as well.
Thanks. One last question, according to viewtopic.php?f=146&t=24366 we need to install a mainline kernel that supports the MFC encoder (step 1).

Is it enough to just use https://wiki.odroid.com/odroid-xu4/os_i ... 03-minimal ?
Or, do we need to specifically use one of the kernels stated in the thread ?

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

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by mad_ady » Wed Dec 05, 2018 4:39 pm

The 4.14 kernel that is shipped by hardkernel in their 18.04 minimal/desktop images should be fine. The same for the ffmpeg they ship. The only problem with their ffmpeg I think is that it doesn't have a patch to support very low bitrate encoding (it looks like crap anyway). So you can skip step 1 and 2.
You can try it with the minimal image, but if you run into problems you should try the desktop image as well (in case it needs mali for scaling or something).
You can try the ffmpeg encoding examples from that thread.

trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Fri Dec 07, 2018 10:15 am

mad_ady wrote:The 4.14 kernel that is shipped by hardkernel in their 18.04 minimal/desktop images should be fine. The same for the ffmpeg they ship. The only problem with their ffmpeg I think is that it doesn't have a patch to support very low bitrate encoding (it looks like crap anyway). So you can skip step 1 and 2.
You can try it with the minimal image, but if you run into problems you should try the desktop image as well (in case it needs mali for scaling or something).
You can try the ffmpeg encoding examples from that thread.
Thanks. Unfortunately it did not work for me, building tvheadend using the option --enable-libav in order to get transcoding fails with the error

Code: Select all

ffmpeg development support not found
I checked how many ffmpeg instances do I have with find / -name ffmpeg, but there only seems to be one binary in /usr/bin:

Code: Select all

/root/tvheadend/build.linux/ffmpeg
/root/tvheadend/build.linux/ffmpeg/build/ffmpeg
/usr/share/doc/ffmpeg
/usr/share/lintian/overrides/ffmpeg
/usr/share/ffmpeg
/usr/bin/ffmpeg
Any idea on how to solve this?

trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Mon Dec 10, 2018 12:08 pm

@mad_ady

I managed to build tvheadend and ffmpeg without problems after a fresh install.

However, when adding a new "transcoding/av-lib" stream profile in tvheadend, the only options available for video codec are:
- disabled
- copy
- webtv-h264
- webtv-vp8

Which one should be the one used for HW transcode ? Looking at some forum posts in viewtopic.php?f=96&t=26344 it looks that I should have h264_v4l2m2m but there is no such option in tvheadend...

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

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by mad_ady » Mon Dec 10, 2018 2:45 pm

Not sure where tvheadend gets its codec list from. Have you tried transcoding a static file from the command line to validate that the encoder works?

trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Mon Dec 10, 2018 10:17 pm

mad_ady wrote:Not sure where tvheadend gets its codec list from. Have you tried transcoding a static file from the command line to validate that the encoder works?
Just tested now. Unfortunately the h264_v4l2m2m does not seem to be used according to this line: 0 (h264 (native) -> h264 (libx264))

Full log follows:

Code: Select all

ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --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-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --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-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'simpsons.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2007-02-19T05:03:04.000000Z
  Duration: 00:02:17.30, start: 0.000000, bitrate: 4283 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x544, 4221 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      creation_time   : 2007-02-19T05:03:04.000000Z
      handler_name    : GPAC ISO Video Handler
    Stream #0:1(und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      creation_time   : 2007-02-19T05:03:08.000000Z
      handler_name    : GPAC ISO Audio Handler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x521c00] using cpu capabilities: ARMv6 NEON
[libx264 @ 0x521c00] profile High, level 3.1
[libx264 @ 0x521c00] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=2000 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

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

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by mad_ady » Mon Dec 10, 2018 10:56 pm

You can try to force it for decoding or for encoding. Also, make sure the user you're running ffmpeg as can access rw /dev/video*.

trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Wed Dec 12, 2018 11:10 pm

mad_ady wrote:You can try to force it for decoding or for encoding. Also, make sure the user you're running ffmpeg as can access rw /dev/video*.
Thanks. The user running ffmpeg belongs to the video group and can access rw /dev/video*.

I have tried running ffmpeg with the option -vcodec h264_v4l2m2m, but it seems to get stuck after "encoder adjustment" and does not transcode at all.
I am also getting the message "h264 profile not found" which makes me think that there is something wrong with my ffmpeg.... What do you think?

Log below:

Code: Select all

root@odroid:~/tests# ffmpeg -i simpsons.mp4 -acodec aac -vcodec h264_v4l2m2m aaa.mp4
ffmpeg version 3.4.2-9 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.3.0-27ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=9 --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --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-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --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-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-v4l2_m2m --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'simpsons.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2007-02-19T05:03:04.000000Z
  Duration: 00:02:17.30, start: 0.000000, bitrate: 4283 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x544, 4221 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      creation_time   : 2007-02-19T05:03:04.000000Z
      handler_name    : GPAC ISO Video Handler
    Stream #0:1(und): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      creation_time   : 2007-02-19T05:03:08.000000Z
      handler_name    : GPAC ISO Audio Handler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x5389d0] driver 'exynos-gsc' on card 'exynos-gsc gscaler'
    Last message repeated 1 times
[h264_v4l2m2m @ 0x5389d0] driver 's5p-mfc' on card 's5p-mfc-enc'
[h264_v4l2m2m @ 0x5389d0] Using device /dev/video11
[h264_v4l2m2m @ 0x5389d0] driver 's5p-mfc' on card 's5p-mfc-enc'
[h264_v4l2m2m @ 0x5389d0] h264_v4l2m2m encoder: enabling bit rate control: 200000
[h264_v4l2m2m @ 0x5389d0] h264 profile not found
[h264_v4l2m2m @ 0x5389d0] Encoder adjusted: qmin (0), qmax (51)

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

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by mad_ady » Thu Dec 13, 2018 12:28 am

As far as I remember the resolution has to be multiple of 64 otherwise you get problems. Can you try with the big buck bunny video to rule out incompatible input? (some input is known to hang the encoder)

trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Thu Dec 13, 2018 9:47 am

mad_ady wrote:As far as I remember the resolution has to be multiple of 64 otherwise you get problems. Can you try with the big buck bunny video to rule out incompatible input? (some input is known to hang the encoder)
Thanks, you were right. Using the 720p big buck bunny video with the setting -vcodec h264_v4l2m2m let me successfully convert the file without hanging. I have 2 questions regarding the command and the transcoding output:

1. During the process the following warnings? were thrown, is there something to worry about? The h264 profile not found warning looks like a big problem but just wanted to confirm.

[h264_v4l2m2m @ 0x5837a0] h264 profile not found
[h264_v4l2m2m @ 0x5837a0] Encoder adjusted: qmin (0), qmax (51)
[mp4 @ 0x56d300] Non-monotonous DTS in output stream 0:0; previous: 0, current: 0; changing to 1. This may result in incorrect timestamps in the output file.

2. In your thread (viewtopic.php?f=146&t=24366) it loooks like the hardware encoder is automatically used by just using the option -vcodec h264. This does not happen on my side, I have to explicitly set h264_v4l2m2m as vcodec. Otherwise libx264 is used. Any idea why this happens?

Thanks!

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

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by mad_ady » Thu Dec 13, 2018 2:42 pm

h264 profile not found
I don't remember whether I was getting this or not. The rest are normal.
Regarding size restrictions, on that thread there is a command that has a filter which crops the image to a supported resolution.

Regarding the default m2m behavior - it must have been on on @memeka's branch. Don't know what enables it, but it's best to request it specifically so that you contril if you want to do software decoding and hardware encoding.

I also noticed that you have higher chances of getting an encoding working by ignoring audio completely (-an).

User avatar
memeka
Posts: 4143
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by memeka » Mon Dec 17, 2018 7:44 am

* mad_ady is correct, you can use some filters to crop the image to multiply of 64 resolution
* h264 profile not found warning is ok, you can ignore
* i think HK defaults to having h264_v4l2m2m as default. i don't do this anymore, and leave the software as default. for transcoding, using both HW encoder and decoder doesn't work, so you need to specify anyway which is HW and which is SW. might as well leave the default ffmpeg bahaviour, and let the user manually specify encoder/decoder.
* you might want to try decoupling audio and video, have audio working on separate thread... (dunno the options for that tho` :D)

zupet
Posts: 13
Joined: Tue Dec 26, 2017 11:13 pm
languages_spoken: korean,english
ODROIDs: HC1
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by zupet » Mon Dec 17, 2018 2:17 pm

tvheadend + ffmpeg will not give good result because it won't get over 1x speed on FHD transcoding.
You can save stream to *.ts or *.mkv without transcoding and run post script with ffmpeg HW acceleration.

Gstreamer can transcode faster than ffmpeg but didn't tested with tvheadend because it's kinda unstable.
It run slight faster than 1x and it might be possible to transcode live streams.

gstreamer .ts -> deinterlace -> resize -> hw mp4 encoding -> .mkv
gst-launch-1.0 \
filesrc location=input.ts \
! tsdemux name=demux \
! queue \
! h264parse \
! v4l2video10videodec \
! deinterlace mode=interlaced \
! videoscale n-threads=2 \
! video/x-raw,width=864,height=480 \
! videorate \
! video/x-raw,framerate=30000/1001 \
! v4l2video11h264enc extra-controls="encode,h264_level=10,h264_profile=5,frame_level_rate_control_enable=1,video_bitrate=1024000" \
! h264parse \
! queue \
! matroskamux name=mux \
! filesink location=result.mkv \
demux. \
! queue \
! ac3parse \
! a52dec \
! audioresample \
! audioconvert \
! audio/x-raw,channels=2 \
! avenc_aac compliance=experimental \
! queue \
! mux.
gstreamer .mkv -> deinterlace -> resize -> hw mp4 encoding -> .mp4
gst-launch-1.0 -m \
filesrc location=input.mkv \
! matroskademux name=demux \
! queue \
! h264parse \
! v4l2video10videodec \
! deinterlace mode=interlaced \
! videoscale n-threads=2 \
! video/x-raw,width=1280,height=720 \
! videorate \
! video/x-raw,framerate=30000/1001 \
! v4l2video11h264enc extra-controls="encode,h264_level=10,h264_profile=5,frame_level_rate_control_enable=1,video_bitrate=2048000" \
! h264parse \
! queue \
! matroskamux name=mux \
! filesink location=result.mp4 \
demux. \
! queue \
! ac3parse \
! a52dec \
! audioresample \
! audioconvert \
! audio/x-raw,channels=2 \
! avenc_aac compliance=experimental \
! queue \
! mux. \
Last edited by zupet on Tue Dec 18, 2018 1:44 pm, edited 1 time in total.

User avatar
memeka
Posts: 4143
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by memeka » Tue Dec 18, 2018 7:57 am

i recommend using v4l2video20<...> instead of videoscale for hardware scaling

trimethia
Posts: 18
Joined: Fri Oct 05, 2018 12:38 pm
languages_spoken: english, spanish
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by trimethia » Sun Dec 23, 2018 5:01 am

zupet wrote:
Mon Dec 17, 2018 2:17 pm
tvheadend + ffmpeg will not give good result because it won't get over 1x speed on FHD transcoding.
You can save stream to *.ts or *.mkv without transcoding and run post script with ffmpeg HW acceleration.

Gstreamer can transcode faster than ffmpeg but didn't tested with tvheadend because it's kinda unstable.
It run slight faster than 1x and it might be possible to transcode live streams.

gstreamer .ts -> deinterlace -> resize -> hw mp4 encoding -> .mkv
gst-launch-1.0 \
filesrc location=input.ts \
! tsdemux name=demux \
! queue \
! h264parse \
! v4l2video10videodec \
! deinterlace mode=interlaced \
! videoscale n-threads=2 \
! video/x-raw,width=864,height=480 \
! videorate \
! video/x-raw,framerate=30000/1001 \
! v4l2video11h264enc extra-controls="encode,h264_level=10,h264_profile=5,frame_level_rate_control_enable=1,video_bitrate=1024000" \
! h264parse \
! queue \
! matroskamux name=mux \
! filesink location=result.mkv \
demux. \
! queue \
! ac3parse \
! a52dec \
! audioresample \
! audioconvert \
! audio/x-raw,channels=2 \
! avenc_aac compliance=experimental \
! queue \
! mux.
gstreamer .mkv -> deinterlace -> resize -> hw mp4 encoding -> .mp4
gst-launch-1.0 -m \
filesrc location=input.mkv \
! matroskademux name=demux \
! queue \
! h264parse \
! v4l2video10videodec \
! deinterlace mode=interlaced \
! videoscale n-threads=2 \
! video/x-raw,width=1280,height=720 \
! videorate \
! video/x-raw,framerate=30000/1001 \
! v4l2video11h264enc extra-controls="encode,h264_level=10,h264_profile=5,frame_level_rate_control_enable=1,video_bitrate=2048000" \
! h264parse \
! queue \
! matroskamux name=mux \
! filesink location=result.mp4 \
demux. \
! queue \
! ac3parse \
! a52dec \
! audioresample \
! audioconvert \
! audio/x-raw,channels=2 \
! avenc_aac compliance=experimental \
! queue \
! mux. \
Thanks! Is there any guide/tutorial to set up gstreamer on the xu4 ?

zupet
Posts: 13
Joined: Tue Dec 26, 2017 11:13 pm
languages_spoken: korean,english
ODROIDs: HC1
Contact:

Re: Recommended kernel for HW encoding (video transcoding)

Unread post by zupet » Mon Dec 24, 2018 2:43 pm

trimethia wrote:
Sun Dec 23, 2018 5:01 am
Thanks! Is there any guide/tutorial to set up gstreamer on the xu4 ?
No. There was no result from forum search or wiki.

Post Reply

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 3 guests