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 768 forks source link

Keyframes not sent if display is not moving? #398

Closed pesutt closed 3 years ago

pesutt commented 5 years ago

Hi,

First of all thank you for your great project! :)

I've been testing with a red5pro server and Samsung phones, and I've been wondering if it's possible to send a constant video stream, even when there is no user interaction? I am using the DisplayRtmpActivity without audio.

The issue is that if the connection quality is not perfect, then it is possible that the last frame sent was not received in a good quality by the consumer, so it sometimes stays in a pixelated state.

The initNotification Method is called, but I don't see any notification. I'm running a Samsung S8 with Android 9. Tested it with Android 8, but did not see any notification either. Any hints to what might be wrong would be highly appreciated.

I noticed that it only periodically sends audio packets, and not video packets.

Thanks in advance! Best regards, Toni

pesutt commented 5 years ago

Sorry, my description was a bit wrong. I just checked the log and observed:

Is it possible that the Keyframes would still be sent, even without any change on the screen?

pedroSG94 commented 5 years ago

I think this is related with your issue https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/issues/63

pesutt commented 5 years ago

Agreed, unfortunately the Notification is not showing up on my devices, but I haven't found the issue yet.

pesutt commented 5 years ago

Ok, so for Android API 26+ a Notificationchannel has to be created first, that's why it didn't work. Also I had to use NotificationCompat instead of Notification. [https://developer.android.com/training/notify-user/build-notification](Android doc)

gopopov commented 4 years ago

Hello, I am having a similar issue it seems where the encoder send keyframes irregularly ( seems at first it does not send keyframe for 30secs then it will send keyframe every 180 frames, independently from what I have it set. ( I've played around with 30fps and 60fps values ) and set keyframe to 2,4, 60 etc

` @Override public void onClick(View view) {

            if (isStreaming) {
                rtmpCamera1.stopStream();
                isStreaming = false;
            } else if (rtmpCamera1.prepareAudio() && rtmpCamera1.prepareVideo(640, 480, 30, 4500000, false, 2
            , 90)) {
                rtmpCamera1.startStream("rtmp://live.twitch.tv/app/$$$$");
                isStreaming = true;
            }
        }
    });

}`
gopopov commented 4 years ago

@pedroSG94 what are your thoughts on they keyframe interval inconsistency I am experiencing. Are those values supposed to be per Frame or per second (gop length)?

Depending on what framerate / iframe is set, I get I lot of these: I/SrsFlvMuxer: frame discarded

pedroSG94 commented 4 years ago

According with Android documentation encoder should send a keyframe like this: FPS / iframe = 1 key frame each encoding these frames. If you set iframe = 0 this means all frames will be keyframes and this result in a large buffer that could be related with your frame discarded log. This log means that you are producing frames faster than you can send it. About inconsistency, I don't know the reason. I think this is related with mediaprojection api.

mkrn commented 4 years ago

The value for iFrameInterval seems to be in seconds (int)

Android documentation says:

Most video encoders will convert this value of the number of non-key-frames between key-frames, using the frame rate information; therefore, if the actual frame rate differs (e.g. input frames are dropped or the frame rate changes), the time interval between key frames will not be the configured value.

So the issue then is that due to the initial frame dropping keyframe interval may be too long.