Feature #4443

support vaapi for transcoding

Added by C vH about 1 month ago. Updated 3 days ago.

Status:NewStart date:2016-05-28
Priority:NormalDue date:
Assignee:John Törnblom% Done:

100%

Category:Transcoding
Target version:-

Description

This was similar requested a few times but this is a different approach.

current situation:

Tvh supports only nvenc (for Nvida GPUs) for hw accelerated transcoding, QSV is supported but has no real world usability (you need to patch/recompile your kernel with outdated patches + sign in for SDK ...) and was widely dropped in favor of vaapi that is supported by every Intel and AMD CPUs that are not older then ~6+ years that include an gpu.

So basically every low end CPU like the popular J1900,N3150,J3455 that are even at commercial NAS systems (Synology...) would be able to handle easily 2-3 Streams at the same time, the latest generation could even transcode H265 in real time without an problem.

Vaapi is completely integrated at the latest ffmpeg, Linux distributions support it also widely (because you only need the GPU driver) and even Tvh ffmpeg is getting build with --enable-vaapi.

What is missing:
Vaapi is used via command line switches, you can't just build ffmpeg with support for it and it works. full howto

ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i "input file" -vf 'format=nv12,hwupload' -map 0:0 -map 0:1 -threads 8 -aspect 16:9 -y -f matroska -acodec copy -b:v 12500k -vcodec 264_vaapi "output file"

possible solutions:
- Tvh offers a way to specify the command line that is used for transcoding (user could tune it their self)
- Tvh adds a profile for vaapi (this could be problematic due the different systems with maybe different paths to dri render)
- redo the transcoding profiles or "merge" the codecs branch from here https://github.com/lekma/tvheadend/tree/codecs that is sadly not finished (but works) and was intended to pred to Tvh


Subtasks

Feature #3831: VAAPI Encoding via FFmpeg.Rejected

History

#1 Updated by Jaroslav Kysela about 1 month ago

Unfortunately, it seems that lekma has no time to work on the transcoding code and I have no ETA to port his changes to latest tvh. There's no such thing like command-line if you like to use the ffmpeg library directly - you have to build/use all things which the command line ffmpeg tool does.

The problem with the current tvh code is missing: "-vf 'format=nv12,hwupload'" and the /dev/dri device passing.

#2 Updated by C vH about 1 month ago

To be honest I have no real knowledge how ffmpeg gets called from Tvh, I thought Tvh calls ffmpeg with some command line - there it would be relatively easy to adjust the used command line to call ffmpeg. No idea if this works this way but at least would be some workaround till a proper solution is at the table.

#3 Updated by saen acro about 1 month ago

Then what about Gstreamer

#4 Updated by Gustavo Sánchez about 1 month ago

C vH wrote:

This was similar requested a few times but this is a different approach.

current situation:

Tvh supports only nvenc (for Nvida GPUs) for hw accelerated transcoding, QSV is supported but has no real world usability (you need to patch/recompile your kernel with outdated patches + sign in for SDK ...) and was widely dropped in favor of vaapi that is supported by every Intel and AMD CPUs that are not older then ~6+ years that include an gpu.

So basically every low end CPU like the popular J1900,N3150,J3455 that are even at commercial NAS systems (Synology...) would be able to handle easily 2-3 Streams at the same time, the latest generation could even transcode H265 in real time without an problem.

Vaapi is completely integrated at the latest ffmpeg, Linux distributions support it also widely (because you only need the GPU driver) and even Tvh ffmpeg is getting build with --enable-vaapi.

What is missing:
Vaapi is used via command line switches, you can't just build ffmpeg with support for it and it works. full howto

ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i "input file" -vf 'format=nv12,hwupload' -map 0:0 -map 0:1 -threads 8 -aspect 16:9 -y -f matroska -acodec copy -b:v 12500k -vcodec 264_vaapi "output file"

possible solutions:
- Tvh offers a way to specify the command line that is used for transcoding (user could tune it their self)
- Tvh adds a profile for vaapi (this could be problematic due the different systems with maybe different paths to dri render)
- redo the transcoding profiles or "merge" the codecs branch from here https://github.com/lekma/tvheadend/tree/codecs that is sadly not finished (but works) and was intended to pred to Tvh

Hello, when implementing vaapi support, take in mind that is possible to use vaapi without X11 installed, there is no need to compile with libva_x11. libra_drm is usable and you can compile only with this library when using a headless server.

You could compile vaapi when QSV is not present in your system. Current configuration script only active vaapi when you select QSV and always try to compile with libva_x11

Is easy to change this behavior, changing configure script and Makefile.ffmpeg but when you run tvheadend it fails to open h264_vaapi codec. FFMPEG and a especial Plex version with HW transcode are running fine on my headless server, so permission and installation is OK.

I am not familiarized with ffmpeg lib use, so I can not help too much. As beta tester but there are many people as me. I look at lekmark implementation but differs so much respect to mainline, so I could not include changes from one version to other.

Lekmark version is working great on my server, but is relative old and sometimes crash. Quality is good and performance and power usage is great !!!! On a Celeron J1900 you could transcode a Full HD to a 360p, 240p, 120p with an extra use of 1w. Linux system + tvheadend streaming = 9w, Linux system + tvheadend vaapi transcode and streaming = 10w !!!! And cpu use is around 12~20%

Hope you develop a great vaapi support for tvheadend

Sorry my bad english.

Regards, Gustavo

#5 Updated by Christian Brauwers 3 days ago

This would be really nice.

I was playing around on a Synology DS916+ with the ffmpeg_vaapi Version.
Its working great with 3 Streams ... Have the ability of setup everything in TVH would be fantastic.

Also available in: Atom PDF