mirror of https://github.com/AlfredoSequeida/fvid
Fixed #8 Output file naming not working correctly
This commit is contained in:
parent
ba150c3304
commit
ee078031e0
29
fvid.py
29
fvid.py
|
@ -115,8 +115,15 @@ def save_bits_to_file(filepath, bits):
|
|||
mime = Magic(mime=True)
|
||||
mime_type = mime.from_buffer(bitstring.tobytes())
|
||||
|
||||
# If filepath not passed in use defualt
|
||||
# otherwise used passed in filepath
|
||||
if file_path == None:
|
||||
filepath = f"file{mimetypes.guess_extension(type=mime_type)}"
|
||||
else:
|
||||
filepath = file_path
|
||||
|
||||
with open(
|
||||
f"{filepath}/file{mimetypes.guess_extension(type=mime_type)}", "wb"
|
||||
filepath, "wb"
|
||||
) as f:
|
||||
bitstring.tofile(f)
|
||||
|
||||
|
@ -158,12 +165,18 @@ def make_image_sequence(bitstring, resolution=(1920, 1080)):
|
|||
|
||||
def make_video(output_filepath, image_sequence):
|
||||
|
||||
if output_filepath == None:
|
||||
outputfile = "file.mp4"
|
||||
else:
|
||||
outputfile = output_filepath
|
||||
|
||||
|
||||
frames = glob.glob(f"{FRAMES_DIR}encoded_frames*.png")
|
||||
|
||||
# for one frame
|
||||
if len(frames) == 1:
|
||||
ffmpeg.input(frames[0], loop=1, t=1).output(
|
||||
output_filepath, vcodec="libx264rgb"
|
||||
outputfile, vcodec="libx264rgb"
|
||||
).run(quiet=True)
|
||||
|
||||
else:
|
||||
|
@ -171,7 +184,7 @@ def make_video(output_filepath, image_sequence):
|
|||
f"{FRAMES_DIR}encoded_frames*.png",
|
||||
pattern_type="glob",
|
||||
framerate="1/5",
|
||||
).output(output_filepath, vcodec="libx264rgb").run(quiet=True)
|
||||
).output(outputfile, vcodec="libx264rgb").run(quiet=True)
|
||||
|
||||
|
||||
def cleanup():
|
||||
|
@ -208,14 +221,12 @@ if __name__ == "__main__":
|
|||
if args.decode:
|
||||
bits = get_bits_from_video(args.input)
|
||||
|
||||
file_path = ""
|
||||
file_path = None
|
||||
|
||||
if args.output:
|
||||
file_path = args.output
|
||||
else:
|
||||
file_path = "./"
|
||||
|
||||
save_bits_to_file("./", bits)
|
||||
save_bits_to_file(file_path, bits)
|
||||
|
||||
elif args.encode:
|
||||
# get bits from file
|
||||
|
@ -230,12 +241,10 @@ if __name__ == "__main__":
|
|||
f"{FRAMES_DIR}encoded_frames_{index}.png"
|
||||
)
|
||||
|
||||
video_file_path = ""
|
||||
video_file_path = None
|
||||
|
||||
if args.output:
|
||||
video_file_path = args.output
|
||||
else:
|
||||
video_file_path = "./file.mp4"
|
||||
|
||||
make_video(video_file_path, image_sequence)
|
||||
|
||||
|
|
Loading…
Reference in New Issue