Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: taking a screenshot of a video track #714

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .styles/config/vocabularies/Base/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ lecle_yoyo_player
stream_video
stream_video_push_notification
screensharing
[Ss]creen[Ss]hare
Livestreaming
livestreaming
callee
17 changes: 17 additions & 0 deletions docusaurus/docs/Flutter/05-advanced/06-screenshots.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
slug: /screenshots
title: Screenshots
---
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.
Brazol marked this conversation as resolved.
Show resolved Hide resolved

```dart
final participant = call.state.value.otherParticipants.first;
final screenshot = call.takeScreenshot(participant);
```

In case you want to take a screenshot of a screen-sharing track, you can specify which track type you want to capture:

```dart
final participant = call.state.value.otherParticipants.first;
final screenshot = call.takeScreenshot(participant, trackType: SfuTrackType.screenShare);
```
11 changes: 11 additions & 0 deletions packages/stream_video/lib/src/call/call.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: deprecated_member_use_from_same_package

import 'dart:async';
import 'dart:typed_data';

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

Future<ByteBuffer?> takeScreenshot(
CallParticipantState participant, {
SfuTrackType? trackType,
}) async {
final track =
getTrack(participant.trackIdPrefix, trackType ?? SfuTrackType.video);

return track?.captureScreenshot();
}

Future<void> _applyCallSettingsToConnectOptions(CallSettings settings) async {
// Apply defaul audio output and input devices
final mediaDevicesResult =
Expand Down
10 changes: 10 additions & 0 deletions packages/stream_video/lib/src/webrtc/rtc_track/rtc_track.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:typed_data';

import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
import 'package:meta/meta.dart';

Expand Down Expand Up @@ -65,6 +67,14 @@ abstract class RtcTrack {
}
}

Future<ByteBuffer?> captureScreenshot() async {
if (isVideoTrack) {
return mediaStream.getVideoTracks().first.captureFrame();
}

return null;
}

Future<void> start();

Future<void> stop();
Expand Down
Loading