Skip to content

Commit f69d938

Browse files
authored
feat: taking a screenshot of a video track (#714)
* track screenshot * vale fix * vale fix
1 parent 421f2ac commit f69d938

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

.styles/config/vocabularies/Base/accept.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ lecle_yoyo_player
3434
stream_video
3535
stream_video_push_notification
3636
screensharing
37+
[Ss]creen[Ss]hare
3738
Livestreaming
3839
livestreaming
3940
callee
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
slug: /screenshots
3+
title: Screenshots
4+
---
5+
You can take a picture of a VideoTrack at highest possible resolution. This can be useful for example if you want to take a screenshot of a screenshare at full resolution.
6+
7+
```dart
8+
final participant = call.state.value.otherParticipants.first;
9+
final screenshot = call.takeScreenshot(participant);
10+
```
11+
12+
In case you want to take a screenshot of a screen-sharing track, you can specify which track type you want to capture:
13+
14+
```dart
15+
final participant = call.state.value.otherParticipants.first;
16+
final screenshot = call.takeScreenshot(participant, trackType: SfuTrackType.screenShare);
17+
```

packages/stream_video/lib/src/call/call.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ignore_for_file: deprecated_member_use_from_same_package
22

33
import 'dart:async';
4+
import 'dart:typed_data';
45

56
import 'package:collection/collection.dart';
67
import 'package:flutter/foundation.dart';
@@ -1058,6 +1059,16 @@ class Call {
10581059
return [...?_session?.getTracks(trackIdPrefix)];
10591060
}
10601061

1062+
Future<ByteBuffer?> takeScreenshot(
1063+
CallParticipantState participant, {
1064+
SfuTrackType? trackType,
1065+
}) async {
1066+
final track =
1067+
getTrack(participant.trackIdPrefix, trackType ?? SfuTrackType.video);
1068+
1069+
return track?.captureScreenshot();
1070+
}
1071+
10611072
Future<void> _applyCallSettingsToConnectOptions(CallSettings settings) async {
10621073
// Apply defaul audio output and input devices
10631074
final mediaDevicesResult =

packages/stream_video/lib/src/webrtc/rtc_track/rtc_track.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:typed_data';
2+
13
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
24
import 'package:meta/meta.dart';
35

@@ -65,6 +67,14 @@ abstract class RtcTrack {
6567
}
6668
}
6769

70+
Future<ByteBuffer?> captureScreenshot() async {
71+
if (isVideoTrack) {
72+
return mediaStream.getVideoTracks().first.captureFrame();
73+
}
74+
75+
return null;
76+
}
77+
6878
Future<void> start();
6979

7080
Future<void> stop();

0 commit comments

Comments
 (0)