encode recordings with quicksync/vaapi ffmpeg on Ubuntu 16.04 server
#1
Hello,

I am recording my Live tv (DVB S2 with tvheadend) on my storage as mkv files with no transcoding on an N3150 Box. But I have not unlimited storage and want to reduce the filesize. Reencoding the files on CPU is way to slow on the N3150, therefore I want to use Quicksync/VAAPI since the hardware should be able to do it.
I am running a pure Ubuntu 16.04.1 server system (no X Server), which is my storage server.

I download a precompiled ffmpeg from http://johnvansickle.com/ffmpeg/ with vaapi/qsv support, but I cant get i working and I dont know why


Code:
./ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -i /Aufnahmen/Transcendence.mkv -an -c:v h264_vaapi /Aufnahmen/Transcendence.mp4
ffmpeg version N-82997-g557c0df9a8-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.1 (Debian 5.4.1-4) 20161202
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 70.101 / 57. 70.101
  libavformat    57. 61.100 / 57. 61.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
[AVHWDeviceContext @ 0x402f080] No VA display found for device: /dev/dri/renderD128.
[vaapi @ 0x30e41e0] Failed to create a VAAPI device





root@serverhost:~/ffmpeg-git-20170104-64bit-static# ./ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i /Aufnahmen/Transcendence.mkv -vf 'format=nv12,hwupload' -acodec copy -vcodec h264_vaapi -qp 19 /Aufnahmen/Transcendence.mp4
ffmpeg version N-82997-g557c0df9a8-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.1 (Debian 5.4.1-4) 20161202
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 70.101 / 57. 70.101
  libavformat    57. 61.100 / 57. 61.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
[AVHWDeviceContext @ 0x46880c0] No VA display found for device: /dev/dri/renderD128.
[vaapi @ 0x30e41e0] Failed to create a VAAPI device




root@serverhost:~/ffmpeg-git-20170104-64bit-static# ./ffmpeg -vaapi_device /dev/dri/renderD128 -i /Aufnahmen/Transcendence.mkv -vf 'format=nv12,hwupload' -c:v h264_vaapi /Aufnahmen/Transcendence.mp4
ffmpeg version N-82997-g557c0df9a8-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.1 (Debian 5.4.1-4) 20161202
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 70.101 / 57. 70.101
  libavformat    57. 61.100 / 57. 61.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
[AVHWDeviceContext @ 0x52f0040] No VA display found for device: /dev/dri/renderD128.
[vaapi @ 0x30e41e0] Failed to create a VAAPI device



root@serverhost:/dev/dri# ls /dev/dri/
card0  controlD64  renderD128

If I get it working in the commandline I would like to use a script to run a postprocessing process in Tvheadend.
Backend: Asrock N3150 with Ubuntu 22.04 Server with TvHeadend 
Living Room: Nvidia Shield with Kodi
Other Kodi Clients: Coreelec, Mibox, Windows
Reply
#2
Nothing to do with Kodi
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#3
1) Are you sure the build you got has vaapi support?
It's not listed in build options and if I run the build you linked on my machine I get same failure as you.
If I run my own dynamic build with proper vaapi support it's working fine.

Code:
/opt/builds/ffmpeg/bin/ffmpeg  -vaapi_device /dev/dri/renderD128 -i test.720p.mkv -vf 'format=nv12,hwupload' -c:v h264_vaapi test.hw.mp4
ffmpeg version N-83096-g6596b34954-avh Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/opt/builds/ffmpeg --extra-version=avh --extra-ldflags= --extra-cflags= --disable-debug --enable-shared --disable-static --enable-pic --disable-doc --enable-gpl --enable-version3 --enable-nonfree --enable-avresample --enable-openssl --enable-vaapi --enable-vdpau --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-fontconfig --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libbluray --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-librtmp --enable-libwebp --enable-libopenjpeg --enable-libvidstab --enable-bzlib --enable-lzma --enable-zlib --enable-avisynth --disable-crystalhd --enable-encoder=png --enable-encoder=mjpeg --disable-ffplay --disable-x11grab --disable-opencl --disable-opengl --disable-libpulse --disable-libopencv --disable-xlib --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-libxcb-shape --disable-nvenc --disable-sdl --enable-ffserver --enable-indev=alsa --enable-outdev=alsa
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 72.100 / 57. 72.100
  libavformat    57. 62.100 / 57. 62.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 69.100 /  6. 69.100
  libavresample   3.  2.  0 /  3.  2.  0
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
libva info: VA-API version 0.40.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /opt/builds/ffmpeg/lib/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_40
libva info: va_openDriver() returns 0
Input #0, matroska,webm, from 'test.720p.mkv':

