* This example streams to files, each with 10 seconds of video. * The output will be in output/part${part #}.mp4
()
| 9 | **/ |
| 10 | |
| 11 | async function example() { |
| 12 | const ringApi = new RingApi({ |
| 13 | // Replace with your refresh token |
| 14 | refreshToken: process.env.RING_REFRESH_TOKEN!, |
| 15 | debug: true, |
| 16 | }), |
| 17 | [camera] = await ringApi.getCameras() |
| 18 | |
| 19 | if (!camera) { |
| 20 | console.log('No cameras found') |
| 21 | return |
| 22 | } |
| 23 | |
| 24 | await cleanOutputDirectory() |
| 25 | |
| 26 | console.log('Starting Video...') |
| 27 | const call = await camera.streamVideo({ |
| 28 | // save video 10 second parts so the mp4s are playable and not corrupted: |
| 29 | // https://superuser.com/questions/999400/how-to-use-ffmpeg-to-extract-live-stream-into-a-sequence-of-mp4 |
| 30 | output: [ |
| 31 | '-flags', |
| 32 | '+global_header', |
| 33 | '-f', |
| 34 | 'segment', |
| 35 | '-segment_time', |
| 36 | '10', // 10 seconds |
| 37 | '-segment_format_options', |
| 38 | 'movflags=+faststart', |
| 39 | '-reset_timestamps', |
| 40 | '1', |
| 41 | path.join(outputDirectory, 'part%d.mp4'), |
| 42 | ], |
| 43 | }) |
| 44 | console.log('Video started, streaming to part files...') |
| 45 | |
| 46 | call.onCallEnded.subscribe(() => { |
| 47 | console.log('Call has ended') |
| 48 | process.exit() |
| 49 | }) |
| 50 | |
| 51 | setTimeout(function () { |
| 52 | console.log('Stopping call...') |
| 53 | call.stop() |
| 54 | }, 60 * 1000) // Stop after 1 minute |
| 55 | } |
| 56 | |
| 57 | example().catch((e) => { |
| 58 | console.error(e) |
no test coverage detected