Live555 fMaxSize and FFMPEG

2.8k views Asked by At

I have built a version of Live555 that uses FFMPEG to encode a video and stream it over RTSP.

Basically it works but the RTSP stream is very jittery.

I looked into it further and it turns out that Live555's max buffer size (fMaxSize) is too small and Live555 is truncating the frame as shown below:

/* This should never happen, but check anyway.. */
if (newFrameSize > fMaxSize) {
  fFrameSize = fMaxSize;
  fNumTruncatedBytes = newFrameSize - fMaxSize;
} else {
  fFrameSize = newFrameSize;
}

Now, I have almost no control over how big the packets are from FFMPEG, I can set the bitrate low but the quality is appauling and the packets are still too big!

Basically FFMPEG decides how big each frame is here:

int reti = avcodec_encode_video2(m_c, &pkt, m_frame, &got_packet);

If pkt.size > fMaxSize then the frame will be truncated and Live555 will stuff up streaming the video, which is does ALL the time. Also FFMPEG sometimes decides to buffer frames so the packet could be more than one frame big.

I can try and tell Live555 to up it's buffer size but it ignores it completely:

OutPacketBuffer::maxSize = 100000;

Has anyone else got a solution to stream the encoded video correctly? I have tried breaking the packets up and passing them to Live555 in smaller chunks but it doesn't work, and Live555 brings down it's fMaxSize if I send more packets.

My code is here:

https://dl.dropboxusercontent.com/u/15883001/Code.zip

Some images of what is happening to the RTSP stream is here, as you can see in the higher detail images LIVE555 struggles to send the packets properly:

https://dl.dropboxusercontent.com/u/15883001/vlcsnap-2013-12-12-09h34m30s225.zip

In the black and white image, the frame size is 117000 bytes and is less than the max frame size 300000

In the Iron coloured image, the frame size is 212000 bytes.

In the rainbow coloured image, the frame size is 322000 bytes and is greater than the max frame size 300000 and is truncated resulting in what you see in the example image.

Any help would be much appreciated

Thanks

1

There are 1 answers

6
av501 On BEST ANSWER

You need to do correct packetization of data. Live555 already has everything. Look at how it works by reading from a file, packetizing it to rtp and then sending it. The only difference here is you are taking it from a encoder instead of file.