# Screen Capture module makes Slicer hang

**URL:** <https://discourse.slicer.org/t/screen-capture-module-makes-slicer-hang/10456>\
**Category:** Development\
**Created:** [February 27, 2020, 10:43am UTC](https://discourse.slicer.org/t/screen-capture-module-makes-slicer-hang/10456 "2020-02-27T10:43:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [February 27, 2020, 10:43am UTC](https://discourse.slicer.org/t/screen-capture-module-makes-slicer-hang/10456/1 "2020-02-27T10:43:30Z")

</div>

Hi all,

When I try to make a GIF with the Screen Capture module, Slicer hangs and I need to force quit. I’m quite confident it happens when `ffmpeg` is called. I open Slicer from `zsh` and I think this shell is not happy with some characters in the command line. If I run the command with quotes outside Slicer, it works fine. It also works if I open Slicer from `bash`. I tried using quotes [here](https://github.com/Slicer/Slicer/blob/09d3554e74422e3bb504d2f7f2364e9534284453/Modules/Scripted/ScreenCapture/ScreenCapture.py#L755), i.e. `"-filter_complex \"palettegen,[v]paletteuse\""`, with no luck.

I’m using iTerm2 on macOS Sierra 10.12.6.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 27, 2020, 1:42pm UTC](https://discourse.slicer.org/t/screen-capture-module-makes-slicer-hang/10456/2 "2020-02-27T13:42:54Z")

</div>

How does the correctly working command line look like?

Python `subprocess.Popen` expects command-line arguments in a list but GUI for getting arguments from users as a list of strings would be quite complicated, so we just use a string and [split to arguments at space characters](https://github.com/Slicer/Slicer/blob/09d3554e74422e3bb504d2f7f2364e9534284453/Modules/Scripted/ScreenCapture/ScreenCapture.py#L1275). Maybe you can try to replace this simple split with a version that does not split along spaces within quoted strings (like [this](https://stackoverflow.com/questions/16710076/python-split-a-string-respect-and-preserve-quotes)).

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [February 27, 2020, 9:40pm UTC](https://discourse.slicer.org/t/screen-capture-module-makes-slicer-hang/10456/3 "2020-02-27T21:40:15Z")

</div>

Ok so I might have omitted some information. Sorry about that.

In macOS, I always open Slicer from the command line as `path_to_slicer &!`. I have noticed that the problem is caused by the [`&`](https://bashitout.com/2013/05/18/Ampersands-on-the-command-line.html). When Slicer hangs, I just run `fg` in the terminal and the `ffmpeg` is run. I’m still not sure this behavior is expected. This is the same in `bash` and `zsh`.

Still confused by the command line. This one doesn’t work on `zsh`:

```auto
/usr/local/bin/ffmpeg -y -r 0.4 -start_number 0 -i /Users/fernando/tmp/SlicerCapture/tmp-PHBIZ-%05d.png -filter_complex palettegen,[v]paletteuse /Users/fernando/tmp/SlicerCapture/SlicerCapture.gif
zsh: no matches found: palettegen,[v]paletteuse

```

But this one does:

```auto
/usr/local/bin/ffmpeg -y -r 0.4 -start_number 0 -i /Users/fernando/tmp/SlicerCapture/tmp-PHBIZ-%05d.png -filter_complex "palettegen,[v]paletteuse" /Users/fernando/tmp/SlicerCapture/SlicerCapture.gif

```

I guess I can just stop calling Slicer as a background process.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 28, 2020, 4:47pm UTC](https://discourse.slicer.org/t/screen-capture-module-makes-slicer-hang/10456/4 "2020-02-28T16:47:24Z")

</div>

It might have something to do with console output redirection or usage of " characters in Python `subprocess.Popen`. If you can experiment with this a bit more (e.g., trying to call subprocess.Popen directly to run ffmpeg in Slicer’s Python console and see if you can find a working variant) then it would be great. If not, then I guess it’s useful information that running Slicer as a background process may lead to issues.

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [March 1, 2020, 10:29am UTC](https://discourse.slicer.org/t/screen-capture-module-makes-slicer-hang/10456/5 "2020-03-01T10:29:48Z")

</div>

Running just ffmpeg with Popen in the console causes the problem as well. [Apparently](https://stackoverflow.com/questions/47115191/when-i-run-ffmpeg-in-the-background-how-do-i-prevent-suspended-tty-output), this can be solved adding `-nostdin` to the parameters. I’ll open a PR.
