JPery / MJPEGWriter

Lightweight HTTP server to stream your OpenCV processing in C++
MIT License
97 stars 40 forks source link

Endless page loading #7

Closed AshleyRoth closed 5 years ago

AshleyRoth commented 5 years ago

Hello there! I'm download and sucessfully compiled your code. Run "MJPEG" and when I enter the address in the browser (localhost:7777 or 127.0.0.1:7777), the page loads indefinitely and nothing opens. in VLC the same does not work. Maybe I'm doing something wrong, can you tell?

Regards

JPery commented 5 years ago

Hi!

Are you using the example main.cpp? Which web browser are you using? The endless loading is due to how the server is actually working, but it should show the video that you are streaming.

AshleyRoth commented 5 years ago

@JPery Thanks for your answer! Yes, i use main.cpp (I did not change anything, I left everything by default). I tried browsers: Chrome, Firefox.. :(

when I used your command "g ++ MJPEGWriter.cpp main.cpp -o MJPEG -lpthread -lopencv_highgui -lopencv_core -std = c ++ 11" to compile there was an error, and I compiled it with the following command: "g ++ MJPEGWriter.cpp main.cpp -o MJPEG pkg-config --cflags --libs opencv -lpthread -std = c ++ 11"

Is this a problem? (compilation passed without errors)

JPery commented 5 years ago

I think it could be because of your OpenCV version. I have OpenCV 2.4.13.5.

Could be this the problem?

AshleyRoth commented 5 years ago

@JPery, I’m test on 3.2.0 and 3.3.0 versions, hmm, is it possible fix to older opencv version?

JPery commented 5 years ago

I've not tried the software in OpenCV3+ versions. I think this could be the problem. Could you try in OpenCV 2.4? I think you'll have to compile and install it. You can find the sources at https://opencv.org/releases.html

AshleyRoth commented 5 years ago

I check it tomorrow and write again. Thanks!

JPery commented 5 years ago

Thanks!

AshleyRoth commented 5 years ago

@JPery, Hello again! I check it on OpenCV 2.4.13.5 version, Unfortunately, the problem remains, everything also starts, but when I try to open a page with a stream, nothing happens, the page loads endlessly. Checked on another computer, the same problem: (

JPery commented 5 years ago

Hi! I've been able to recreate your problem in an Ubuntu 16.04 machine. Unfortunately I'm not been able to fix it. I don't know where the problem is coming from... I'm so sorry about that. If you find the problem please report it and a pull request will be welcome.

Thanks for your time and, again, sorry about this.

SpintroniK commented 5 years ago

Hi! Here's a patch that fixes the problem on Debian: 0001-Fixed-issue-7.-Tested-on-Debian.patch.zip I removed a few things in the header, and passed the strings lengths to the _write function. To apply the patch, unzip the file and then: git am 0001-Fixed-issue-7.-Tested-on-Debian.patch.

JPery commented 5 years ago

It's working for me in macOS and Ubuntu 16.04, so I think the bug is fixed. Thank you a lot, @AshleyRoth for reporting this issue and, of course, thanks to @SpintroniK for having fixed it.

AshleyRoth commented 5 years ago

@JPery @SpintroniK Thanks! I will test it and write again.

@JPery Tell me please, is it possible to transfer images to the input instead of video? For example, I do not have the opportunity to receive a video stream, but I can receive frames from the camera. These frames should be submitted to the input in order to get video on streaming.

Regards, Ash.

JPery commented 5 years ago

Yes, @AshleyRoth, you can stream any image of type cv::Mat. An example code to stream a simple image could be:

#include "MJPEGWriter.h"
int
main()
{
    MJPEGWriter test(7777);
    Mat frame = imread("/path/to/image.jpg");
    test.write(frame);
    frame.release();
    test.start();
    while(1){}
    test.stop();
    exit(0);
}

Hope this helps!

AshleyRoth commented 5 years ago

@JPery Thank you very much for your reply. So far I have tried to launch the corrected version, but for an unknown problem, some videos play for 1-2 seconds and freeze, some do not play at all. In the terminal it shows that I connected as a 12th client, although I am the first. I'll try to look for a problem

starrabb1t commented 5 years ago

It works great under opencv 4.0.0. I've just changed deprecated ‘CV_IMWRITE_JPEG_QUALITY' to cv::IMWRITE_JPEG_QUALITY