4
votes

I have a video stream with mime type video/h264 that streams live h.264 video from a security camera. I am trying to stream this real time and decode the h.264 frames (preferably hardware decode) and display them in a view. I have looked extensively for libraries or frameworks to support this but am not exactly sure which is the right approach. I have looked a little bit at the AVFoundation but not sure how to handle the video/h264 stream. Should I be grabbing each frame (I frame / P frame) from the stream and passing it the AVAssetReader? Any direction / sample code / library references would be extremely helpful!

HTTP/1.1 200 OK
Date: {date}
Connection: keep-alive
Cache-Control: no-cache, no-store
Expires: -1
Content-Type: multipart/x-mixed-replace;boundary=myboundary
Set-Cookie: stream={stream-id}; version=1

--myboundary
Content-Type: video/h264
Sync-Point: "yes" or "no"
Pre-roll: "yes" or "no"
Media-Start: "invalid" or {mediastart}
Media-End: "invalid" or {mediaend}
Stream-Start: "invalid" or {stream start time}
Stream-End: "invalid" or {stream end time}
Content-Length: {content-length}
X-Date: {x-date}

{image}
1
What protocol does your camera use, HLS,Rtsp,mjpegMichelle Cannon
Well the camera itself is being streamed via RTSP, however I am speaking to a video surveillance server that does NOT speak RTSP. Instead it just has a multipart HTTP stream with mimetype video/h264. I believe it is just a stream of NAL units.steji113
You mean some proprietary format, not HLS, you need to decode the nalu's, is there any kind of documentation, you need to decode the header to determine the packet structure, I thinkMichelle Cannon
HTTP/1.1 200 OK\r\n Date: {date}\r\n Connection: keep-alive\r\n Cache-Control: no-cache, no-store\r\n Expires: -1\r\n Content-Type: multipart/x-mixed-replace;boundary=myboundary\r\n Set-Cookie: stream={stream-id}; version=1\r\n \r\n [--myboundary\r\n Content-Type: video/h264\r\n Sync-Point: "yes" or "no" \r\n Pre-roll: "yes" or "no" \r\n Media-Start: "invalid" or {mediastart} \r\n Media-End: "invalid" or {mediaend} \r\n Stream-Start: "invalid" or {stream start time} \r\n Stream-End: "invalid" or {stream end time} \r\n Content-Length: {content-length}\r\n X-Date: {x-date}\r\n \r\n {image} \r\n]steji113
That is hard to read there but that is the specification for this stream.steji113

1 Answers

2
votes

You cannot play elementary h.264 on iOS. Your workaround can be to wrap it in a mp4 or ts stream before playing [http pd download or hls]. But unless you compile something else (like ffmpeg) onto the device you will not be able to play raw h.264