diff --git a/h264_converter.py b/h264_converter.py index 02ccaa8..48c060d 100644 --- a/h264_converter.py +++ b/h264_converter.py @@ -14,6 +14,35 @@ l = c.cdll.LoadLibrary(dll) print("Readed DLL SDK Version", l.H264_PLAY_GetSdkVersion()) +##only use this part in windows +from subprocess import call as sCall +from subprocess import DEVNULL +import os, sys + +def check(): + try: + if sCall(f"ffmpeg -version", stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) != 0: + print("Cannot find ffmpeg, features must be disabled") + return False + else: + print("Enabled ffmpeg features!") + return True + except: + return False + +FFMPEG = check() + +def convertAviToAny(source_file, out_format, print_statuses = False): + print(f"Start convertion to {out_format}") + sCall(f"ffmpeg -y -i \"{source_file}\" \"{source_file}.{out_format}\"", stdin=None if print_statuses else DEVNULL, stdout=None if print_statuses else DEVNULL, stderr=None if print_statuses else DEVNULL) + if os.path.exists(f"{source_file}.{out_format}"): + print("convert to other format success") + os.remove(source_file) + else: + print("in process convert trubles convert") + sys.exit(2) +##end + @c_callback(None, c_windows.DWORD, c_windows.DWORD, c.c_long) def coverPosCallback(CurrentPos, TotoalPos, dwUser): pass @@ -36,8 +65,10 @@ enum ENCODE_TYPE StreamTypeStd = 8 }; """) +parser.add_argument("--out-format", type=str, default="avi", help = "output video file type") +parser.add_argument("--show-convertion", action="store_true", help = "show ffmpeg cenvertion statuses") args = parser.parse_args() -output = str(args.input + ".avi") +output = f"{args.input}.avi" print("Input file path:", args.input) print("Output file path", output) @@ -63,9 +94,19 @@ while True: if os.path.exists(output): if os.path.getsize(output) == last_size: print("completed!", check_exists_fails, check_output_complete) - sys.exit(0) + if args.out_format.lower() != "avi": + if FFMPEG: + convertAviToAny(output, args.out_format, args.show_convertion) + sys.exit(0) + else: + print("cannot find ffmpeg, save only original file") + sys.exit(0) + else: + print("not need convert file") + sys.exit(0) else: last_size = os.path.getsize(output) check_output_complete -= 1 else: - check_exists_fails -= 1 \ No newline at end of file + check_exists_fails -= 1 +