RTSP to TS/OGG/FLV streaming

Topics: Question
May 2, 2015 at 10:07 PM
Hi,
I have camera with H264/AAC (codec) source via RTSP. I would like to broadcast it via TS/HLS for iOS or OGG/HLS or FLV (for android?) I don't have almost any experience so correct me if I am wrong.

I connected sucessfully to camera (RTSP client part). This was simple and works perfectly. From this point I have to depacketize stream to get (undecoded) video frames and then packetize them to TS/HLS or OGG/HLS using containers from MMA and then send everything (HTTP enveloped) via HTTP handler to client.
Is there any sample or "pseudo code" available to see a basic priciple how to do that using MMA, please?
Thank you for this awsome peace of work.
May 3, 2015 at 12:56 PM
Hi there,

I can only help you with the depacketizing of the h264, but that might help you a little bit on the way. I assume that by connecting correctly to the rtsp stream you are receiving data in your RtpFrameChanged event handler.

Handling these RTP frames is quite simple. If the data is always h264 and there is no way this will ever change, you can simply use something like this:
using ( RFC6184Media.RFC6184Frame hframe = new RFC6184Media.RFC6184Frame(frame)){
    hframe.Depacketize();
    if (hframe.Buffer == null || hframe.Buffer.Length == 0) return;
    byte[] bytes = hframe.Buffer.ReadFullyToByteArray();    
}
The ReadFullyToByteArray method is an extension method that simply uses the stream and reads it into a byte[] (you get a stream back in case your next step might work better using that).

Whatever you do with those bytes (or stream) make sure you don't do to much in the event handler since this will slow the background processing down. I've solved this simply by using a ConcurrentQueue and not doing any processing in the event handler at all besides putting the new frame in the queue.

Hope this helps you a little bit!
Marked as answer by juliusfriedman on 5/4/2015 at 5:55 AM
May 3, 2015 at 9:30 PM
Thank you for your help. Further help I need is how to pack this frames into segmented "ts" file, which in essence is group of frames enveloped in "MPEG-TS" container(?). So, missing part is how to save these frames to "mpeg-ts" container with all logic(GOP, start frame, timestamps, timespan up to 10s, endframe).

Implemented containers in MMA are "readers" only. Is there any plan to implement "writers" or any example on c# how to do that, please?