Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CROW to implement a MJPEG video streaming server #302

Open
shogunxam opened this issue May 2, 2018 · 8 comments
Open

Use CROW to implement a MJPEG video streaming server #302

shogunxam opened this issue May 2, 2018 · 8 comments

Comments

@shogunxam
Copy link

Using flask and sending a response like:
---Response start here----
Content-Type: multipart/x-mixed-replace; boundary=frame
--frame
Content-Type: image/jpeg
Content-Length: #image_size#

##image_data##
--frame--
---Response end here----

I was able to build a very simple MJPEG video streaming server.
Is it possible achieve the same result with CROW?
I have tried with a similar approach but I'm able to show only the first frame, I have to manually refresh the browser to send another request and receive the new frame.

@mrozigor
Copy link

mrozigor commented May 4, 2018

Could you show requests and responses, both from Flask and Crow? Maybe there are some differences in handling these requests?

@shogunxam
Copy link
Author

shogunxam commented May 5, 2018

I have tried to use wireshark to capture the packets and I have noticed a strange thing, filtering the pakets with "http.request or http.response" using crow I can se both the request and the response, using flask I can see only the request and I need to filter with "http" to see also the packets transmitted by flask.
Here what I got:

--REQUEST (it's the same for flask and crow, I'm using chrome)--
GET /video.mjpg HTTP/1.1
Host: 192.168.1.5:7071
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8
DNT: 1
Accept-Encoding: gzip, deflate
Accept-Language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7,fr;q=0.6

--CROW RESPONSE--
HTTP/1.1 200 OK
Content-Type: multipart/x-mixed-replace; boundary=frame
Server: Crow/0.1
Date: Sat, 05 May 2018 10:03:34 GMT
Connection: Keep-Alive
--frame
Content-Type: image/jpeg
Content-Length: 147113

<< Image data >>

--FLASK RESPONSE (captured filtering with http)--
--frame
Content-Type: image/jpeg
Content-Length:149932

<< Image data >>

When I'm using flask, I'm passing the "multipart/x-mixed-replace; boundary=frame" to the response class as mime-type and not as a Content-Type but I don't know how to achive this with CROW.

@mrozigor
Copy link

mrozigor commented May 6, 2018

Did you try try to return crow:response object, with custom headers? I see there is 'add_header(std::string key, std::string value)' method in this class.

@shogunxam
Copy link
Author

Yes, I'm already using the method add_header, and I'm passing the mime-type as:
response.add_header("Content-Type", "multipart/x-mixed-replace; boundary=frame");
I'm using "Content-Type" because, if I have understood well, mime-type is not a valid entry.

Anyway I think I will drop CROW to use a more tailored frame for my needed, because I have to stream only a mjpg from a webcam. Thank you any way for your help

@mrozigor
Copy link

mrozigor commented May 9, 2018

I looks like mimetype from Flask's Response class only set 'Content-Type' header. Maybe CROW doesn't stream due to double Content-Type entry as it is in your responses?

@shogunxam
Copy link
Author

I have already tried, but I get the same result, and without setting the mime-type on flask it doesn't work as well. Pheraps I'm missing a loop in frame generator. Anyway, also using flask, I don't understand who is triggering the request for the new frame.

@mrozigor
Copy link

Can you maybe make wireshark dump with Flask streaming session, as well as Crow? Or maybe there is some method to dump response object in Flask?

@Rz-Rz
Copy link

Rz-Rz commented Sep 5, 2024

Sorry for posting in an old topic but I'm having the same problem I can't seem to get MJPEG streaming to work on Crow cpp webserver, here's an issue I opened : CrowCpp/Crow#890

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants