Bug #5607
VAAPI h264 encoding: bad picture quality for a minute
0%
Description
When I'm streaming TV using the h264_vaapi codec, the picture quality is fine for the first seconds (20 seconds in the attached demo.mkv), will become unwatchable for another 45 seconds before it will be fine again (it stays fine, then).
I've also attached my settings page of the codec.
Files
History
Updated by Kai M. over 5 years ago
CPU: Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz (Skylake), integrated Graphics
BER is 0
Updated by Kai M. over 5 years ago
DVB Input using SAT>IP
12GB RAM in the machine, about 10GB free
Updated by Luis Alves over 5 years ago
I also have this issue.
It starts with a really bad quality and then after more or less 1 minute it stays fine.
I suspect of the intel driver.
Updated by Luis Alves over 5 years ago
And in my case the CPU is a i7-8700 coffee lake with 32GB ram.
Updated by saen acro over 5 years ago
OS, video driver version?
From recorded video example, it is same as DASH switch to reduced bitrate+resolution.
Updated by saen acro over 5 years ago
Are you both try to set in bios/uefi Intel GPU memory to 256+mb (2048Mb recommended) and multiple displays, as recommended for QSV?
Updated by Luis Alves over 5 years ago
Good point - at the moment I have set to 256Mb
I'll try with more as soon as I'm able to reboot the machine...
Updated by Jason Scurtu over 5 years ago
I use a little Zotak Nano CI327 for TVHeadend and encode 3x VAAPI h264 streams at once using much less RAM (4GB) and CPU/GPU.
I am using Linux and the intel-media-driver (iHD).
Since you have that issue using much beefier hardware I think its something else.
Looking at your Video, I have seen that when setting the bitrate and co. too high, well sure 3000 is really not much but just for testing, does it happen when you set it to auto (0)?
Updated by saen acro over 5 years ago
How many memory is reserved for video in your system?
GPU transcoding use video memory, rest of memory is used audio transcoding stream muxing and demuxing.
Updated by Kai M. over 5 years ago
I've increased the GPU RAM from 256MB to 1GB with no improvements.
intel-gpu-top shows about 3% Render/3D / 1.5% Video / 1.5% VideoEnhance Load.
Updated by saen acro over 5 years ago
Updated by Kai M. over 5 years ago
As the machine runs headless, intel-gpu-top shows 0% without any transcoding running. It only goes up to 1.5%/3% while transcoding.
While transcoding, it runs at about 1GHz, ~500 interrupts/s, the readings won't change while the quality is bad.
Updated by Stefan Dietzel over 5 years ago
I have the same problem with VAAPI when I use the build in transcode/av-lib part. Picture is going really bad if I set a bitrate (even 2mbit).
I solved it by using a MPEG-TS Spawn/build-in profile and use the following command-line:
/usr/bin/ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i pipe:0 -vf 'deinterlace_vaapi,scale_vaapi=w=-1:h=480,format=nv12|vaapi,hwupload' -c:a:0 libmp3lame -b:a:0 112k -ar 44100 -c:v h264_vaapi -maxrate 1572864 -b:v 1572864 -bufsize 2M -force_key_frames expr:gte(t,n_forced*3) -f mpegts -tune zerolatency pipe:1
With this i get a good quality (downscaled to 480p) and the bitrate is between 1-2 mbit.
I guess for vaapi encoding many options ffmpeg has are missing in tvheadend (very important for good picture quality is: -maxrate and -bufsize).
Updated by saen acro over 5 years ago
/usr/bin/ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i pipe:0 -vf 'deinterlace_vaapi,scale_vaapi=w=-1:h=480,format=nv12|vaapi,hwupload' -c:a:0 libmp3lame -b:a:0 112k -ar 44100 -c:v h264_vaapi -maxrate 1572864 -b:v 1572864 -bufsize 2M -force_key_frames expr:gte(t,n_forced*3) -f mpegts -tune zerolatency pipe:1
Use AAC as more supported format in hardware
-c:a libfdk_aac -ac 2 -b:a 96k
aka
ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i pipe:0 -vf 'deinterlace_vaapi,scale_vaapi=w=-1:h=480,format=nv12|vaapi,hwupload' -c:a libfdk_aac -ac 2 -b:a 96k -c:v h264_vaapi -maxrate 1572864 -b:v 1572864 -bufsize 2M -force_key_frames expr:gte(t,n_forced*3) -f mpegts -tune zerolatency pipe:1
Updated by Stefan Dietzel over 5 years ago
The problem with the Spawn solution is that it does not work with the normal HTSP sultions (like kodi plugin etc).
Therefore it would be great if some options could be added to the transcoding profiles. This would help very very much.
Updated by Stefan Dietzel over 5 years ago
Any news on this? Would it be possible to add more options to the transcoding profiles?
Updated by Luka Karinja over 5 years ago
I was working on a similar patch, i just ended using static values in my patch for bufsize and maxrate. I will try to make my patch ui configurable and i will make a pull request on github
Updated by Stefan Dietzel over 5 years ago
Could you tell me where you added the static values into the src. I want to try something but I do not find the correct entry into the transcoding sources.
It would be great if you can post your changes in this thread.
Thank you.
Updated by saen acro over 5 years ago
If someone have good programming skills,
can implement some of transcoders in this repo https://github.com/rigaya
Updated by Stefan Dietzel over 5 years ago
Problem still exists. When using the normal VAAPI encoding (transcode/av-lib) with bitrate (even 5000) first 30-45 seconds the picture quality is very bad then from one second to another it changes to good quality. Tested with actual devalopment version and newest debian buster.
Updated by Stefan Dietzel over 5 years ago
Tested with Intel(R) Celeron(R) J4005 and Intel(R) Core(TM) i5-7600T CPU. Both have the same problem.
Updated by Stefan Dietzel over 5 years ago
Find fix for this issue here: