Screen Capture module makes Slicer hang

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, i.e. "-filter_complex \"palettegen,[v]paletteuse\"", with no luck.

I’m using iTerm2 on macOS Sierra 10.12.6.

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. Maybe you can try to replace this simple split with a version that does not split along spaces within quoted strings (like this).

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 &. 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:

/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:

/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.

1 Like

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.

Running just ffmpeg with Popen in the console causes the problem as well. Apparently, this can be solved adding -nostdin to the parameters. I’ll open a PR.

2 Likes