-
-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forward H264 over RTSP #1033
Comments
Thank you! How can I determine the flags to be set? |
As I told you 1 for "normal frames (no IDR)" and 5 for keyframes (IDR). You have a table with nal unit values here: |
Got it. I am using rtsp-simple-server to run the RTSP server.
|
Close but not correct at all. Try this: public void onVideoFrame(@NonNull byte[] frame, int size, boolean isIdr) {
ByteBuffer h264Buffer = ByteBuffer.wrap(frame);
info = new MediaCodec.BufferInfo();
info.size = size;
info.offset = 0;
info.presentationTimeUs = System.nanoTime() / 1000 - presentTimeUs;
if(isIdr) {
info.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME;
if (!rtspClient.isStreaming()) {
presentTimeUs = System.nanoTime() / 1000;
Pair<ByteBuffer, ByteBuffer> videoData = decodeSpsPpsFromBuffer(h264Buffer, size);
ByteBuffer newSps = videoData.first;
ByteBuffer newPps = videoData.second;
rtspClient.setVideoInfo(newSps, newPps, null);
rtspClient.connect("<rtsp://<rtsp-server-IP>:8554/mystream");
}
}
if (rtspClient.isStreaming()) {
rtspClient.sendVideo(h264Buffer, info);
}
} With this you avoid send video until you connect and keyframe flag is correctly send (previously it is only set the first time) |
Thank you!. I tried your corrected code and no crashes but the output on the receiving player seems to be corrupt. This is the ffplay log. [rtsp @ 0x7f2750000b80] setting jitter buffer size to 0 0B f=0/0 |
sprop-parameter-sets is too large. It seems incorrect so your SPS and PPS is not correct. Try create a fake sps and pps using byte[] generated by your mobile using the same resolution: Anyway, the correct way should be extract it from bytebuffers of the incomming stream. You can check if you receive nal unit type 7 (sps) and 8 (pps) to get the correct values. |
Your right. Fixed my sps, pps buffers and it works now. Thank you again for the excellent work and support! |
I have a H264 video stream coming in from a server as a byte[].
How can I forward it over RTSP? Is there a sample code I could refer to?
The text was updated successfully, but these errors were encountered: