FFmpeg
Loading...
Searching...
No Matches
zmqshell.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3import argparse
4import cmd
5import logging
6import sys
7import zmq
8
9HELP = '''
10Provide a shell used to send interactive commands to a zmq filter.
11
12The command assumes there is a running zmq or azmq filter acting as a
13ZMQ server.
14
15You can send a command to it, following the syntax:
16TARGET COMMAND [COMMAND_ARGS]
17
18* TARGET is the target filter identifier to send the command to
19* COMMAND is the name of the command sent to the filter
20* COMMAND_ARGS is the optional specification of command arguments
21
22See the zmq/azmq filters documentation for more details, and the
23zeromq documentation at:
24https://zeromq.org/
25'''
26
27logging.basicConfig(format='zmqshell|%(levelname)s> %(message)s', level=logging.INFO)
28log = logging.getLogger()
29
30
31class LavfiCmd(cmd.Cmd):
32 prompt = 'lavfi> '
33
34 def __init__(self, bind_address):
35 context = zmq.Context()
36 self.requester = context.socket(zmq.REQ)
37 self.requester.connect(bind_address)
38 cmd.Cmd.__init__(self)
39
40 def onecmd(self, cmd):
41 if cmd == 'EOF':
42 sys.exit(0)
43 log.info(f"Sending command: {cmd}")
44 self.requester.send_string(cmd)
45 response = self.requester.recv_string()
46 log.info(f"Received response: {response}")
47
48
50 argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter
51):
52 pass
53
54
55def main():
56 parser = argparse.ArgumentParser(description=HELP, formatter_class=Formatter)
57 parser.add_argument('--bind-address', '-b', default='tcp://localhost:5555', help='specify bind address used to communicate with ZMQ')
58
59 args = parser.parse_args()
60 try:
61 LavfiCmd(args.bind_address).cmdloop('FFmpeg libavfilter interactive shell')
62 except KeyboardInterrupt:
63 pass
64
65
66if __name__ == '__main__':
67 main()
onecmd(self, cmd)
Definition zmqshell.py:40
__init__(self, bind_address)
Definition zmqshell.py:34