API docs¶
Note that ipywebrtc.webrtc
is imported in the ipywebrtc namespace, to you can access ipywebrtc.CameraStream instead of ipywebrtc.webrtc.CameraStream
.
ipywebrtc¶
- ipywebrtc.chat(room=None, stream=None, **kwargs)[source]¶
Quick setup for a chatroom.
- Parameters
room (str) – Roomname, if not given, a random sequence is generated and printed.
stream (MediaStream) – The media stream to share, if not given a CameraStream will be created.
- Return type
ipywebrtc.webrtc¶
- class ipywebrtc.webrtc.AudioRecorder(*args, **kwargs)[source]¶
Bases:
Recorder
Creates a recorder which allows to record the Audio of a MediaStream widget, play the record in the Notebook, and download it or turn it into an Audio widget.
For help on supported values for the “codecs” attribute, see https://stackoverflow.com/questions/41739837/all-mime-types-supported-by-mediarecorder-in-firefox-and-chrome
- audio¶
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- codecs¶
Optional codecs for the recording, e.g. “opus”.
- save(filename=None)[source]¶
Save the audio to a file, if no filename is given it is based on the filename trait and the format.
>>> recorder = AudioRecorder(filename='test', format='mp3') >>> ... >>> recorder.save() # will save to test.mp3 >>> recorder.save('foo') # will save to foo.mp3 >>> recorder.save('foo.dat') # will save to foo.dat
- class ipywebrtc.webrtc.AudioStream(*args, **kwargs)[source]¶
Bases:
MediaStream
Represent a stream of an audio element
- audio¶
An ipywidgets.Audio instance that will be the source of the media stream.
- classmethod from_download(url, **kwargs)[source]¶
Create a AudioStream from a url by downloading
- Parameters
url (str) – The url of the file that will be downloadeded and its bytes assigned to the value trait of the video trait.
**kwargs – Extra keyword arguments for AudioStream
- classmethod from_file(filename, **kwargs)[source]¶
Create a AudioStream from a local file.
- Parameters
filename (str) – The location of a file to read into the audio value from disk.
**kwargs – Extra keyword arguments for AudioStream
- classmethod from_url(url, **kwargs)[source]¶
Create a AudioStream from a url.
This will create a AudioStream from an Audio using its url
- Parameters
url (str) – The url of the file that will be used for the .audio trait.
**kwargs – Extra keyword arguments for AudioStream
- playing¶
Plays the audiostream or pauses it.
- class ipywebrtc.webrtc.CameraStream(*args, **kwargs)[source]¶
Bases:
MediaStream
Represents a media source by a camera/webcam/microphone using getUserMedia. See https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia for more detail. The constraints trait can be set to specify constraints for the camera or microphone, which is described in the documentation of getUserMedia, such as in the link above, Two convenience methods are avaiable to easily get access to the ‘front’ and ‘back’ camera, when present
>>> CameraStream.facing_user(audio=False) >>> CameraStream.facing_environment(audio=False)
- constraints¶
//developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia for details.
- Type
Constraints for the camera, see https
- class ipywebrtc.webrtc.ImageRecorder(*args, **kwargs)[source]¶
Bases:
Recorder
Creates a recorder which allows to grab an Image from a MediaStream widget.
- format¶
The format of the image.
- image¶
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- save(filename=None)[source]¶
Save the image to a file, if no filename is given it is based on the filename trait and the format.
>>> recorder = ImageRecorder(filename='test', format='png') >>> ... >>> recorder.save() # will save to test.png >>> recorder.save('foo') # will save to foo.png >>> recorder.save('foo.dat') # will save to foo.dat
- class ipywebrtc.webrtc.ImageStream(*args, **kwargs)[source]¶
Bases:
MediaStream
Represent a media stream by a static image
- classmethod from_download(url, **kwargs)[source]¶
Create a ImageStream from a url by downloading
- Parameters
url (str) – The url of the file that will be downloadeded and its bytes assigned to the value trait of the video trait.
**kwargs – Extra keyword arguments for ImageStream
- classmethod from_file(filename, **kwargs)[source]¶
Create a ImageStream from a local file.
- Parameters
filename (str) – The location of a file to read into the value from disk.
**kwargs – Extra keyword arguments for ImageStream
- classmethod from_url(url, **kwargs)[source]¶
Create a ImageStream from a url.
This will create a ImageStream from an Image using its url
- Parameters
url (str) – The url of the file that will be used for the .image trait.
**kwargs – Extra keyword arguments for ImageStream
- image¶
An ipywidgets.Image instance that will be the source of the media stream.
- class ipywebrtc.webrtc.MediaStream(*args, **kwargs)[source]¶
Bases:
DOMWidget
Represents a media source.
See https://developer.mozilla.org/nl/docs/Web/API/MediaStream for details In practice this can a stream coming from an HTMLVideoElement, HTMLCanvasElement (could be a WebGL canvas) or a camera/webcam/microphone using getUserMedia.
- The currently supported MediaStream (subclasses) are:
VideoStream
: A video file/data as media stream.CameraStream
: Webcam/camera as media stream.ImageStream
: An image as a static stream.WidgetStream
: Arbitrary DOMWidget as stream.
- A MediaStream can be used with:
VideoRecorder
: To record a movieImageRecorder
: To create images/snapshots.AudioRecorder
: To record audio.WebRTCRoom
(or ratherWebRTCRoomMqtt
): To stream a media stream to a (set of) peers.
- class ipywebrtc.webrtc.Recorder(*args, **kwargs)[source]¶
Bases:
DOMWidget
- autosave¶
If true, will save the data to a file once the recording is finished (based on filename and format)
- filename¶
The filename used for downloading or auto saving.
- format¶
The format of the recording.
- recording¶
(boolean) Indicator and controller of the recorder state, i.e. putting the value to True will start recording.
- stream¶
An instance of
MediaStream
that is the source for recording.
- class ipywebrtc.webrtc.VideoRecorder(*args, **kwargs)[source]¶
Bases:
Recorder
Creates a recorder which allows to record a MediaStream widget, play the record in the Notebook, and download it or turn it into a Video widget.
For help on supported values for the “codecs” attribute, see https://stackoverflow.com/questions/41739837/all-mime-types-supported-by-mediarecorder-in-firefox-and-chrome
- codecs¶
Optional codecs for the recording, e.g. “vp8” or “vp9, opus”.
- save(filename=None)[source]¶
Save the video to a file, if no filename is given it is based on the filename trait and the format.
>>> recorder = VideoRecorder(filename='test', format='mp4') >>> ... >>> recorder.save() # will save to test.mp4 >>> recorder.save('foo') # will save to foo.mp4 >>> recorder.save('foo.dat') # will save to foo.dat
- video¶
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- class ipywebrtc.webrtc.VideoStream(*args, **kwargs)[source]¶
Bases:
MediaStream
Represent a stream of a video element
- classmethod from_download(url, **kwargs)[source]¶
Create a VideoStream from a url by downloading
- Parameters
url (str) – The url of the file that will be downloadeded and its bytes assigned to the value trait of the video trait.
**kwargs – Extra keyword arguments for VideoStream
- classmethod from_file(filename, **kwargs)[source]¶
Create a VideoStream from a local file.
- Parameters
filename (str) – The location of a file to read into the value from disk.
**kwargs – Extra keyword arguments for VideoStream
- classmethod from_url(url, **kwargs)[source]¶
Create a VideoStream from a url.
This will create a VideoStream from a Video using its url
- Parameters
url (str) – The url of the file that will be used for the .video trait.
**kwargs – Extra keyword arguments for VideoStream
- playing¶
Plays the videostream or pauses it.
- video¶
An ipywidgets.Video instance that will be the source of the media stream.
- class ipywebrtc.webrtc.WebRTCPeer(*args, **kwargs)[source]¶
Bases:
DOMWidget
A peer-to-peer webrtc connection
- connected¶
A boolean (True, False) trait.
- failed¶
A boolean (True, False) trait.
- id_local¶
A trait for unicode strings.
- id_remote¶
A trait for unicode strings.
- stream_local¶
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- stream_remote¶
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- class ipywebrtc.webrtc.WebRTCRoom(*args, **kwargs)[source]¶
Bases:
DOMWidget
A ‘chatroom’, which consists of a list of :WebRTCPeer connections
- nickname¶
A trait for unicode strings.
- peers¶
An instance of a Python list.
- room¶
A trait for unicode strings.
- room_id¶
A trait for unicode strings.
- stream¶
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- streams¶
An instance of a Python list.
- class ipywebrtc.webrtc.WebRTCRoomLocal(*args, **kwargs)[source]¶
Bases:
WebRTCRoom
- class ipywebrtc.webrtc.WebRTCRoomMqtt(*args, **kwargs)[source]¶
Bases:
WebRTCRoom
Use a mqtt server to connect to other peers
- server¶
A trait for unicode strings.
- class ipywebrtc.webrtc.WidgetStream(*args, **kwargs)[source]¶
Bases:
MediaStream
Represents a widget media source.
- max_fps¶
(int, default None) The maximum amount of frames per second to capture, or only on new data when the valeus is None.
- widget¶
An instance of ipywidgets.DOMWidget that will be the source of the MediaStream.