record-camera-and-screen/RunCMD.py

53 lines
1.8 KiB
Python
Raw Normal View History

2018-06-16 14:06:56 +00:00
import subprocess,os,sys
2018-04-17 08:11:26 +00:00
def run_cmd(cmd, shell = True, universal_newlines = False):
output_info=[]
output_err=[]
2018-06-16 14:06:56 +00:00
cmd = os.path.join(get_ffmpeg_path(), cmd)
print('执行cmd\n%s' % cmd)
2018-04-17 08:11:26 +00:00
with subprocess.Popen(cmd,
shell = shell,
universal_newlines = universal_newlines,
stdout = subprocess.PIPE,
stdin = subprocess.PIPE,
stderr = subprocess.PIPE
) as p:
while True:
2018-04-24 01:35:42 +00:00
info=p.stdout.read()
2018-04-17 08:11:26 +00:00
# print(dir(p.stderr))
2018-04-24 01:35:42 +00:00
print(info)
err=p.stderr.read()
print(err)
# if not info and not err:
if info == b'' and err == b'':
2018-04-17 08:11:26 +00:00
if p.poll() is not None:
break
else:
output_info.append(info)
output_err.append(err)
return output_err, output_info
2018-06-16 14:06:56 +00:00
def get_ffmpeg_path():
datadir = ''
subdir = os.path.join('ffmpeg-shared','bin')
if getattr(sys, 'frozen', False):
# The application is frozen
datadir = os.path.dirname(sys.executable)
else:
# The application is not frozen
# Change this bit to match where you store your data files:
datadir = os.path.dirname(__file__)
datadir = os.path.join(datadir, subdir)
datadir = os.path.abspath(datadir)
print(datadir)
#如果存在ffmpeg.exe
if os.path.isfile(os.path.join(datadir, 'ffmpeg.exe')):
return datadir
#兼容环境变量设置
return ''
2018-04-17 08:11:26 +00:00