| @@ -3,7 +3,8 @@ video.py h265[h264] | |||||
| """ | """ | ||||
| import sys | import sys | ||||
| import subprocess | |||||
| import subprocess as sp | |||||
| import shlex | |||||
| import time | import time | ||||
| import os | import os | ||||
| @@ -17,23 +18,34 @@ def list_folder(org_folder, tar_folder, code): | |||||
| current_time = time.strftime(time.strftime("%Y-%m-%d-%H"), time.localtime()) | current_time = time.strftime(time.strftime("%Y-%m-%d-%H"), time.localtime()) | ||||
| for root, dirs, files in os.walk(org_folder): | for root, dirs, files in os.walk(org_folder): | ||||
| for f in files: | for f in files: | ||||
| if current_time + ".dat" == f: | |||||
| print("{0} ignore".format(os.path.join(root, f))) | |||||
| if current_time in f: | |||||
| print("file ignore: {0} ".format(os.path.join(root, f))) | |||||
| continue | continue | ||||
| convert(os.path.join(root, f), os.path.join(tar_folder, code, list(root.split("/"))[-1],f.replace(SUFFIX,"")+TARGET_SUFFIX)) | |||||
| else: | |||||
| convert(os.path.join(root, f), os.path.join(tar_folder, code, list(root.split("/"))[-1],f.replace(SUFFIX,"")+TARGET_SUFFIX)) | |||||
| def convert(origin, target): | def convert(origin, target): | ||||
| print("origin: {0} ,target: {1}".format(origin,target)) | print("origin: {0} ,target: {1}".format(origin,target)) | ||||
| cmd = 'ffmpeg -i {0} -c copy {1}'.format(origin,target) | cmd = 'ffmpeg -i {0} -c copy {1}'.format(origin,target) | ||||
| print("cmd:: {0}".format(cmd)) | print("cmd:: {0}".format(cmd)) | ||||
| status, output = subprocess.getstatusoutput(cmd) | |||||
| args = shlex.split(cmd) | |||||
| # status, output = sp.getstatusoutput(cmd) | |||||
| print("status:: {0}, output {1}".format(status, output)) | print("status:: {0}, output {1}".format(status, output)) | ||||
| if status == 0: | |||||
| print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) | |||||
| os.remove(origin) | |||||
| else: | |||||
| print("{0} convert fail".format(origin)) | |||||
| proc = sp.Popen(args,stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE) | |||||
| try: | |||||
| if 'Overwrite ? [y/N]' in outs: | |||||
| proc.stdin.write("y\n") | |||||
| outs, errs = proc.communicate(timeout=300) | |||||
| print(outs,errs) | |||||
| if p.returncode == 0: | |||||
| print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) | |||||
| os.remove(origin) | |||||
| else: | |||||
| print("{0} convert fail".format(origin)) | |||||
| except TimeoutExpired: | |||||
| proc.kill() | |||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||