Helpers

These classes are not part of the WebRTC or ORTC API, but provide higher-level helpers for tasks like manipulating media streams.

Media sources

class aiortc.contrib.media.MediaPlayer(file, format=None, options={})

A media source that reads audio and/or video from a file.

Examples:

# Open a video file.
player = MediaPlayer('/path/to/some.mp4')

# Open an HTTP stream.
player = MediaPlayer(
    'http://download.tsi.telecom-paristech.fr/'
    'gpac/dataset/dash/uhd/mux_sources/hevcds_720p30_2M.mp4')

# Open webcam on Linux.
player = MediaPlayer('/dev/video0', format='v4l2', options={
    'video_size': '640x480'
})

# Open webcam on OS X.
player = MediaPlayer('default:none', format='avfoundation', options={
    'video_size': '640x480'
})
Parameters
  • file – The path to a file, or a file-like object.

  • format – The format to use, defaults to autodect.

  • options – Additional options to pass to FFmpeg.

property audio

A aiortc.MediaStreamTrack instance if the file contains audio.

Return type

MediaStreamTrack

property video

A aiortc.MediaStreamTrack instance if the file contains video.

Return type

MediaStreamTrack

Media sinks

class aiortc.contrib.media.MediaRecorder(file, format=None, options={})

A media sink that writes audio and/or video to a file.

Examples:

# Write to a video file.
player = MediaRecorder('/path/to/file.mp4')

# Write to a set of images.
player = MediaRecorder('/path/to/file-%3d.png')
Parameters
  • file – The path to a file, or a file-like object.

  • format – The format to use, defaults to autodect.

  • options – Additional options to pass to FFmpeg.

addTrack(track)

Add a track to be recorded.

Parameters

track – A aiortc.MediaStreamTrack.

class aiortc.contrib.media.MediaBlackhole

A media sink that consumes and discards all media.

addTrack(track)

Add a track whose media should be discarded.

Parameters

track – A aiortc.MediaStreamTrack.