Gathering detailed insights and metrics for use-simple-camera
Gathering detailed insights and metrics for use-simple-camera
Gathering detailed insights and metrics for use-simple-camera
Gathering detailed insights and metrics for use-simple-camera
simple-vue-camera
A simple to use, but extensive, camera component for Vue 3 with Typescript support to create great camera experiences.
camera-processor
A Simple to Use Webcam Filter Framework.
@camera-processor/virtual-background
Simple, Easy-to-use Background Masking Using Camera-Processor.
rippleberry-camera-recorder
A simple and easy to use webcam recorder for your web applications
A simple and easy to use react hook, it can help you capture videos, images and get media devices streams in an easy to use way.
npm install use-simple-camera
Typescript
Module System
Node Version
NPM Version
TypeScript (97.25%)
JavaScript (2.75%)
Total Downloads
1,162
Last Day
3
Last Week
9
Last Month
93
Last Year
1,162
MIT License
15 Stars
12 Commits
1 Watchers
1 Branches
1 Contributors
Updated on May 01, 2025
Latest Version
1.0.9
Package Id
use-simple-camera@1.0.9
Unpacked Size
56.64 kB
Size
11.29 kB
File Count
10
NPM Version
10.2.4
Node Version
20.11.1
Published on
Dec 31, 2024
Cumulative downloads
Total Downloads
Last Day
0%
3
Compared to previous day
Last Week
-59.1%
9
Compared to previous week
Last Month
-20.5%
93
Compared to previous month
Last Year
0%
1,162
Compared to previous year
1
4
🛠️ Use Simple Camera is a lightweight React hook that simplifies interacting with browser APIs for capturing audio and video from media devices. It abstracts the complexities of managing permissions, media streams, and recording operations, providing a seamless developer experience for building camera-enabled applications.
Whether you're creating a video conferencing app, a custom video recording tool, or an image capture utility, Use Simple Camera equips you with all the essential functionalities in one easy-to-use package.
Well life's too short for clunky APIs! Whether you’re building a photo booth, a live streamer, or a casual media app, Use Simple Camera is your new BFF.
Find it on NPM https://www.npmjs.com/package/use-simple-camera
Find it on Github https://github.com/ketanip/use-simple-camera
Demo Project Live: https://use-simple-camera-demo.vercel.app/
Demo Project Source Code: https://github.com/ketanip/use-simple-camera-demo
That'll Make You Go WOW
I was working extensively once with these APIs for a project and that experience annoyed me a lot, so I decided to write custom code that time.
I was planning once again to work with same APIs so not to feel that same unpleasant experience again I decided to create this library (hook).
1import { useSimpleCamera } from "use-simple-camera"; 2import { useState, useRef } from "react"; 3 4const MyComponent = () => { 5 const [imageURL, setImageURL] = useState(""); 6 const videoRef = useRef<HTMLVideoElement>(null); 7 const { 8 acquirePermissions, 9 captureImage, 10 startCamera, 11 stopCamera, 12 recordVideo, 13 stopVideoRecording, 14 downloadRecordedVideo, 15 } = useSimpleCamera(); 16 17 return ( 18 <div> 19 <button onClick={acquirePermissions}>Permissions</button> 20 <button onClick={startCamera}>Start</button> 21 <button onClick={stopCamera}>Stop</button> 22 <button onClick={() => captureImage().then(setImageURL)}>Capture</button> 23 <button onClick={() => recordVideo("vid1")}>Record</button> 24 <button onClick={stopVideoRecording}>Stop Recording</button> 25 <button onClick={() => downloadRecordedVideo("vid1")}>Download</button> 26 27 {imageURL && <img src={imageURL} alt="Captured" />} 28 {videoRef && <video ref={videoRef} controls />} 29 </div> 30 ); 31};
This hook packs a punch with intuitive, flexible functions. Here’s the action-packed lineup:
Here’s the magic you'll have at your fingertips:
permissionAcquired
– Do we have the green light?isCameraActive
– Is the camera rolling?videoDevices
– All available video sources.audioDevices
– All available audio sources.videoRecordingInProgress
– Are we filming?videoProcessingStatus
- Are we done processing videos yet?acquirePermissions
, startCamera
, stopCamera
, getMediaStream
captureImage
recordVideo
, stopVideoRecording
, getRecordedVideoURL
, getRecordedVideoBlob
, downloadRecordedVideo
acquirePermissions
before anything else.stopCamera
to release media devices and avoid leaving them active.captureImage
gives you a Base64 blob of your snapshot.getRecordedVideoURL
: Get a URL to the video.getRecordedVideoBlob
: Get the raw blob of the video.downloadRecordedVideo
: Save the video locally.getMediaStream
with React refs for custom video streaming, audio-only and video-only streaming.videoProcessingStatus
status for any video before downloading/reading it as blob or as base64 format string.acquirePermissions()
Description: Asks the user for permission to access the camera and microphone.
Returns: Promise<void>
Example:
1await acquirePermissions();
startCamera(config: object)
Description: Starts the camera to capture video and audio.
Parameters:
config
: Provide MediaStreamConstraints
for the media input. (optional)Returns: Promise<void>
Example:
1await startCamera();
stopCamera()
Description: Stops the camera and releases all media devices.
Returns: Promise<void>
Example:
1await stopCamera();
captureImage(videoTrackID?: string)
Description: Captures an image from the specified video track. If no videoTrackID
is provided, it uses the first available video device.
Returns: Promise<string>
– A Base64-encoded string representing the captured image.
Example:
1const imageURL = await captureImage(); 2<img src={imageURL} alt="Captured" />;
recordVideo(id: string, config?: RecordVideoConfig)
Description: Starts recording a video.
Parameters:
id
: Unique identifier for the recorded video.config
: Optional configuration object for custom video settings.
videoStreamID
: The ID of the video stream to record.audioStreamID
: The ID of the audio stream to record.customMimeType
: Optional MIME type for the video recording (e.g., 'video/webm'
).Returns: Promise<void>
Example:
1 await recordVideo("submission-1234", { 2 videoStreamID: "video-stream-1", 3 audioStreamID: "audio-stream-1", 4 customMimeType: "video/codec=vp9". 5 })
stopVideoRecording()
Description: Stops the ongoing video recording.
Returns: Promise<void>
Example:
1await stopVideoRecording();
getRecordedVideoURL(videoID: string)
Description: Retrieves the blob URL of the recorded video by its videoID
.
Returns: string
– The blob URL of the recorded video.
Example:
1const videoURL = getRecordedVideoURL("video1"); 2<video src={videoURL} controls />;
getRecordedVideoBlob(videoID: string)
Description: Retrieves the recorded video as a Blob by its videoID
.
Returns: Blob
– The raw Blob of the recorded video.
Example:
1const videoBlob = getRecordedVideoBlob("video1"); 2const url = URL.createObjectURL(videoBlob);
downloadRecordedVideo(videoID: string, filename?: string)
Description: Downloads the recorded video by its videoID
, with an optional custom filename. Include file extension. If you haven't changed codec use webm as file extension.
Returns: void
Example:
1downloadRecordedVideo("video1", "my-video.webm");
getMediaStream(config: GetMediaStreamConfig)
Description: Retrieves a media stream based on the provided video and audio track IDs.
Parameters:
config
: The configuration for selecting the media stream, which includes videoID
and audioID
.Returns: Promise<MediaStream>
– The media stream for custom use.
Example:
1const mediaStream = await getMediaStream({ 2 videoID: "camera1", 3 audioID: "microphone1", 4}); 5videoRef.current.srcObject = mediaStream;
We welcome contributions! If you'd like to help improve this project, here’s how you can contribute:
The License for this project is located in License
file. This project is licensed under MIT License.
If you encounter any issues or have questions, please open a GitHub issue, and I'll be happy to assist you!
This is still first version of this library so please be careful while using it your application, test it extensively for your application.
✨ Ready to simplify your media game? Let’s roll!
No vulnerabilities found.
No security vulnerabilities found.