Skip to content

Commit

Permalink
feat: Fixed duplicated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dawhn committed Jul 19, 2022
1 parent 19e415d commit 1cbf56f
Showing 1 changed file with 0 additions and 70 deletions.
70 changes: 0 additions & 70 deletions backend/src/crispy/utils/ffmpeg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,76 +171,6 @@ def merge_videos(videos_path: List[str], save_path: str) -> None:
.overwrite_output()
.run(quiet=True)
) # yaPf: disable


def find_available_path(video_path: str) -> str:
"""
Find available path to store the scaled video temporarily.
"""
dirname, basename = os.path.split(video_path)
h = str(hash(basename)) + ".mp4"
while (os.path.exists(os.path.join(dirname, h))):
h = random.choice(string.ascii_letters) + h

return os.path.join(dirname, h)


def scale_video(video_path: str) -> None:
"""
Scale (up or down) a video.
"""
if os.path.exists(video_path):
save_path = find_available_path(video_path)
(
ffmpeg
.input(video_path)
.filter("scale", w=1920, h=1080)
.output(save_path, start_number=0)
.overwrite_output()
.run()
) # yapf: disable

os.remove(video_path)
os.rename(save_path, video_path)
# check if image has to be upscaled or downscaled ?
else:
raise FileNotFoundError(f"{video_path} not found")


def create_new_path(video_path: str) -> str:
"""
Create new path based on the original one.
"""
drive, tail = os.path.split(video_path)
name, ext = os.path.splitext(tail)
nb = 1
cur_name = name + "_" + str(nb)
while os.path.exists(os.path.join(drive, cur_name + ext)):
nb = nb + 1
cur_name = name + "_" + str(nb)

tail = cur_name + ext
res = os.path.join(drive, cur_name + ext)

return res


# FIXME: audio
def merge_videos(videos_path: List[str], save_path: str) -> None:
"""
Merge videos together.
"""
if len(videos_path) > 1:
videos: List[Any] = []
for video_path in videos_path:
videos.append(ffmpeg.input(video_path))
(
ffmpeg
.concat(*videos)
.output(save_path)
.overwrite_output()
.run(quiet=True)
) # yapf: disable
else:
shutil.copyfile(videos_path[0], save_path)

Expand Down

0 comments on commit 1cbf56f

Please sign in to comment.