mirror of
https://gitlab.sectorq.eu/jaydee/python.git
synced 2025-12-14 18:44:53 +01:00
bitwarden
This commit is contained in:
@@ -19,7 +19,7 @@ elif sys.platform == "darwin":
|
|||||||
elif sys.platform == "win32":
|
elif sys.platform == "win32":
|
||||||
ops = "win"
|
ops = "win"
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "r:fp:d:s:", ["command=", "help", "output=", "backup"])
|
opts, args = getopt.getopt(sys.argv[1:], "a:r:fp:d:s:", ["command=", "help", "output=", "backup"])
|
||||||
except getopt.GetoptError as err:
|
except getopt.GetoptError as err:
|
||||||
# print help information and exit:
|
# print help information and exit:
|
||||||
print(str(err)) # will print something like "option -a not recognized"
|
print(str(err)) # will print something like "option -a not recognized"
|
||||||
@@ -45,6 +45,8 @@ for o, a in opts:
|
|||||||
_FLIP = True
|
_FLIP = True
|
||||||
elif o in ("-r", "--source"):
|
elif o in ("-r", "--source"):
|
||||||
_SOURCE_DIR = a
|
_SOURCE_DIR = a
|
||||||
|
elif o in ("-a", "--action"):
|
||||||
|
_ACTION = a
|
||||||
elif o in ("-s", "--sequence"):
|
elif o in ("-s", "--sequence"):
|
||||||
a = a.split(",")
|
a = a.split(",")
|
||||||
for s in a:
|
for s in a:
|
||||||
@@ -62,99 +64,161 @@ if ops == "win":
|
|||||||
else:
|
else:
|
||||||
_FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR + "/"
|
_FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR + "/"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#print(_FULL_PATH)
|
#print(_FULL_PATH)
|
||||||
|
|
||||||
video_seq = {}
|
if _ACTION == "join":
|
||||||
if os.path.exists(_FULL_PATH):
|
video_seq = {}
|
||||||
if os.path.exists(_FULL_PATH + "100GOPRO"):
|
|
||||||
_FULL_PATH = _FULL_PATH + "100GOPRO"
|
|
||||||
for filename in os.listdir(_FULL_PATH):
|
|
||||||
if filename.endswith(".MP4"):
|
|
||||||
prefix = filename[0:2]
|
|
||||||
part = prefix + filename[2:4]
|
|
||||||
seq = filename[4:8]
|
|
||||||
if not seq in video_seq:
|
|
||||||
video_seq[seq] = []
|
|
||||||
video_seq[seq].append(part + seq + ".MP4")
|
|
||||||
# print(filename)
|
|
||||||
# print(seq)
|
|
||||||
# print(part)
|
|
||||||
# print(json.dumps(video_seq,indent=2))
|
|
||||||
_PROCESSED = _FULL_PATH + "processed"
|
|
||||||
if not os.path.exists(_PROCESSED):
|
|
||||||
os.mkdir(_PROCESSED)
|
|
||||||
# print(f"SEQUENCES : {_SEQUENCES}")
|
|
||||||
|
|
||||||
for vid in video_seq:
|
if os.path.exists(_FULL_PATH):
|
||||||
|
if os.path.exists(_FULL_PATH + "100GOPRO"):
|
||||||
|
_FULL_PATH = _FULL_PATH + "100GOPRO"
|
||||||
|
for filename in os.listdir(_FULL_PATH):
|
||||||
|
if filename.endswith(".MP4"):
|
||||||
|
prefix = filename[0:2]
|
||||||
|
part = prefix + filename[2:4]
|
||||||
|
seq = filename[4:8]
|
||||||
|
if not seq in video_seq:
|
||||||
|
video_seq[seq] = []
|
||||||
|
video_seq[seq].append(part + seq + ".MP4")
|
||||||
|
# print(filename)
|
||||||
|
# print(seq)
|
||||||
|
# print(part)
|
||||||
|
# print(json.dumps(video_seq,indent=2))
|
||||||
|
_PROCESSED = _FULL_PATH + "processed"
|
||||||
|
if not os.path.exists(_PROCESSED):
|
||||||
|
os.mkdir(_PROCESSED)
|
||||||
|
# print(f"SEQUENCES : {_SEQUENCES}")
|
||||||
|
|
||||||
if len(_SEQUENCES) != 0 and vid not in _SEQUENCES:
|
for vid in video_seq:
|
||||||
continue
|
|
||||||
export_name = "joined_" + vid + ".MP4"
|
|
||||||
parts = video_seq[vid]
|
|
||||||
|
|
||||||
parts.sort()
|
if len(_SEQUENCES) != 0 and vid not in _SEQUENCES:
|
||||||
# print(parts)
|
continue
|
||||||
if len(parts) > 1:
|
export_name = "joined_" + vid + ".MP4"
|
||||||
print("This need to be joined!")
|
parts = video_seq[vid]
|
||||||
# for p in parts:
|
|
||||||
# join_string =
|
|
||||||
# else:
|
|
||||||
# continue
|
|
||||||
# print(parts)
|
|
||||||
|
|
||||||
# print(type(parts))
|
parts.sort()
|
||||||
#ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4
|
# print(parts)
|
||||||
|
if len(parts) > 1:
|
||||||
|
print("This need to be joined!")
|
||||||
|
# for p in parts:
|
||||||
|
# join_string =
|
||||||
|
# else:
|
||||||
|
# continue
|
||||||
|
# print(parts)
|
||||||
|
|
||||||
os.chdir(_FULL_PATH)
|
# print(type(parts))
|
||||||
f = open("video.txt", "w")
|
#ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4
|
||||||
f.write("# Files to join\n")
|
|
||||||
f.close()
|
|
||||||
f = open("video.txt", "a")
|
|
||||||
for p in parts:
|
|
||||||
f.write(f"file '{p}'\n")
|
|
||||||
|
|
||||||
f.close()
|
os.chdir(_FULL_PATH)
|
||||||
print(_FULL_PATH)
|
f = open("video.txt", "w")
|
||||||
# if _FLIP:
|
f.write("# Files to join\n")
|
||||||
# if ops == "win":
|
f.close()
|
||||||
# myCmd = 'ffmpeg -display_rotation 180 -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
f = open("video.txt", "a")
|
||||||
# else:
|
for p in parts:
|
||||||
# myCmd = '/opt/ffmpeg/ffmpeg -display_rotation 180 -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
f.write(f"file '{p}'\n")
|
||||||
# else:
|
|
||||||
# if ops == "win":
|
f.close()
|
||||||
# myCmd = 'ffmpeg -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
print(_FULL_PATH)
|
||||||
# else:
|
# if _FLIP:
|
||||||
# myCmd = '/opt/ffmpeg/ffmpeg -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
# if ops == "win":
|
||||||
|
# myCmd = 'ffmpeg -display_rotation 180 -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
||||||
|
# else:
|
||||||
|
# myCmd = '/opt/ffmpeg/ffmpeg -display_rotation 180 -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
||||||
|
# else:
|
||||||
|
# if ops == "win":
|
||||||
|
# myCmd = 'ffmpeg -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
||||||
|
# else:
|
||||||
|
# myCmd = '/opt/ffmpeg/ffmpeg -f concat -i video.txt -vcodec copy -acodec copy ' + export_name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# print(os.getcwd())
|
# print(os.getcwd())
|
||||||
#status, output = subprocess.getstatusoutput(myCmd)
|
#status, output = subprocess.getstatusoutput(myCmd)
|
||||||
|
|
||||||
|
if _FLIP:
|
||||||
|
if ops == "win":
|
||||||
|
myCmd = [
|
||||||
|
"ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name, "null", "/dev/null",
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
myCmd = [
|
||||||
|
"/opt/ffmpeg/ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name, "null", "/dev/null",
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
if ops == "win":
|
||||||
|
myCmd = [
|
||||||
|
"ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name , "null", "/dev/null",
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
myCmd = [
|
||||||
|
"/opt/ffmpeg/ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name , "null", "/dev/null",
|
||||||
|
]
|
||||||
|
|
||||||
|
print(myCmd)
|
||||||
|
print(f"Joining {len(parts)} files...")
|
||||||
|
ff = FfmpegProgress(myCmd)
|
||||||
|
with tqdm(total=100, position=1, desc="Convert") as pbar:
|
||||||
|
for progress in ff.run_command_with_progress():
|
||||||
|
pbar.update(progress - pbar.n)
|
||||||
|
|
||||||
|
# get the output
|
||||||
|
print(ff.stderr)
|
||||||
|
status = 0
|
||||||
|
if status == 0:
|
||||||
|
print("Moving...")
|
||||||
|
for p in parts:
|
||||||
|
try:
|
||||||
|
shutil.move(p, _PROCESSED)
|
||||||
|
except:
|
||||||
|
print(f"Failed to move {p}")
|
||||||
|
try:
|
||||||
|
shutil.move(p.replace("MP4", "THM"), _PROCESSED)
|
||||||
|
except:
|
||||||
|
print(f"Failed to move {p.replace("MP4", "THM")}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
shutil.move(p.replace("MP4", "LRV").replace("GH","GL"), _PROCESSED)
|
||||||
|
except:
|
||||||
|
print(f"Failed to move {p.replace("MP4", "LRV")}")
|
||||||
|
os.remove("video.txt")
|
||||||
|
|
||||||
|
if _ACTION == "encode":
|
||||||
|
if os.path.exists(_FULL_PATH):
|
||||||
|
if os.path.exists(_FULL_PATH + "100GOPRO"):
|
||||||
|
_FULL_PATH = _FULL_PATH + "100GOPRO"
|
||||||
|
for filename in os.listdir(_FULL_PATH):
|
||||||
|
if filename.startswith("joined_") and filename.endswith(".MP4"):
|
||||||
|
parts.append(filename)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for p in parts:
|
||||||
|
export_name = "encoded_" + p
|
||||||
if _FLIP:
|
if _FLIP:
|
||||||
if ops == "win":
|
if ops == "win":
|
||||||
myCmd = [
|
myCmd = [
|
||||||
"ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name, "null", "/dev/null",
|
"ffmpeg", "-display_rotation", "180", "-i", p, "-c:v", "hevc_amf", "-rc", "cqp", "-qp_i", "42", "-qp_p", "42", "-quality", "quality", "-crf", "25", export_name, "-f", "null", "/dev/null",
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
myCmd = [
|
myCmd = [
|
||||||
"/opt/ffmpeg/ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name, "null", "/dev/null",
|
"/opt/ffmpeg/ffmpeg", "-display_rotation", "180", "-i", p, "-c:v", "hevc_amf", "-rc", "cqp", "-qp_i", "42", "-qp_p", "42", "-quality", "quality", "-crf", "25", export_name, "-f", "null", "/dev/null",
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
if ops == "win":
|
if ops == "win":
|
||||||
myCmd = [
|
myCmd = [
|
||||||
"ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name , "null", "/dev/null",
|
"ffmpeg", "-i", p, "-c:v", "hevc_amf", "-rc", "cqp", "-qp_i", "42", "-qp_p", "42", "-quality", "quality", "-crf", "25", export_name , "-f", "null", "/dev/null",
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
myCmd = [
|
myCmd = [
|
||||||
"/opt/ffmpeg/ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name , "null", "/dev/null",
|
"/opt/ffmpeg/ffmpeg", "-i", p, "-c:v", "hevc_amf", "-rc", "cqp", "-qp_i", "42", "-qp_p", "42", "-quality", "quality", "-crf", "25", export_name , "-f", "null", "/dev/null",
|
||||||
]
|
]
|
||||||
|
|
||||||
print(myCmd)
|
print(myCmd)
|
||||||
print(f"Joining {len(parts)} files...")
|
print(f"Encoding files...")
|
||||||
ff = FfmpegProgress(myCmd)
|
ff = FfmpegProgress(myCmd)
|
||||||
with tqdm(total=100, position=1, desc="Convert") as pbar:
|
with tqdm(total=100, position=1, desc="Convert") as pbar:
|
||||||
for progress in ff.run_command_with_progress():
|
for progress in ff.run_command_with_progress():
|
||||||
@@ -162,21 +226,7 @@ if os.path.exists(_FULL_PATH):
|
|||||||
|
|
||||||
# get the output
|
# get the output
|
||||||
print(ff.stderr)
|
print(ff.stderr)
|
||||||
status = 0
|
#ffmpeg -i .\GH010149.MP4 -c:v hevc_amf -rc cqp -qp_i 42 -qp_p 42 -quality quality -crf 25 output7.mp4
|
||||||
if status == 0:
|
|
||||||
print("Moving...")
|
|
||||||
for p in parts:
|
|
||||||
try:
|
|
||||||
shutil.move(p, _PROCESSED)
|
|
||||||
except:
|
|
||||||
print(f"Failed to move {p}")
|
|
||||||
try:
|
|
||||||
shutil.move(p.replace("MP4", "THM"), _PROCESSED)
|
|
||||||
except:
|
|
||||||
print(f"Failed to move {p.replace("MP4", "THM")}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
shutil.move(p.replace("MP4", "LRV").replace("GH","GL"), _PROCESSED)
|
|
||||||
except:
|
|
||||||
print(f"Failed to move {p.replace("MP4", "LRV")}")
|
|
||||||
os.remove("video.txt")
|
|
||||||
Reference in New Issue
Block a user