我试图在linux上使用subprocess.call()调用ffmpeg命令,但是我无法正确地理解参数。在此之前,我使用了os.system,它起了作用,但不建议使用此方法。
使用带有像"-i“这样的破折号的参数会导致这个错误。
Unrecognized option 'i "rtsp://192.168.0.253:554/user=XXX&password=XXX&channel=0&stream=0.sdp?real_stream"'.
Error splitting the argument list: Option not found使用不带破折号的参数(如"i“)会使我犯这个错误。
[NULL @ 0x7680a8b0] Unable to find a suitable output format for 'i rtsp://192.168.0.253:554/user=admin&password=&channel=0&stream=0.sdp?real_stream'
i rtsp://192.168.0.253:554/user=XXX&password=XXX&channel=0&stream=0.sdp?real_stream: Invalid argument这是密码
class IPCamera(Camera):
"""
IP Camera implementation
"""
def __init__(self,
path='\"rtsp://192.168.0.253:554/'
'user=XXX&password=XXX&channel=0&stream=0.sdp?real_stream\"'):
"""
Constructor
"""
self.path = path
def __ffmpeg(self, nb_frames=1, filename='capture%003.jpg'):
"""
"""
ffm_input = "-i " + self.path
ffm_rate = "-r 5"
ffm_nb_frames = "-vframes " + str(nb_frames)
ffm_filename = filename
if platform.system() == 'Linux':
ffm_path = 'ffmpeg'
ffm_format = '-f v4l2'
else:
ffm_path = 'C:/Program Files/iSpy/ffmpeg.exe'
ffm_format = '-f image2'
command = [ffm_path, ffm_input, ffm_rate, ffm_format, ffm_nb_frames, ffm_filename]
subprocess.call(command)
print(command)顺便说一句,我正在MT7688上运行这个命令。
谢谢
发布于 2018-09-14 14:03:43
你必须分两种选择:
command = [ffm_path, '-i', ffm_input, '-r', ffm_rate, '-f', ffm_format, '-vframes', ffm_nb_frames, ffm_filename]ffm_input、ffm_rate、ffm_format只应包含以下值:
ffm_input = self.path
ffm_rate = '5'
ffm_nd_frames = str(nb_frames)
ffm_format = 'v412' if platform.system() == 'Linux' else 'image2'当您传递一个列表时,不会进行任何解析,因此将-r 5作为一个参数,但是该程序希望您提供两个独立的参数,-r,然后是5。
基本上,如果将它们作为一个元素放在列表中,就好像在命令行中引用了它们一样:
$ echo "-n hello"
-n hello
$ echo -n hello
hello$在第一个示例中,echo看到了一个参数-n hello。因为它不匹配任何选项,所以它只打印它。在第二种情况下,echo看到两个参数-n和hello,第一个参数是有效的选项,以抑制行结束,正如您可以看到的那样,提示符是在hello之后打印的,而不是在自己的行上。
https://stackoverflow.com/questions/52333558
复制相似问题