how to write subcommand to FFPLAY during playback using subprocess module?

277 Views Asked by At

I'm trying to pause a video playback started with FFPLAY through a python subprocess. You can do this manually by pressing the "p" key on the keyboard while the video is playing. I'd like to emulate this behavior through a python call.

I'm now sending a "p" string, encoded as bytes, through the stdin of the Popen call. The video starts and I can pause it with the keyboard but the communicate command doesn't seem to do anything.

import subprocess
import time

proc = subprocess.Popen(['ffplay', 'PATH_TO_'],
                        stdin=subprocess.PIPE,
                        stdout=subprocess.PIPE,
                        )
time.sleep(2) # just waiting to make sure playback has started
proc.communicate(input="p".encode())[0]

Thanks in advance!

0

There are 0 best solutions below