Project

General

Profile

Bug #5607

VAAPI h264 encoding: bad picture quality for a minute

Added by Kai M. over 5 years ago. Updated over 5 years ago.

Status:
New
Priority:
Normal
Category:
Streaming
Target version:
-
Start date:
2019-04-19
Due date:
% Done:

0%

Estimated time:
Found in version:
4.3-1789~g6bfeca6c0
Affected Versions:

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

demo.mkv (20.8 MB) demo.mkv demo Kai M., 2019-04-19 15:44
h264 vaapi.png (40.9 KB) h264 vaapi.png settings Kai M., 2019-04-19 15:44
1.png (17.9 KB) 1.png Stefan Dietzel, 2019-04-26 10:57
2.png (33.6 KB) 2.png Stefan Dietzel, 2019-04-26 10:57

History

#1

Updated by saen acro over 5 years ago

With witch CPU/GPU
Is there BER on transponder/mux?

#2

Updated by Kai M. over 5 years ago

CPU: Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz (Skylake), integrated Graphics

BER is 0 :)

#3

Updated by saen acro over 5 years ago

IPTV or DVB input do you have enough RAM?

#4

Updated by Kai M. over 5 years ago

DVB Input using SAT>IP

12GB RAM in the machine, about 10GB free

#5

Updated by saen acro over 5 years ago

intel-gpu-top

what is usage during problematic part
#6

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.

#7

Updated by Luis Alves over 5 years ago

And in my case the CPU is a i7-8700 coffee lake with 32GB ram.

#8

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.

#9

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?

#10

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...

#11

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)?

#12

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.

#13

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.

#15

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.

#16

Updated by Kai M. over 5 years ago

If I set the bitrate to 0, the quality will stay normal.

#17

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).

#18

Updated by Stefan Dietzel over 5 years ago

#19

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
#20

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.

#21

Updated by Stefan Dietzel over 5 years ago

Any news on this? Would it be possible to add more options to the transcoding profiles?

#22

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

#23

Updated by Stefan Dietzel over 5 years ago

That would be great.

#24

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.

#25

Updated by Stefan Dietzel over 5 years ago

Anything new for this problem?

#26

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

#27

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.

#28

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.

#29

Updated by Stefan Dietzel over 5 years ago

Find fix for this issue here:

https://tvheadend.org/issues/5701

Also available in: Atom PDF