ultravideo / uvgRTP

An open-source library for RTP/SRTP media delivery
BSD 2-Clause "Simplified" License
318 stars 90 forks source link

Streaming H264 video #207

Closed wdtkr closed 10 months ago

wdtkr commented 10 months ago

hello,

I would like to stream video using cisco's openh264.

Configuration on the sender side:

uvgrtp::context ctx;
uvgrtp::session *sess = ctx.create_session(REMOTE_ADDRESS);
int send_flags = RCE_PACE_FRAGMENT_SENDING | RCE_SEND_ONLY;
uvgrtp::media_stream *strm = sess->create_stream(REMOTE_PORT, RTP_FORMAT_H264, send_flags);
strm->configure_ctx(RCC_MTU_SIZE, 1500);

... Encoding process ...

if (strm->push_frame(layerInfo.pBsBuf + layerSize, layerInfo.pNalLengthInByte[nal], RTP_NO_H26X_SCL) ! = RTP_OK)
{
    cerr << "Failed to send RTP frame" << endl; }
}

Receiver's configuration:


uvgrtp::context ctx;
uvgrtp::session *sess = ctx.create_session(LOCAL_ADDRESS);

// create RTP stream (receive only)
int receive_flags = RCE_RECEIVE_ONLY | RCE_NO_H26X_PREPEND_SC;
uvgrtp::media_stream *h264 = sess->create_stream(LOCAL_PORT, RTP_FORMAT_H264, receive_flags);

while (true)
{
    // receive data from uvgRTP
    frame::rtp_frame *frame = h264->pull_frame(1000);

    SBufferInfo bufInfo;
    memset(&bufInfo, 0, sizeof(SBufferInfo));
    unsigned char *pData[3] = {nullptr, nullptr, nullptr};
    int ret = decoder->DecodeFrameNoDelay(frame->payload, frame->payload_len, pData, &bufInfo);
    if (ret == 0 && bufInfo.iBufferStatus == 1)
    {

... Decode process...
    else
    {
        cerr << "Error code ret: " << ret << ",, bufInfo.iBufferStatus: " << bufInfo.iBufferStatus << endl;
    }

However, these have a ret of almost 18 and bufInfo.iBufferStatus of 0.

I tried saving the received data as download.264 and converting it to mp4 with ffmpeg, but that did not work either. I am thinking that there is not an encoding/decoding problem, but a mistake in the way I send or receive (use) the data with uvgRTP. can you give me some advice?

Also, when streaming camera video in real time with uvgRTP, is it usually stupid to combine it with openh264, like this?

Sorry for my poor English, thank you in advance.

wdtkr commented 10 months ago

After looking at some of the packets, I noticed that a number of hexadecimal numbers at equal intervals (about 4000 characters) were missing 8 characters (e.g., 8f 4c 4b 65 b1 c6 32 1f) when received. What could be causing this?

wdtkr commented 10 months ago

The problem was that strm->configure_ctx(RCC_MTU_SIZE, 1500); had set mtu-size to 1500. The size of the data being sent was 1504, perhaps because the first 4 bytes are given, which caused the back 4 bytes to be lost on reception. The mtu-size of the local host was up to 1500, so all I had to do was change strm->configure_ctx(RCC_MTU_SIZE, 1400);.