Can you write video to memory? I use Raspberry Pi and I don't want to keep writing and deleting videowriter objects created on sd card (or is it ok to do so?).
If conditions are not met I would like to discard written video every second. I use type of motion detector recording and I would like to capture moment (one second in this case) before movement has been detected, because otherwise written video loses part of what happened. I use opencv in python environment.
Video files will often, or even generally, be too big to fit in your main memory so you will be unlikely to be able to just keep the entire video there.
It also worth noting that your OS itself may decide to move data between fast memory, slower memory, disk etc as it manages multiple processes but that is likely not important in this discussion.
It will depend on your use case but a typical video scenario might be:

receive video frame from camera or source stream
do some processing on the video frame - e.g. transcode it, detect an object, add text or images etc
store or send the updated frame someplace
go back to first step

In a flow like this, there is obviously advantage in keeping the frame in memory while working on it, but once done then it is generally not an advantage any more so its fine to move it to disk, or send it to its destination.
If you use cases requires you to work on groups of frames, as some encoding algorithms do, then it may make sense to keep the group of frames in memory until you are finished with them and then write them to disk.
I think the best answer for you will depend on your exact use case, but whatever that it is it is unlikely that keeping the entire video in memory would be necessary or even possible.
How to write video to memory in OpenCV