I can't tell why exactly that static build won't work. Contact the author.

2) I advice against using vaapi to encode your media if you want to save space!
The encoded files are actually BIGGER.
Playing with quality/bitrate settings gives crap quality.
I haven't been able to find the balance yet ...
Code:
-rw-rw-rw- 1  root                root                287M May 26  2016 test.720p.mkv
-rw-r--r-- 1 root                root                435M Jan 18 10:38 test.hw.mp4

3) On a side note ffmpeg with NVENC on my desktop with GTX760 gives both excellent speed and size.

4) This is slightly offtopic for this forum. It's certain ffmpeg build issue, not Kodi issue ...
Reply
#4
yeah, sorry if I post it here. I thought its semi Kodi related, because I want to add this script to TVheadend Smile

If its to offtopic, please move this to the offtopic area.

I will try to compile ffmpeg by myself and test again, thanks @asavah for your test.
Is your test.720p.mkv in mp4 or mpeg2? My recordings are in mpeg2 and therefore 2 hours SD Content equals to 3-4 GB and HD to even more.
Backend: Asrock N3150 with Ubuntu 22.04 Server with TvHeadend 
Living Room: Nvidia Shield with Kodi
Other Kodi Clients: Coreelec, Mibox, Windows
Reply
#5
It's h264, I've grabbed a random file from my collection.
Don't think I've got mpeg2 files to test.
Code:
Duration: 00:17:48.28, start: 0.400000, bitrate: 2245 kb/s
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Stream #0:1(unknown): Audio: ac3, 44100 Hz, stereo, fltp, 192 kb/s (default)
Reply
#6
as you suggested the precompiled ffmpeg was misbehaving.
After installing a hell of depencies I managed to use:

ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i /Aufnahmen/Transcendence.mkv -vf 'format=nv12,hwupload' -acodec copy -vcodec h264_vaapi -qp 19 /Aufnahmen/Transcendence.mp4

Input stream #0:0 frame changed from size:720x576 fmt:yuv420p to size:720x576 fmt:nv12
frame= 1308 fps=123 q=-0.0 size= 18041kB time=00:00:52.16 bitrate=2833.5kbits/s dup=5 drop=0 speed=4.92xn


CPU Load on one Core is 50 % with htop. There a lot of other processes on my system, mainly qemu, therefore I cant measure exactly. But it seems like the GPU is doing the job.

If this job finishes I will update this post to see how big the file is and how the quality is.

Thanks
Backend: Asrock N3150 with Ubuntu 22.04 Server with TvHeadend 
Living Room: Nvidia Shield with Kodi
Other Kodi Clients: Coreelec, Mibox, Windows
Reply
#7
Back with some results. The filesice can be reduced to half with the settings from above, but the image quality is quite blocky.
This is not something worth watching, maybe I need the right options with ffmpeg / I will try software encode and compare the quality.
Backend: Asrock N3150 with Ubuntu 22.04 Server with TvHeadend 
Living Room: Nvidia Shield with Kodi
Other Kodi Clients: Coreelec, Mibox, Windows
Reply

Logout Mark Read Team Forum Stats Members Help
encode recordings with quicksync/vaapi ffmpeg on Ubuntu 16.04 server0