Search code examples
httpruby-on-rails-4ubuntu-16.04keep-alivemultipart-mixed-replace

Save JPEG images from HTTP multipart/x-mixed-replace keep-alive stream to ubuntu server


I have a camera which sends JPEG images to a webserver through a continuous multipart http stream. When I visit the IP address of the stream, the browser reads this stream as a series of images which mimics a video. I am wanting to download the files from this stream to a remote server.

I do not know how to parse the stream and the save the files to either my ubuntu server directly, or through my ruby on rails application filesystem.

Here is how the browser sees the stream:

Response Headers:
HTTP/1.1 200 OK
Content-Type: multipart/x-mixed-replace; boundary=frame

Request Headers:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
DNT: 1
Host: my-ip-address

Please help me find the correct approach to this problem.


Solution

  • You can use ffmpeg to download a video stream from a continues video stream. Since you are using ubuntu, you can do it by simply running a command in your terminal and save the stream to your remote server. Following command is a sample ffmpeg command to save a live stream to your local disk.

    ffmpeg.exe -y -i http://stream2.cnmns.net/hope-mp3 hopestream-latest.mp3
    

    In above command -i indicates URL to be recorded. "hopestream-latest.mp3" is the output mp3 file. You can replace this with your remote server file path.