0

I am using a Jetson Nano and the idea is the run a video when a button is pushed. Which I have working currently by waiting for a button push event and then running a shell script using subprocess.call() to call a shell script I wrote that contains gstreamer command to run the video.

My next objective is to be able to stop the video, even mid-video, if the button is pushed. Doing some research (aka searching stackoverflow), it seems the best way to stop gstreamer video is to tell the pipeline to terminate. Going off of what I found, my code is essentially as follows:

import subprocess

p = subprocess.Popen("./open-video.sh")
time.sleep(2)
p.kill()

Which doesn't stop the video, other variations I've tried are as follows (none have worked):

import subprocess, os
import signal

p = subprocess.Popen("./open-video.sh")
time.sleep(2)
os.kill(p.pid, signal.SIGINT)
import subprocess
p = subprocess.call("./open-video.sh")
p.kill()

The contents of open-video.sh:

gst-launch-1.0 filesrc location=CES_AE_3D.mp4 ! qtdemux name=demux ! h264parse ! omxh264dec ! nvoverlaysink -e

Thanks for reading.

  • What is the content of `open-video.sh`? What do you mean by "stopping the video", do you want to obtain the effect of pressing the *stop* button or do you want to stop the `gstreamer` process from execution (i.e. killing it)? – norok2 Dec 04 '19 at 16:46
  • @norok2 The ideal situation is that the video (which is playing full-screen) would close and the script would continue as normal. – Maxwell Newberry Dec 04 '19 at 16:59
  • You are sending the signal to the shell process, not the gstreamer process that your shell script started. I suggest moving the logic from your shell script to your python program. Then you python program will run `gst-launch-1.0` instead of a shell, and you can more easily control it and send it the signal. – dsh Dec 04 '19 at 17:57
  • @dsh Thanks, I was able to get the process to terminate with your suggestion. Is there a signal or option for me to terminate the process but not CTRL+C out of the python script in its entirety? – Maxwell Newberry Dec 04 '19 at 18:46

1 Answers1

0

Kill the gst-launch-1.0 process instead of the script running the gst-launch-1.0 process. You need to get the pid that is created when your shell script is executed.

eagle33322
  • 228
  • 2
  • 11
  • 1
    https://stackoverflow.com/questions/58536265/how-to-kill-a-subprocess-in-python - Based on this answer I was able to cancel the process. Is there a way do cancel the process without emulating a CTRL+C signal? – Maxwell Newberry Dec 04 '19 at 18:27