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

Out of memory when running stream #105

Closed
JSBmanD opened this issue Feb 12, 2024 · 2 comments
Closed

Out of memory when running stream #105

JSBmanD opened this issue Feb 12, 2024 · 2 comments

Comments

@JSBmanD
Copy link

JSBmanD commented Feb 12, 2024

I have a command running stream via ffmpeg
libcamera-vid --framerate 24 --nopreview --inline -t 0 --width 1920 --height 1080 --listen -o - | ffmpeg -f lavfi -i anullsrc -i - -profile:v high -pix_fmt yuvj420p -level:v 4.1 -preset ultrafast -framerate 24 -g 48 -tune zerolatency -vcodec libx264 -r 10 -s 1920x1080 -b:v 2M -f flv rtmp://a.rtmp.youtube.com/live2/YOUR_KEY

And after some time - I'm having out of memory error

Error
  Exhausted heap space, trying to allocate 8589934608 bytes.
Unhandled exception:
Out of Memory
#0      List._grow (dart:core-patch/growable_array.dart:376:19)
#1      List.addAll (dart:core-patch/growable_array.dart:304:9)
#2      runExecutableArguments.streamToResult (package:process_run/src/process_run.dart:132:12)
#3      _FutureListener.handleValue (dart:async/future_impl.dart:162:18)
#4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:846:45)
#5      Future._propagateToListeners (dart:async/future_impl.dart:875:13)
#6      Future._complete (dart:async/future_impl.dart:638:7)
#7      _StreamIterator._onData (dart:async/stream_impl.dart:1034:20)
#8      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#10     _StreamController.add (dart:async/stream_controller.dart:606:5)
#11     runExecutableArguments.<anonymous closure> (package:process_run/src/process_run.dart:147:13)
#12     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#13     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#14     _StreamController.add (dart:async/stream_controller.dart:606:5)
#15     _Socket._onData (dart:io-patch/socket_patch.dart:2447:41)
#16     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#17     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#18     _StreamController.add (dart:async/stream_controller.dart:606:5)
#19     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1936:33)
#20     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1379:14)
#21     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#22     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)
@alextekartik
Copy link
Contributor

Thanks for the report, indeed it seems that putting all the resulting output in memory is causing the error. I'll look into it.

alextekartik added a commit that referenced this issue Feb 21, 2024
…ns to avoid out of memory for very long output
@alextekartik
Copy link
Contributor

To handle such case (i.e. it is trying to add 10GB of output here). I have added a way to discard putting the output in the resulting ProcessResult.stdout. I have added options noStdoutResult and noStderrResult to ShellOptions and runExecutableArguments. In this case the resulting ProcessResult will have a null stdout (or stderr). You can still stream the output as desired but the overall result is discarded and it should solve your issue. Let me know

usage example:

var shell = Shell(options: ShellOptions(noStdoutResult: true));
await shell.run('xxxx');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants