You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Currently, when trying to analyze video frames from WebRTC MediaStreamTrack in real-time (e.g., for ML processing), we need to use Timer to periodically capture frames using captureFrame(). This approach has several issues:
High CPU/Memory usage
UI stuttering
Potential frame drops
Inconsistent frame rate Describe the solution you'd like
Add a new Stream-based API to capture video frames from MediaStreamTrack that:
Provides frames as a Stream at the native frame rate
Integrates directly with the native WebRTC frame callback system
Has an API similar to:
Stream<VideoFrame> getVideoFrameStream() async {
// Implementation that hooks into native frame callbacks
}
This would allow more efficient frame processing without Timer polling. Describe alternatives you've considered
Current Timer-based approach with captureFrame()
Custom native implementation per platform
Using platform channels with event streams
The Stream API would be the most elegant and performant solution.
Additional context
Looking at the current implementation in the codebase:
The current implementation uses Timer-based approach:
captureImageTimer =Timer.periodic(
constDuration(milliseconds:200),
() async {
if (!mounted) return;
awaitcaputureImage(videoTrack);
},
);
Future<Image> captureImage({
requiredVideoTrack videoTrack,
}) async {
try {
final mediaStreamTrack = videoTrack.mediaStreamTrack;
final imageByteBuffer =await mediaStreamTrack.captureFrame();
final imageBytes = imageByteBuffer.asUint8List();
final image =awaitcompute(
decodeImage,
imageBytes,
);
return image;
}
The proposed Stream API could be integrated with the existing RemoteRehabilitationRoomState class, replacing the current Timer implementation:
Is this possible to implement? I'd like to mention @cloudwebrtc for their expertise.
I tried to extend the package myself by downloading it, but the dependencies with other packages seem quite strong and make it challenging to modify independently.
I'm willing to put in the effort to implement this myself, but I would greatly appreciate any advice or guidance on:
hey @YouheiShikano , I am trying to improve this PR #657 to add a frame sink API for local or remote track, and I am also trying to write a filter example plugin so that you can follow this example to write a sink or processor for the track in native. Like ML processing
Thank you so much @cloudwebrtc for your detailed response and the great solution!
The Track Processor API looks exactly like what I needed. The implementation with native frame callbacks instead of Timer-based approach will definitely solve the performance issues I was experiencing.
I really appreciate you sharing the flutter-filter-plugin-example as well. This will be incredibly helpful as a reference for implementing custom processors for ML processing.
I'll try implementing this using your example as a guide. Thanks again for your help and for working on this improvement!
Looking forward to trying out PR #657 when it's ready!
Is your feature request related to a problem? Please describe.
Currently, when trying to analyze video frames from WebRTC MediaStreamTrack in real-time (e.g., for ML processing), we need to use Timer to periodically capture frames using
captureFrame()
. This approach has several issues:Describe the solution you'd like
Add a new Stream-based API to capture video frames from MediaStreamTrack that:
This would allow more efficient frame processing without Timer polling.
Describe alternatives you've considered
captureFrame()
The Stream API would be the most elegant and performant solution.
Additional context
Looking at the current implementation in the codebase:
RemoteRehabilitationRoomState
class, replacing the current Timer implementation:/cc @cloudwebrtc
The text was updated successfully, but these errors were encountered: