34 lines
748 B
Python
34 lines
748 B
Python
import subprocess
|
|
|
|
class Reciever:
|
|
|
|
def __init__(self, protocol: str, target: str, disable_audio: bool) -> None:
|
|
self.protocol = protocol # should be 'tcp' or 'udp'
|
|
self.target = target
|
|
self.disable_audio = disable_audio
|
|
self.proc = None
|
|
|
|
def __del__(self) -> None:
|
|
self.stop()
|
|
|
|
def start(self):
|
|
# currently there is no direct ffplay support in the ffmpeg package
|
|
|
|
args = ['ffplay', '-fflags', 'nobuffer', '-flags', 'low_delay', '-f', 'mpegts']
|
|
|
|
if self.disable_audio:
|
|
args.append('-an')
|
|
|
|
# the address
|
|
args.append(self.protocol+ '://' + self.target + '?listen')
|
|
|
|
self.proc = subprocess.Popen(args)
|
|
|
|
def stop(self):
|
|
if self.proc:
|
|
self.proc.terminate()
|
|
self.proc.wait(1)
|
|
self.proc.kill()
|
|
self.proc = None
|
|
|