Git Product home page Git Product logo

mjpegwriter's People

Contributors

jpery avatar otamay avatar spintronik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mjpegwriter's Issues

Threaded example

Hi,

I am new to the c++.

how we can put the mjpeg server a std::thread ? so video cap and mjpeg server will be separate thred ?

Best

Compiling under Ubuntu 18.04

Compiling led to a few undefined references under Ubuntu 18.04. The following might be a better way to compile this if you want to stick to pure g++:

g++ MJPEGWriter.cpp main.cpp -o MJPEG -lpthread `pkg-config opencv --cflags --libs` -std=c++11

Does this work in chrome?

It works well with vlc player. However chrome only shows first image. Is there any way to test in the browser using img src tag?

Accessing the stream

Hi,
I'm trying to use your code to stream mjpg from a c++ application. The code is running and the server is accepting connections, however I can't seem to access the video (either from the browser or VLC).
Could you specify the exact URL of the stream? Sorry if it's a bit basic...

Thanks!

Endless page loading

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

Compilation on raspberry using opencv 4.5.0-pre library.

I installed opencv library version 4.5.0-pre on raspberry pi 4.
But I have errors:

/usr/bin/ld: /tmp/ccjurhlf.o: неопределённая ссылка на символ «_ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERSt6vectorIhSaIhEERKSB_IiSaIiEE»
 /usr/bin/ld: //usr/local/lib/libopencv_imgcodecs.so.4.5: error adding symbols: в командной строке не указан DSO
 collect2: error: ld returned 1 exit status

I solved this problem by replacing CV_ * with cv :: in the file according to this recommendation. Also I used the following command to compile.

sudo g++ MJPEGWriter.cpp main.cpp -o MJPEG -lpthread -lopencv_highgui -lopencv_core -lopencv_imgcodecs -lopencv_videoio -std=c++11

sending data / using processing time even when no client is connected

i compiled it and i works, great idea and was exactly what i was looking for. I could stream frames coming from hardware to firefox / vlc.

i noticed though that as soon as its started, it takes up a lot of processing time (from looking over the code it seems the load comes from the Writer) which keeps writing even when no client is yet connected / or the last client disconnected

would it not be better if it starts writing only after at least one client is connected (and stops after the last disconnects)?
If no client is connected just Listen and wait until one connects or is there smt that would stand against that?

License

Hey, any chance you could add a license to this project? Preferably MIT or something related would be nice.

Thanks!

Screen Tearing Problem

First I converted my output QImage to Mat and then I write that converted Mat in MJPEGWriter. I observed screen tearing problem.
How can I solve this problem?

Do I need a HTTP server to do this?

Dear JPery,

I would like to implement this method in my project, but I am curious whether do I need a HTTP server to have this done?

Thank you

Socket: is accepting nonexistent connection

Hi, I'm compiling for raspbian and the program works but socket "accept" command is returning -1 as soon as it is reached. One hot fix is to move all open() code to Listener() (before loop), maybe there is a problem with sharing resources between threads?

This is my working code:

void
MJPEGWriter::Listener()
{
    fd_set rread;
    SOCKET maxfd;
    sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    // SOCKADDR_IN address;
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = INADDR_ANY;
    address.sin_port = htons(port);
    if (::bind(sock, (SOCKADDR*)&address, sizeof(address)) == SOCKET_ERROR)
      {
	cerr << "error : couldn't bind sock " << sock << " to port " << port << "!" << endl;
	return;
      }
    if (listen(sock, NUM_CONNECTIONS) == SOCKET_ERROR)
      {
	cerr << "error : couldn't listen on sock " << sock << " on port " << port << " !" << endl;
	return;
      }
    cout << "Listening on socket " << sock << " on port " << port << "..." << endl;
    FD_SET(sock, &master);
    // cout << "Master: " << master << endl;

    while (true)
    {
        rread = master;
        struct timeval to = { 0, timeout };
        maxfd = sock + 1;
        int sel = select(maxfd, &rread, NULL, NULL, &to);
        if (sel > 0) {
            for (int s = 0; s < maxfd; s++)
            {
                if (FD_ISSET(s, &rread) && s == sock)
                {
		    sockaddr_in client_addr;
                    socklen_t         client_addr_len = sizeof(client_addr);
                    // SOCKADDR_IN address = { 0 };
                    SOCKET      client = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len);
                    if (client == SOCKET_ERROR)
                    {
                        cerr << "error : couldn't accept connection on sock " << sock << " !" << endl;
                        return;
                    }
                    maxfd = (maxfd>client ? maxfd : client);
                    pthread_mutex_lock(&mutex_cout);
                    cout << "new client " << client << endl;
                    pthread_mutex_unlock(&mutex_cout);
                    pthread_mutex_lock(&mutex_client);
                    _write(client, (char*)"HTTP/1.0 200 OK\r\n", 0);
                    _write(client, (char*)
                        "Server: Mozarella/2.2\r\n"
                        "Accept-Range: bytes\r\n"
                        "Connection: close\r\n"
                        "Max-Age: 0\r\n"
                        "Expires: 0\r\n"
                        "Cache-Control: no-cache, private\r\n"
                        "Pragma: no-cache\r\n"
                        "Content-Type: multipart/x-mixed-replace; boundary=mjpegstream\r\n"
                        "\r\n", 0);
                    clients.push_back(client);
                    pthread_mutex_unlock(&mutex_client);
                }
            }
        }
        usleep(1000);
    }
}

Can I ask you something?

Hi, I'm making Image processing auto-line-tracing vehicle by raspberry-pi.

and, Im beginer of opencv. I tried to find information about that by google, books etc.

Finally , I found your git . Thank you so much.

I toke the code on my vehicle, and this is the picture,
image

I want the picture rotate 180 angle and remove (some?) color correction filter.
(truly, I also want more resolution)
So please give me the way .... THANK YOU

Authorisation

Is there anyway the stream encoded can be authorised with username and password?

Something here seems to be hoarding memory

I have incorporated this into a C++ design on ARM. I instantiate MJPEGWriter in the class in another classes constructor like this:

mjpgWriter = new MJPEGWriter(8080);

Then to write a new frame I use this code:

mjpgWriter->write(drawing); if(!mjpgWriter->isOpened()) { mjpgWriter->start(); }

Over the course of about a day MJPGWriter goes from consuming very little to all of the system memory (4GB in this case) and crashes.

Any idea why this might be happening?

stop() function halting

hi, first thank you for pulling the example together, I've benefited from it a lot as a socket noobie.
When I ran the example, I was having issue stoping the socket thread on both listens & writes. It seems to stuck at p_thread trying to join the writes & listens. Would you kindly provides some insight ? Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.