I am an intermediate Processing user trying to make the transition to oF so I can work better with video.
As a first project I’m trying to make a simple application that records 3 seconds of video from the webcam whenever a key is pressed, and then loops it.
I found a few libraries that deal with playing a video file or grabbing live video from a camera.
However, I can’t seem to find a simple library for Windows (code blocks) that deals with recording video to file, and then playing it.
Or is it possible to skip entirely the recording to file as I need only 3 seconds of Video? Maybe keep the frames in memory some other way?
Any tips or nudges in the right direction would be appreciated.
You can try this
I could never get it working really well. I also had wanted to do this. I was working in HD. I had the following issues. I had trouble getting high quality recordings firstly (I wanted them to be kind of long so storing everything in memory was not an option)- if you look there are some 64 bit builds that will allow you to address more memory.
I was on mac, there are a few options available for recording actual movies.
uses avfoundation and has a longer wait time before the movie is ready (you will also need to modify the code a little to make it record incoming video)
There is also this to help
This uses ffmpeg and is a little faster at finishing the video but still takes a little while for the movies to be ready. I also was looking for very high quality HD video and this was not that easy to get - I could not do real time proress encoding with this but I think it is possible if you tweak the way it uses ffmpeg.
This has been a goal for me (constantly ‘on the backburner’ but I also investigated hardware solutions and there are a few ssd HD recorders with HDMI and SDI inputs that you can remote with rs422 sony deck control protocols. These are expensive but allow for pretty much instant seeking and very high quality recording. You can mark your in point as you are recording and then send your stop recording code and outpoint and then seek to the inpoint and play and you get almost a seamless playback and looping with audio.
If you want to save frame there is a threaded video saver, I had made an array of these and each uses its own threads. You can also load the frames in threads into a playback array and loop through the images.
I am also a hack and far from a good programmer but these are the results I got from a while of investigating.
Best of luck
Another much cruder solution i guess is to create a
vector <ofImage> video, and then call
video.push_back(newFrame) every new frame for recording.
it could be better to use a vector instead of ofImage depending on how much video memory you have and how many images/how big they are. ofImage will create a texture (GPU memory) to go along with the pixels (main memory).
You would just need to have one ofTexture object and update it with the data from the current ofPixels you want to display each frame.
Thanks for the tips!
Will update on any progress.
For only 3 seconds of video, I think a good option is just storing the frames in RAM using arrays of unsigned chars. If it is exactly 3 seconds, you can use arrays with fixed size. You can simply record into a small buffer, either a static one or one created with new, record frames into it, then loop them. When a key is pressed, you can fill a new buffer, or record into the already looping one, always one frame behind where it is playing, which will result in an automatic transition to the new loop after it has been recorded.
Myself I am working on variable video delay, where video is displayed a variable amount of time after it has been recorded, where you can change the delay amount during recording/playing. I think that is more or less something ofxPlaymodes can also do, but I did not get it to work properly. See this post: Best way to create a video buffer. I have good results now using arrays of unsigned chars in a vector. When I get beyond a draft state I will put some code on git. However for just a 3 second loop this would be too much hassling with memory, I think.
You can try fonelab screen recorder to record audio on computer.
It is easy to use, you can only launch it, and then begin and stop recording whenever you want.
It enables you to record video, audio, webcam and more contents easily on computer. Both windows and mac versions are supported.
You can download and have a try now!