Synology DS718+ VAAPI hevc transcoding - SOLVED

TVMosaic live and recorded TV products for Desktop/NAS/Raspbery Pi
Post Reply
leone007
Posts: 3
Joined: Mon Feb 10, 2020 10:46 am

Synology DS718+ VAAPI hevc transcoding - SOLVED

Post by leone007 » Mon Feb 10, 2020 11:10 am

I have a Synology DS718+ NAS, and I was using tvheadend where I was able to do vaapi transcoding to hevc output as a ts-spawn profile using the following command line

Code: Select all

/usr/local/ffmpeg/bin/ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i pipe:0 -vf 'deinterlace_vaapi=rate=field:auto=1' -c:v hevc_vaapi -profile main -b:v 4000k -compression_level 7 -c:a aac -b:a 96k -f mpegts pipe:1
-compression_level has to be 7 (lowest compression) for this to work, any other setting results a f...ed up stream.

This was done using ffmpeg 4.2.2 from th0ma7's repo, which is installed on my NAS.

Now since in kodi htsp tvheadend client you cannot access ts-spawn profiles, I'd like to switch to tvmosaic.

- I have created a new profile for transcoding.

in info file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<profile_info>
	<name>VAAPI (Intel/i965) hardware accelerated x265 transcoding</name>
	<default>false</default>
	<type>builtin</type>
	<env>
		<var>LIBVA_DRIVER_NAME=i965</var>
		<var>LIBVA_DRIVERS_PATH=%FFMPEGDIR%/dri</var>
	</env>
</profile_info>
transcode_live_to_ts.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<usecase>
	<params>
		<param>-hwaccel</param>
		<param>vaapi</param>		
		<param>-vaapi_device</param>
		<param>/dev/dri/renderD128</param>		
		<param>-hwaccel_output_format</param>
		<param>vaapi</param>		
		<param>-analyzeduration</param>
		<param>2500000</param>		
		<param>-i</param>
		<param>%SRC%</param>
		<param>-f</param>
		<param>mpegts</param>
		<param>-acodec</param>
		<param>aac</param>
		<param>-c:v</param>
		<param>hevc_vaapi</param>
		<param>-compression_level</param>
		<param>7</param>
		<param>-async</param>
		<param>1</param>
		<param>-ab</param>
		<param>128k</param>
		<param>-qp</param>
		<param>25</param>
		<param>-level</param>
		<param>31</param>
		<param>-bf</param>
		<param>4</param>
		<param dimensions="false" scale="false">-vf</param>
		<param dimensions="false" scale="false">deinterlace_vaapi=rate=field:auto=1</param>
		<param dimensions="true">-vf</param>
		<param dimensions="true">deinterlace_vaapi=rate=field:auto=1,scale_vaapi=w=trunc(iw*(%HEIGHT%/ih)*sar/32)*32:h=trunc(ih*(%HEIGHT%/ih)/16)*16</param>
		<param scale="true">-vf</param>
		<param scale="true">deinterlace_vaapi=rate=field:auto=1,scale_vaapi=w=trunc(iw/%SCALE%/32)*32:h=trunc(ih/%SCALE%/16)*16</param>
		<param bitrate="true">-b:v</param>
		<param bitrate="true">%BITRATE%k</param>
		<param>-map</param>
		<param>0:v:?</param>
		<param>-map</param>
		<param>0:a</param>
		<param>-y</param>
		<param>%DEST%</param>
	</params>
</usecase>
Now I receive a stream with 0 fps, with a sill image, the sound is OK.

My question is: how can I use the aformentioned 4.2.2 ffmpeg instead of the "builtin" version? (I believe that is the one causing the issues) I did try with "external" and "system", with no output at all. "system" probably refers to the quite outdated 2.7.1 ffmpeg version that comes with latest DSM version, that has no VAAPI support, so I didn't expect much success from that anyway, since I had to give the full path to 4.2.2 in my command line above, having the same issue when not specifying path to ffmpeg using the system built in.

Probably worth mentioning that this version of 4.2.2 uses iHD drivers instead of i965
Last edited by leone007 on Thu Feb 13, 2020 11:54 am, edited 1 time in total.

leone007
Posts: 3
Joined: Mon Feb 10, 2020 10:46 am

Re: Synology DS718+ VAAPI hevc transcoding

