Comments (14)
I am using WebRTC (RecordRTC) and getUserMedia.
This is a little bit chaotic but it does the job.
I had to clean it up a little so dont expect it to work copy&paste out of the box.
the important function for you is setupVideo()
import RecordRTC from 'recordrtc'
import Video from '../../components/Video'
export default class Record extends React.Component {
constructor(props) {
super(props);
this.state = {
stream: null,
url:'',
videoRecorder:'',
isRecording: false,
isUploading: false,
isPreview: false,
isDone: false,
pausing: false,
}
hasGetUserMedia() {
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia);
}
setupVideo(callback){
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
//check if stream has already been captured
if (this.state.stream) {
console.log(this.state.stream);
this.setState({
url: window.URL.createObjectURL(this.state.stream)
}, callback);
} else {
navigator.getUserMedia({
audio: true,
video: {
frameRate: { ideal: 20, max: 30 }},
height:'480px', width:'640px'
}, (stream) => {
this.setState({
stream: stream,
url: window.URL.createObjectURL(stream)
}, callback);
},(err) => { console.log(err.name) })
}
}
pauseRecording(){
this.state.videoRecorder.pauseRecording()
this.setState({
pausing: true,
});
}
startRecording(){
if (this.state.pausing) {
this.state.videoRecorder.resumeRecording()
this.setState({
pausing: false,
});
return
}
this.setState({
videoRecorder:'',
isUploading: false,
pausing: false,
isPreview: false,
hasRecording: false,
}, this.setupVideo.bind(this, () => {
const videoRecorder = RecordRTC(this.state.stream, {
type: 'video',
video: {
width: 640,
height: 480
},
canvas: {
width: 640,
height: 480
}
})
videoRecorder.startRecording()
this.setState({
videoRecorder: videoRecorder,
isRecording: true,
});
}))
}
stopRecording(){
window.dispatchEvent(new CustomEvent('stopRecording'));
this.state.videoRecorder.stopRecording((url) => {
this.setState({
isRecording: false,
pausing: false,
hasRecording: true,
});
})
}
startPreview(){
this.state.videoRecorder.getDataURL((url) => {
this.setState({
url : url,
isPreview: true
});
})
}
uploadFile(){
this.setState({
pausing: false,
isRecording: false,
isUploading: 1,
isPreview: false,
});
this.state.videoRecorder.getDataURL((data) => {
var uploadData = {
fileName: id
file: data,
isBase64: true,
streams: 'dynamic',
chunkSize: 'dynamic',
}
var uploadInstance = Videos.insert(uploadData, false);
uploadInstance.on('progress', (progress, file) => {
this.setState({
isUploading: progress,
});
});
uploadInstance.on('end', (error, fileObj) => {
if (error) {
console.log('Error during upload: ' + error.reason);
} else {
console.log(fileObj.meta._id, fileObj.meta.try)
this.setState({
id: fileObj._id,
isDone: true
});
}
});
uploadInstance.start()
})
}
render(){
return ( <Video
ref='video'
isPreview={this.state.isPreview}
url={this.state.url}/>)
}
from react-webcam.
plain old html video tag
.
import React from 'react'
export default class Video extends React.Component {
render() {
// console.log(this.props);
return (
<video
id='video'
style={{height:'480px', width:'640px'}}
ref='video'
preload='auto'
controls={this.props.isPreview}
autoPlay={!this.props.isPreview}
src={this.props.url} />
)
}
}
from react-webcam.
@FinnFrotscher Great, that's massively helpful. Appreciate it!
from react-webcam.
ok ill look into my code tomorrow and upload the relevant bits.
from react-webcam.
+1
from react-webcam.
@FinnFrotscher Have you managed to integrate video capturing functionality??
from react-webcam.
I did but i am not sure whether i used this component.
also I saved the files to my own server. not aws. still interested?
@Extra-lightwill
from react-webcam.
@FinnFrotscher I am building a prototype so yes still interested...
from react-webcam.
@FinnFrotscher Have you got a link?
from react-webcam.
@FinnFrotscher Just out of interest, what does your video.js file look like? Assuming you're using react, there are some react-specific video repos, but I'm leaning towards going for something more established e.g. https://github.com/Selz/plyr or https://github.com/videojs/video.js/.. Wondering whether this is the right choice or not based on your experience?
from react-webcam.
Hey @FinnFrotscher I am trying to get your code to work but running into errors. Do you have a repo with a component that has all the code for turning this into a video capture component?
from react-webcam.
@mozmorris Have you managed to add the record video feature in react-webcam?
from react-webcam.
How can we capture video with react-webcam?
from react-webcam.
@shane-hogan see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/captureStream. There's also a guide https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API/Recording_a_media_element
from react-webcam.
Related Issues (20)
- not asking for permission (chrome only) HOT 2
- Record a video
- Webcam not show when user change permission from deny to accept HOT 1
- Mirrored Video HOT 1
- Vertical Recording Issue - always record horizontal video HOT 2
- Variety of issues on iOS 17 HOT 3
- video not displayed with external camera (Logitech) HOT 1
- audio prop state change not working
- iOS no data when stop recording
- Sound is very low quality and cutting out no matter what mic even with professional equipment. HOT 1
- Permissions popup is not shown if `audio=true` HOT 1
- When audio is false there is not audio in the MediaStream from the Webcam HOT 1
- Accessing webcam data is broken by canvas fingerprinting protections (firefox, or any browser with adblockers) HOT 3
- Stop button works with android device but not working with iphone HOT 2
- Unble to save screenshot as blob HOT 1
- Loop Back of Mic Audio in speaker While recording video (using react-webcam).[while using headphones] HOT 1
- Recorded video is getting very large
- Reduce the size of the recorded video HOT 1
- react-webcam not working in some device like this SM-A605G , M2102J20SG
- The sound is not recorded correctly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-webcam.