| @@ -22,29 +22,30 @@ def list_folder(org_folder, tar_folder, code): | |||||
| print("file ignore: {0} ".format(os.path.join(root, f))) | print("file ignore: {0} ".format(os.path.join(root, f))) | ||||
| continue | continue | ||||
| else: | else: | ||||
| convert(os.path.join(root, f), os.path.join(tar_folder, code, list(root.split("/"))[-1],f.replace(SUFFIX,"")+TARGET_SUFFIX)) | |||||
| 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)) | |||||
| cmd = 'ffmpeg -i {0} -c copy {1}'.format(origin,target) | |||||
| print("origin: {0} ,target: {1}".format(origin, target)) | |||||
| cmd = 'ffmpeg -i {0} -c copy {1}'.format(origin, target) | |||||
| print("cmd:: {0}".format(cmd)) | print("cmd:: {0}".format(cmd)) | ||||
| args = shlex.split(cmd) | args = shlex.split(cmd) | ||||
| # status, output = sp.getstatusoutput(cmd) | # status, output = sp.getstatusoutput(cmd) | ||||
| print("status:: {0}, output {1}".format(status, output)) | |||||
| proc = sp.Popen(args,stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE) | |||||
| # print("status:: {0}, output {1}".format(status, output)) | |||||
| proc = sp.Popen(args, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE) | |||||
| y = b'y' | |||||
| try: | try: | ||||
| if 'Overwrite ? [y/N]' in outs: | |||||
| proc.stdin.write("y\n") | |||||
| outs, errs = proc.communicate(timeout=300) | outs, errs = proc.communicate(timeout=300) | ||||
| print(outs,errs) | |||||
| if p.returncode == 0: | |||||
| if 'Overwrite ? [y/N]' in outs: | |||||
| proc.stdin.write(y) | |||||
| print(outs, errs) | |||||
| if proc.returncode == 0: | |||||
| print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) | print("{0} convert {1} Success, origin dat will remove!".format(origin, target)) | ||||
| os.remove(origin) | os.remove(origin) | ||||
| else: | else: | ||||
| print("{0} convert fail".format(origin)) | print("{0} convert fail".format(origin)) | ||||
| except TimeoutExpired: | |||||
| except sp.TimeoutExpired: | |||||
| proc.kill() | proc.kill() | ||||
| @@ -54,4 +55,4 @@ if __name__ == "__main__": | |||||
| codec = sys.argv[1] | codec = sys.argv[1] | ||||
| # timeout=sys.argv[2] | # timeout=sys.argv[2] | ||||
| print("codec:: {0}".format(codec)) | print("codec:: {0}".format(codec)) | ||||
| list_folder(DAT_FOLDER, TARGET_FOLDER, codec) | |||||
| list_folder(DAT_FOLDER, TARGET_FOLDER, codec) | |||||