Post by leone007 » Thu Feb 13, 2020 11:49 am

SOLVED using "external" ffmpeg installation type tag.

1. I copied my Synocommunity ffmpeg library to TVMosaic's stored user files location

Code: Select all

HOME-NAS:/usr/local/ffmpeg$ ls
app  bin  etc  lib  share  var

Code: Select all

HOME-NAS:/usr/local/ffmpeg$ cp /usr/local/ffmpeg/ /volume1/TVMosaic -R
I had to create the subfolders (/app /bin /etc /lib /share /var) in the TVMosaic ffmpeg folder myself to be able to copy into them, this must be some sort of linux/synology user permission stuff I'm not familiar with :D Without it, you'll get errors like:

Code: Select all

HOME-NAS:/usr/local/ffmpeg$ cp /usr/local/ffmpeg/ /volume1/TVMosaic -R
cp: cannot create directory ‘/volume1/TVMosaic/ffmpeg/app’: Permission denied
cp: cannot create directory ‘/volume1/TVMosaic/ffmpeg/var’: Permission denied
So just create them manually using File Station (as admin)

2. Since I had to specify the driver path to TVMosaic, I had to copy the drivers from the volume1/TVMosaic/ffmpeg/lib directory's content to volume1/TVMosaic/ffmpeg/bin/dri directory (that is where TVMosaic is looking for it, and probably copying the video drivers (i965_drv_video.so and iHD_drv_video.so) would have been sufficient, but I didn't want to take chances)

3. I have modified my hevc profile's info file to:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<profile_info>
	<name>VAAPI HEVC (Intel/iHD) hardware accelerated transcoding</name>
	<default>false</default>
	<type>external</type>
	<env>
		<var>LIBVA_DRIVER_NAME=iHD</var>
		<var>LIBVA_DRIVERS_PATH=%FFMPEGDIR%/dri</var>
	</env>
</profile_info>
please notice that I have changed LIBVA_DRIVER_NAME to iHD, this is due to i965 driver is having issues transcoding 1080p 50 fps videos with this GPU at least. (and eventually I did this to that standard h264 vaapi profile too)

whereas my trascode_live_to_ts.xml looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<usecase>
	<params>
		<param>-hwaccel</param>
		<param>vaapi</param>		
		<param>-vaapi_device</param>
		<param>/dev/dri/renderD128</param>		
		<param>-hwaccel_output_format</param>
		<param>vaapi</param>		
		<param>-analyzeduration</param>
		<param>2500000</param>		
		<param>-i</param>
		<param>%SRC%</param>
		<param>-f</param>
		<param>mpegts</param>
		<param>-acodec</param>
		<param>aac</param>
		<param>-c:v</param>
		<param>hevc_vaapi</param>
		<param>-compression_level</param>
		<param>7</param>
		<param>-async</param>
		<param>1</param>
		<param>-ab</param>
		<param>128k</param>
		<param>-qp</param>
		<param>25</param>
		<param>-level</param>
		<param>31</param>
		<param>-bf</param>
		<param>4</param>
		<param dimensions="false" scale="false">-vf</param>
		<param dimensions="false" scale="false">deinterlace_vaapi=rate=field:auto=1:mode=motion_adaptive</param>
		<param dimensions="true">-vf</param>
		<param dimensions="true">deinterlace_vaapi=rate=field:auto=1:mode=motion_adaptive,scale_vaapi=w=trunc(iw*(%HEIGHT%/ih)*sar/32)*32:h=trunc(ih*(%HEIGHT%/ih)/16)*16</param>
		<param scale="true">-vf</param>
		<param scale="true">deinterlace_vaapi=rate=field:auto=1:mode=motion_adaptive,scale_vaapi=w=trunc(iw/%SCALE%/32)*32:h=trunc(ih/%SCALE%/16)*16</param>
		<param bitrate="true">-b:v</param>
		<param bitrate="true">%BITRATE%k</param>
		<param>-map</param>
		<param>0:v:?</param>
		<param>-map</param>
		<param>0:a</param>
		<param>-y</param>
		<param>%DEST%</param>
	</params>
</usecase>
The GPU is powerful enough to hevc transcode 1080p 50 fps for a single stream only, but in my use case this is what I needed (either due to likely limited bandwidth during travel or Fire TV Stick 4k deinterlace problems).

That is it :)

Post Reply