pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.52k stars 770 forks source link

Streaming video output blur when moving camera with CameraX API #1402

Closed Panha-VTechs closed 7 months ago

Panha-VTechs commented 7 months ago

Hello there,

May I know if there're any possible way to prevent streaming video output blur when moving camera with cameraX api?

Thank

pedroSG94 commented 7 months ago

Hello,

If you only have that blur in the stream result you can try using a higher bitrate in prepareVideo method but if the blur is also in the preview you will need check your cameraX code because maybe the problem is related with your autofocus.

You have a guide about bitrate here: https://support.google.com/youtube/answer/2853702?hl=en

Panha-VTechs commented 7 months ago

I have this problem only while streaming. So if i'm try using higher bitrate in prepareVideo method, it mean that it required fast internet connection. While I used high bitrate, streaming video output blur when internet connection is slow.

Thank

pedroSG94 commented 7 months ago

You can't solve it. This is the way an encoder works. If you have a low bitrate you will have that blur or pixelate while moving device.

setBitrateOnFly is used to avoid skip video frames using slow connections because lose a bit of quality is better than lose frames producing freezing. The main idea about the bitrate is maintain all time as possible a good bitrate and reduce bitrate if the internet speed is slow to avoid freezing the stream. While you have a low bitrate you can notify to the user that internet connection is poor to know that the quality is reduced and should go to a site with good connection

You can reduce the bitrate using with H265 or AV1 (recommended H265 because AV1 is not available in most of devices) because this codec need a lower bitrate to get a good quality (you can reduce like 20-30% the bitrate and get a similar quality than H264 depend of you device codec implementation)

Panha-VTechs commented 7 months ago

Okay thank you @pedroSG94. So If there're a way to choose encoder H265 as I use StreamBase Class? The idea is that we want to choose H265 if it's available if not we choose H264.

Thank

pedroSG94 commented 7 months ago

You can use H265 like this:

    rtmpCamera?.setVideoCodec(VideoCodec.H265)

If your device can't use H265 prepareVideo method return false

pedroSG94 commented 7 months ago

Remember that your media server need support H265

Panha-VTechs commented 7 months ago

Okay thank you so much @pedroSG94.