3

I have a URL (<ip>/ipcam/mpeg4.cgi) which points to my IP camera which is connected via Ethernet. Accessing the URL resuls in a infinite stream of video (possibly with audio) data.

I would like to store this data into a video file and play it later with a video player (HTML5's video tag is preferred as the player).

However, a straightforward approach, which is simple saving the stream data into .mp4 file, didn't work.

I have looked into the file and here is what I saw (click to enlarge):

It turned out, there are some HTML headers, which I further on manually excluded using the binary editing tool, and yet no player could play the rest of the file.

The HTML headers are:

--myboundary
Content-Type: image/mpeg4
Content-Length: 76241
X-Status: 0
X-Tag: 1693923
X-Flags: 0
X-Alarm: 0
X-Frametype: I
X-Framerate: 30
X-Resolution: 1920*1080
X-Audio: 1
X-Time: 2000-02-03 02:46:31
alarm: 0000

My question is pretty clear now, and I would like any help or suggestion. I suspect, I have to manually create some MP4 headers myself based on those values above, however, I fail to understand format descriptions such as these.

I have the following video stream settings on my IP camera (click to enlarge):

I could also use the ffmpeg tool, but no matter how I try and mix the arguments to the program, it keeps telling me this error:

Community
  • 1
  • 1
AgentFire
  • 8,944
  • 8
  • 43
  • 90
  • I think you need to know the type of stream (perhaps the encoding), that your IP camera record and provide you with.. – bit Nov 12 '14 at 09:29

2 Answers2

2

It looks like your server is sending H.264 encoded 'rawvideo' in Annex B byte stream format.

It might be reformatted to .mp4 with something like below command line:

ffmpeg -i {input file} -f rawvideo -bsf h264_mp4toannexb -vcodec copy out.mp4

Saving audio/video streaming into file is not an easy job. If it's video only, using MPEG2 TS format is easiest way to go.

For .mp4 streaming, consider -movflags faststart -> Recommendation on the best quality/performance H264 encoder for video encoding?

** Update: -bsf h264_mp4toannexb option could be omitted, I'm not sure.

Community
  • 1
  • 1
9dan
  • 4,222
  • 2
  • 29
  • 44
  • I have tried many a command for **ffmpeg** and it kept telling me the error above (at the bottom of my question). I have just tried your command and it threw me almost the same message. ([link to the shot](http://i.snag.gy/ud3D7.jpg)). – AgentFire Nov 14 '14 at 10:01
  • `ffmpeg -i {input file} -f rawvideo -vcodec copy {output file}` this command worked, however it required additional processing by my own code which cut the HTML headers off from the response and re-direct the rest data of the stream like a TCP proxy. – AgentFire Nov 14 '14 at 13:39
  • @AgentFire how did you convert in finial? – Miroff May 19 '19 at 20:22
  • @Miroff I trimmed the html headers off using my own tcp proxy, and then any ffmpeg started to accept the video and it could be encoded any way you like. – AgentFire May 20 '19 at 08:49
  • @Miroff I'm afraid the sources are lost. Telling you how I done it from what I remember. – AgentFire May 20 '19 at 15:06
0

Well, this is not so straightforward as it seems:

1) HTML5 <video> tag has some requirements for the MP4 stream - it must be fragmented (it means that the internal data atoms that describe length and other data must be in the beginning of the stream). Most MP4 video files do not have this feature, so your option is to reformat them with FFmpeg or other tools (see this) and then you can actually provide the file as is.

2) Nginx has a plugin that allows streaming MP4 files, I haven't used it but it could be useful to you, since I guess it takes care of the internal stuff.

Community
  • 1
  • 1
Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71