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.56k stars 773 forks source link

Loss of image quality during broadcast #164

Closed Rishat7c closed 5 years ago

Rishat7c commented 6 years ago

I use part of the Pedro code, When the broadcast starts, after a while (seconds 5-10) the image starts to deteriorate, pixels appear :-(

I use the following parameters: bitRate - *1200 1024 iFrameInterval - 2 FPS - 30**

The source code of class rRTMP.java [https://pastebin.com/r3CWNXjY] (https://pastebin.com/r3CWNXjY)

in the main class I begin the translation as follows

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    rrtmp.prepare(width, height); // width, height
                    rrtmp.start(MainActivity.this, "rtmp://192.168.0.1:8080/live/dotnet");
                }
pedroSG94 commented 6 years ago

I can't test that code so I only can recommend you: 1 - Increase bitrate. 2 - Make sure that your decoder is not the problem (If image deteriorate in preview with that code and with decoder only then it is decoder problem).

Rishat7c commented 6 years ago

@pedroSG94,

  1. I think that the problem is probably not in bitRate
  2. There is an assumption that in my decoder initCodec() is somehow incorrectly working - the function is on line 378 or 625 (https://pastebin.com/JyREc3jv)
pedroSG94 commented 6 years ago

I think line 625 method is not the problem but you can see my decoder example and find differences: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/encoder/src/main/java/com/pedro/encoder/input/decoder/VideoDecoder.java In line 378 the problem, could be that you are opening camera with low resolution?

Rishat7c commented 6 years ago

@pedroSG94 Our decoders differ only in construction. You have a cyclical construction, but I do not have

Recorded a video. This video is broadcasted from the server in a video player. The video shows how after 10 seconds after the broadcast starts, quality loss begins :-(

https://youtu.be/-TuDgkB7OsY

Rishat7c commented 6 years ago

@pedroSG94 and problems in lightOpenGlView can not be?

pedroSG94 commented 6 years ago

But your preview if working fine or loss quality too? If work lightOpenGlView is not the problem. I saw a similar thing in a device and the reason was an error in the h264 packetizer the problem is that the code is in my job and I'm in holidays a week also I can't confirm you that this will solve it 100%. But you can try do a stream with rtsp that hasnt this bug to confirm it. To do it replace srsflvmuser to rtspclient and the use is really similar. Use this classes to compare: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtplibrary/src/main/java/com/pedro/rtplibrary/rtmp/RtmpCamera1.java https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/rtplibrary/src/main/java/com/pedro/rtplibrary/rtsp/RtspCamera1.java

Rishat7c commented 6 years ago

@pedroSG94 unfortunately our server does not support RTSP :-(

Rishat7c commented 6 years ago

@pedroSG94 Upd. Are there any solutions to this problem? If you are free of course

pedroSG94 commented 6 years ago

Sorry for late response, try with this class: https://pastebin.com/knBzvEb6 Replace your SrsFlvMuxer class with that.

Rishat7c commented 6 years ago

@pedroSG94 Unfortunately, nothing has changed. The image also continues to deteriorate :-(

pedroSG94 commented 6 years ago

I haven't more ideas :(

Rishat7c commented 6 years ago

@pedroSG94 Added small changes to the code in MainActivity and partially rolled your libraries into ours and got the following

r

MainActivity.java ( https://pastebin.com/pVqhfPsv ) Connecting your library takes place on the lines: 194, 349 and 373

pedroSG94 commented 6 years ago

This look that your lightopenglview is not inflated yet. You set surfaceholder callback to other surface not to lightopenglview

Rishat7c commented 6 years ago

@pedroSG94 If I understand you correctly, then the problem is in this function ( https://pastebin.com/hpqwtPxs ) but it is no different from the old

pedroSG94 commented 6 years ago

line 75 should be your lightopenglview I think

Rishat7c commented 6 years ago

@pedroSG94 The old version differs only in that this connection occurs during a call Proof, previous working version ( https://pastebin.com/7pn1nBSQ )

rkoshti commented 6 years ago

i am facing the same problem

pedroSG94 commented 6 years ago

@Rishat7c I don't know where is the problem in the new code, I don't see anything bad and I can't debug your app because I don't have your camera to test so it is really difficult to debug you app. I only can tell you that your actual problem usually is throw when you try use an invalid surface (normally surface not created or already destroyed in this case or maybe still in use, I think this surface is the surface of openglview that is use in the view of this surfaceview not surface created from opengl).

@rkoshti Are you experiment this issue with my original code or did you modify it? If you modify it same that @Rishat7c, debug an implementation without a code example that can't be executed to emulate the problem is difficult. If not, post me: device model, API and media server to find more info about it.

rkoshti commented 6 years ago

i am experimenting in your sample code in opengl Rtmp .

Here is my configurations

public boolean prepareVideo() { if (onPreview) { stopPreview(); onPreview = true; } if (openGlViewBase == null) { cameraManager.prepareCamera(); return videoEncoder.prepareVideoEncoder(); } else { int orientation = (context.getResources().getConfiguration().orientation == 1) ? 90 : 0;

  return videoEncoder.prepareVideoEncoder(1280, 720, 30, 1500 * 1024, orientation, false, 2,
          FormatVideoEncoder.SURFACE);

  /*return videoEncoder.prepareVideoEncoder(640, 480, 30, 1200 * 1024, orientation, false, 2,
      FormatVideoEncoder.SURFACE);*/
}

}

/**

It works when i use this configurations

*return videoEncoder.prepareVideoEncoder(640, 480, 30, 1200 1024, orientation, false, 2, FormatVideoEncoder.SURFACE);**

But it loose video quality when i modify the resolution

*return videoEncoder.prepareVideoEncoder(1280, 720, 30, 1500 1024, orientation, false, 2, FormatVideoEncoder.SURFACE);**

I am testing in Moto g4 plus (7.1 android version), Tested in multiple devices but result is same.

rkoshti commented 6 years ago

178 @pedroSG94