Enhance video quality within given pipeline. Pipeline tuning

Hi.

Consider following pipeline:

appsrc max-bytes=3817263 min-percent=10 format=time stream-type=stream do-timestamp=true min-latency=0 is-live=false caps=video/x-raw,format=(string)GRAY8,width=(int)2448,height=(int)2048,framerate=(fraction)51/4 ! videoconvert ! x264enc key-int-max=10 ! video/x-h264, profile=high ! h264parse ! qtmux ! filesink

where (I’m not sure but probably it is true) appsrc is fidded with jpeg images from camera (probably camera provides raw data, but then they converted to jpeg via OpenCV).

Are there any ways to tune provided pipeline to get better video quality? Maybe add some properties to some elements or add/remove gst elements? Mybe key-int-max=5 to get more I-frames?

Any ideas would be really helpful.

Thanks in advance.

1 Like

Hi,

Generally, you’d want to reduce the frequency of i-frames to improve the quality, so you can increase key-int-max. You can also increase the bitrate of the encoder. Those are pretty much the two things you can do.

2 Likes

Thank you very much for reply. But shouldn’t I increase fequency of I-frames (keyframes), so that there would be more of them? So, put it simple – decrease key-int-max (say to 5), decrease distance between keyframes?

As said by @ocrete, you would increase bitrate. Default bitrate is 2048, which is very low for your resolution. You would try:

... ! x264enc bitrate=8192 ...

See all properties of x264enc and their default values with:

gst-inspect-1.0 x264enc
1 Like

Keyframes don’t increase the quality, they affect where you can start decoding again when you seek or after data loss (in case of network transmission or aerial broadcast; not applicable if you write to an mp4 file).

Keyframes take up a lot of bytes, so if you have keyframes very frequently that means that you spend a lot of bytes on keyframes that could otherwise have been spent on encoding more details in non-keyframes (everything else equal).

It’s probably fine to have a keyframe only every couple of seconds or so (depends on your content of course and if you have other requirements like splicing the video later).

1 Like

Hi. Thank you so much for reply!

This moment is not clear to me – do we have some budget in terms of bytes and we should decide on which we should spend it? I mean, obviously, given live stream this seems to be the case, but given some buffer of jpegs where we need to get video of best quality with minimum size, should we pay attention to budget?
Last but not least, what you’ve metioned above is called bitrate?

Yes, assumption was that your rate control mechanism is bitrate based, in which case there is a finite budget.

If you do rate control by target quality/quantizer, it’s still true that keyframes don’t improve quality, but they also don’t make anything worse (as there’s no finite budget), they just make your file/stream larger than it would be otherwise.

1 Like