@vpalmisano/webrtcperf-js
    Preparing search index...

    Function saveMediaTrack

    • Saves the media track to file. Audio tracks are saved as a raw float32 array, video tracks are saved as VP8 encoded packets in an IVF container. The file is sent to the server defined in config.SAVE_MEDIA_URL using a WebSocket connection.

      Parameters

      • track: MediaStreamTrack

        The media track to save.

      • sendrecv: "send" | "recv"

        If 'send', it is a local track. If 'recv', it is a remote track.

      • enableStart: number = 0

        If greater than 0, the track is enabled after this time in milliseconds.

      • enableEnd: number = 0

        If greater than 0, the track is disabled after this time in milliseconds.

      • x: number = 0

        If greater than 0, the video is cropped to this x coordinate.

      • y: number = 0

        If greater than 0, the video is cropped to this y coordinate.

      • width: number = 0

        If greater than 0, the video is cropped to this width.

      • height: number = 0

        If greater than 0, the video is cropped to this height.

      • frameRate: number = config.VIDEO_FRAMERATE

        The video frame rate.

      • bitrate: number = 20_000_000

        Run a simple websocket server:

        const ws = require('ws')
        const fs = require('fs')
        const wss = new ws.Server({ port: 8080 })
        wss.on('connection', (ws, req) => {
        const query = req.url.split('?')[1]
        const filename = new URLSearchParams(query).get('filename')
        const file = fs.createWriteStream(filename)
        console.log(`Saving media to ${filename}`)
        ws.on('message', message => file.write(message))
        ws.on('close', () => {
        console.log(`done saving ${filename}`)
        file.end()
        })
        })

        Run the test:

        webrtcperf.config.SAVE_MEDIA_URL = 'ws://localhost:8080'
        await saveMediaTrack(videoTrack, 'send')

        The file will sent to the server as Participant-000000_send_<track.id>.ivf.raw.

      Returns Promise<void>