How to implement circular buffer video recording in C#
This article presents a description of circular or ring buffer, explains the benefits of it and shows how to use this data structure in video recording.
What is circular buffer?
A circular buffer (or ring buffer) is a first-in first-out data structure that uses a single, fixed-size
buffer as if it were connected end-to-end.
It is a circular software queue. This queue has a first-in-first-out (FIFO) data characteristic which makes it capable to collect data continually.
These buffers are quite common and are found in many embedded systems. Usually, most developers write these
constructs from scratch on an as-needed basis.
Ring buffers are incredibly useful when processing asynchronous IO. They allow one side to receive data in
random intervals and in random sizes, but feed cohesive chunks to the other side in set sizes or intervals.
How does it work?
Circular Buffers are used for data transfer between two processes. The Producer process places items into the
Circular Buffer and the Consumer process removes them. The variable capacity of the Circular Buffer accommodates
timing differences between the Producer and Consumer processes.
Circular buffers can implement the following functions:
- Create - Makes a new ring buffer.
- Destroy - Destroys an existing ring buffer.
- Connect - Connects to an existing ring buffer.
- Put - Inserts data into the ring buffer.
- Get - Retrieves data from the ring buffer.
- WaitUntil - Blocks until the ring buffer satisfies some condition or predicate.
- Peek - Exactly like get however the get pointer is not updated.
Circular buffer video recording
This data structure allows us to record only a specified length of video files (e.g. 5 minutes). It is very useful when you would like to launch a long-term recording process but your storage capacity is limited.
Related Pages
FAQ
Below you can find the answers for the most frequently asked questions related to this topic:
-
How can I get the URL of the camera?
You can get the URL from the producer of the camera. (In the 10th tutorial you can find information on how to create an own IP camera discoverer program.)
-
I have not managed to build the solution. How to solve it?
- Please set the Target framework property of the project to .NET 4.0.
- You should add the OzekiSDK.dll to the references of the solution.
- Please import the missing classes.
More information
- How to record audio and video stream into MPEG-4 in C#
- How to take a picture snapshot and save it as .jpg in C#
- How to implement circular buffer video recording in C#
- How to set frame rate, codec, and picture size for video recording (resample video stream) in Cx
- How to record from multiple cameras simultaneously in C#
- How to record audio stream into .WAV in C#
- Screen capture function - ScreenCapture