Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a video-streaming server from a raw H.264 frame stream [closed]

I have a IP camera (VisionTech VN6xSM3Ti) which returns me a video stream of H.264 raw data, how can I use this stream to create a live-stream that can be accessed through an HTML5 browser?

To access the camera stream, I must follow a specified protocol from the manufacturer, so it's not as easy as to just access it with the IP address.

I already have the code in C# and C that reads the camera stream as a byte array, but I don't know how to go on.

I've been thinking on solving it with Node.JS and my code as follows:

  1. Access the camera stream with my code and expose it through a local socket
  2. In Node.JS access the created socket and stream its contents to all the clients

IP Camera raw Data ---> My Code --- Local Socket --> Node.js --- ?? ---> Clients

Does anyone knows if this can be done? or is if there's a better option?

like image 481
edua_glz Avatar asked Nov 01 '22 13:11

edua_glz


1 Answers

Assumptions:
I am assuming the following: the H264 stream is AnnexB type, you can read it in chunks and the prerequisite is to write the data in chunks (streaming). The output data is playable in a browser without any extensions or special players.

Proposal:
You need to read a chunk of data, remux the raw h264 data to fragmented mp4 and send the chunk of that file to a client. In order to do that, probably the easiest solution would be to use FFMpeg and pipes.

FFMpeg:
FFMpeg can use pipe input and output (answer ref). To receive the raw h264 stream, remux the stream to a mp4 that is fragmented (answer ref) and write an output do the following (not tested):

ffmpeg -f h264 -i pipe: -c copy -f mp4 -movflags frag_keyframe+empty_moov pipe:

That command will read raw h264 data from a standard input, copy the stream (no re-encoding) and mux it to a fragmented mp4 to standard output.

In C# you can start an external process Process.Start, write to its Process.StandardInput the bytes you receive and read the Process.StandardOutput. The output should be fragmented mp4 which should be playable in a browser.

Remarks:
1. A drawback would be an inability to seek a video, but if I understood you correctly, it is a live stream, so that should be fine.
2. The input stream is not re-encoded, only remuxed. That is the fastest processing, but if you want more control: e.g. to output h265 or to specify the fragment size then a stream must be re-encoded during the process (high CPU usage).

like image 56
dajuric Avatar answered Nov 13 '22 16:11

dajuric