From c39cfc51d014d6eb8143c961b40aa0e45192d97c Mon Sep 17 00:00:00 2001 From: jaydee Date: Thu, 19 Jun 2025 18:04:30 +0200 Subject: [PATCH] build --- handle_imported_video.py | 70 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/handle_imported_video.py b/handle_imported_video.py index 2c3079e..ed316b6 100644 --- a/handle_imported_video.py +++ b/handle_imported_video.py @@ -107,10 +107,13 @@ def export_gps(_DEV,_SOURCE_DIR,_DAY_DIRS): if ops == "win": _FULL_PATH = _SOURCE_DIR + "\\" + _DEV + "\\" + _DAY_DIR + "\\" else: - _FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR + "/" + _FULL_PATH = _SOURCE_DIR + _DEV + "/" + _DAY_DIR + "/" shutil.copyfile("/usr/bin/ffmpeg", _FULL_PATH + "ffmpeg") shutil.copyfile("/usr/bin/ffprobe", _FULL_PATH + "ffprobe") os.chdir(_FULL_PATH) + + if not os.path.exists("gps_data"): + os.mkdir("gps_data") for filename in os.listdir(_FULL_PATH): if _FILTER: if _PATERN in filename: @@ -121,7 +124,20 @@ def export_gps(_DEV,_SOURCE_DIR,_DAY_DIRS): myCmd = f"gopro2gpx -s {filename} {filename.replace('.MP4', '')}" print(myCmd) status, output = subprocess.getstatusoutput(myCmd) - print(output) + #print(output) + print(status) + if os.path.exists(f"{_FULL_PATH}gps_data/{filename.replace('.MP4', '.csv')}"): + os.remove(f"{_FULL_PATH}gps_data/{filename.replace('.MP4', '.csv')}") + if os.path.exists(f"{_FULL_PATH}gps_data/{filename.replace('.MP4', '.gpx')}"): + os.remove(f"{_FULL_PATH}gps_data/{filename.replace('.MP4', '.gpx')}") + if os.path.exists(f"{_FULL_PATH}gps_data/{filename.replace('.MP4', '.kml')}"): + os.remove(f"{_FULL_PATH}gps_data/{filename.replace('.MP4', '.kml')}") + try: + shutil.move(f"{_FULL_PATH}{filename.replace('.MP4', '.csv')}", f"{_FULL_PATH}gps_data/","") + shutil.move(f"{_FULL_PATH}{filename.replace('.MP4', '.gpx')}", f"{_FULL_PATH}gps_data/") + shutil.move(f"{_FULL_PATH}{filename.replace('.MP4', '.kml')}", f"{_FULL_PATH}gps_data/") + except: + pass os.remove(_FULL_PATH + "ffmpeg") os.remove(_FULL_PATH + "ffprobe") def flip_videos(_DEV,_SOURCE_DIR,_DAY_DIRS): @@ -130,10 +146,11 @@ def flip_videos(_DEV,_SOURCE_DIR,_DAY_DIRS): if ops == "win": _FULL_PATH = _SOURCE_DIR + "\\" + _DEV + "\\" + _DAY_DIR + "\\" else: - _FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR + "/" + _FULL_PATH = _SOURCE_DIR + _DEV + "/" + _DAY_DIR + "/" os.chdir(_FULL_PATH) _PROCESSED = _FULL_PATH + "processed" + print(f"Processed folder : {_PROCESSED}") if not os.path.exists(_PROCESSED): os.mkdir(_PROCESSED) for filename in os.listdir(_FULL_PATH): @@ -144,8 +161,6 @@ def flip_videos(_DEV,_SOURCE_DIR,_DAY_DIRS): continue if filename.endswith(".MP4") and not filename.startswith("joined_"): - - create_date = filedate.File(filename).get() print(filename) export_name = 'flipped_' + filename @@ -154,42 +169,21 @@ def flip_videos(_DEV,_SOURCE_DIR,_DAY_DIRS): "ffmpeg", "-i", filename ,"-c", "copy", "-metadata:s:v:0", "rotate=180", "-y", export_name ] else: - # myCmd = [ - # "/usr/bin/ffmpeg", "-i", filename, "-c", "copy", "-metadata:s:v:0", "rotate=180", "-y", export_name - # ] - # myCmd = [ - # "/usr/bin/ffmpeg", "-i", filename, "-vf", "transpose=2,transpose=2", "-y", export_name - # ] - # myCmd = [ - # "/usr/bin/ffmpeg", "-i", filename, "-vf", "hflip", "-c:a", "-codec", "copy", "-y", export_name - # ] myCmd = f"exiftool -rotation=180 {filename}" - #Path = "~/Documents/File.txt" - # filedate.File(Path).set( - # created = "1st February 2003, 12:30", - # modified = "3:00 PM, 04 May 2009", - # accessed = "08/07/2014 18:30:45" - # ) if _TEST: print(_FULL_PATH) print(myCmd) print(myCmd) status, output = subprocess.getstatusoutput(myCmd) print(output) - #proc = subprocess.Popen(myCmd,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) - - # print(f"Fliping {filename} in {_DAY_DIR}...".ljust(100)) - # ff = FfmpegProgress(myCmd) - # with tqdm(total=100, position=1, desc="Fliping") as pbar: - # for progress in ff.run_command_with_progress(): - # pbar.update(progress - pbar.n) - # pbar.close() - # get the output - #print(ff.stderr) - #ffmpeg -i .\GH010149.MP4 -c:v hevc_amf -rc cqp -qp_i 42 -qp_p 42 -quality quality -crf 25 output7.mp4 try: - shutil.move(filename + "_original", _PROCESSED + "/" + filename) + print("Moving file to processed") + src = _FULL_PATH + filename + "_original" + dest = _PROCESSED + "/" + filename + print(f"Source : {src}") + print(f"Destination : {dest}") + shutil.move(src, dest) # shutil.move(export_name, export_name) filedate.File(filename).set( @@ -355,10 +349,14 @@ def join_videos(_DEV,_SOURCE_DIR,_DAY_DIRS): if status == 0 and not _TEST: print("Moving...") for p in parts: - try: - shutil.move(p, _PROCESSED) - except: - print(f"Failed to move {p}") + + if os.path.exists(_PROCESSED + p): + os.remove(p) + else: + try: + shutil.move(p, _PROCESSED) + except: + print(f"Failed to move {p}") try: shutil.move(p.replace("MP4", "THM"), _PROCESSED) except: