I have a C++ program that reads a video from a camera (using OpenCV)and sends it to a Web server.
I can see the video stream in a browser.
Now I want to add record buttons to the video in the browser.
Basically, I want the user to be able to click on the record button in the browser, and in the C++ program the video to start being written somewhere.
What is the best and fastest way to do such thing?
Should I use CGI?
The fastest way is probably to just to dump the stream data you already have directly to disk. You can postprocess it back to a normal video file with compression and all the trimmings when they stop recording, quietly, in the background (show a "saving file" progress bar or something while you work it).
Anything else is going to take time -- to reformat and recompress the data.
Thank you. This is a good idea to have the post-process when the user stops recording.
Aside from that, I don't know how to make the recording happen.
I want the webpage to have a record button and when the user clicks on it some function in the C++ program to run (write video).
I read about CGI but I am not sure if that is the right way to go.
do you know how to write into a binary file? If not, google some examples of that.
you have *something* in hand as your 'stream'.
lets say you have 'frames' (images) in hand: then you loop and write the images back to back into the file with the file.write() command. Or say you have compressed video stream data.. you have a chunk of that in a buffer, you flush that to disk every time you get a chunk of it.
the post processing will read the file back in and make it a playable video file. Whatever library you need for that -- it depends on what your 'stream' data really is and what you want to do to it when you save it to another file type.
It feels like you are reinventing the wheel... there is surely something out there already that does this for you that you can just use in your web page, unless you are trying to learn it or play with it. If you are doing something real, you may also want a piece of hardware in your server to do the video processing -- its a lot for a CPU and if you have thousands of users at once you will need a whale of a computer to do it that way. I assume you are just playing with this?
Yes, it is not for multiple users. It is just a small application with one camera and one PC.
I have a camera connected to a PC (webserver) and I can see the video stream of the camera inside a browser (localhost:8080).
Now I want to add a button under the video in the browser that when it is clicked the video stream starts recording on the server.