-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Flowtter/settings
Settings
- Loading branch information
Showing
17 changed files
with
573 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ build/ | |
tmp/ | ||
outputs/ | ||
issues/ | ||
|
||
settings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ ffmpeg-python==0.2.0 | |
yapf==0.32.0 | ||
mypy==0.961 | ||
pylint==2.14.3 | ||
pylint-quotes==0.2.3 | ||
|
||
# Tests | ||
pytube==12.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,61 @@ | ||
print("Hello World!") | ||
import logging | ||
from typing import List | ||
|
||
from utils.arguments import args | ||
from utils.constants import NEURAL_NETWORK_PATH | ||
from utils.IO import io | ||
import video.video as vid | ||
from AI.network import NeuralNetwork | ||
|
||
logging.getLogger("PIL").setLevel(logging.ERROR) | ||
|
||
|
||
def main(videos: List[str]) -> None: | ||
io.generate_tmp_folder(not args.no_extract) | ||
|
||
nn = NeuralNetwork([4000, 120, 15, 2], 0.01) | ||
nn.load(NEURAL_NETWORK_PATH) | ||
l.debug(f"Neural network: {nn}") | ||
|
||
for video in videos: | ||
l.info(f"Currently processing {video}") | ||
video_no_ext = io.remove_extension(video) | ||
video_clean_name = io.generate_clean_name(video_no_ext) | ||
l.debug(f"Clean name: {video_clean_name}") | ||
|
||
if not args.no_extract: | ||
io.generate_folder_clip(video_clean_name) | ||
images_path = vid.extract_frames_from_video(video) | ||
else: | ||
images_path = vid.get_saving_path(video_clean_name) | ||
|
||
if not args.no_segmentation: | ||
io.clean_cuts(video_clean_name) | ||
|
||
query_array = vid.get_query_array_from_video(nn, images_path) | ||
l.debug(query_array) | ||
kill_array = vid.get_kill_array_from_query_array(query_array) | ||
l.debug(kill_array) | ||
kill_array = vid.post_processing_kill_array(kill_array) | ||
l.debug(kill_array) | ||
vid.segment_video_with_kill_array(video, kill_array) | ||
|
||
if not args.no_merge: | ||
vid.merge_cuts() | ||
|
||
|
||
if __name__ == "__main__": | ||
l = logging.getLogger() | ||
|
||
print("Welcome to crispy!") | ||
|
||
l.info("Starting the program crispy") | ||
|
||
l.debug(f"Arguments: {args}") | ||
|
||
videos_path = ["4.mp4", "quadra chrlie mice.mp4"] | ||
|
||
# FIXME: should be sort with the frontend ? | ||
videos_path.sort() | ||
|
||
main(videos_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
import shutil | ||
|
||
from utils.constants import TMP_PATH, IMAGE, CUT | ||
|
||
|
||
def generate_tmp_folder(overwrite: bool) -> None: | ||
""" | ||
Generate the tmp directory | ||
""" | ||
if not os.path.exists(TMP_PATH): | ||
os.makedirs(TMP_PATH) | ||
elif overwrite: | ||
clear_directory(TMP_PATH) | ||
os.makedirs(TMP_PATH) | ||
|
||
|
||
def generate_folder_clip(name: str, overwrite: bool = True) -> None: | ||
""" | ||
Generate the folder clip | ||
Will generate: | ||
tmp/{name}/cut | ||
tmp/{name}/images | ||
""" | ||
path = os.path.join(TMP_PATH, name) | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
os.makedirs(os.path.join(path, CUT)) | ||
os.makedirs(os.path.join(path, IMAGE)) | ||
elif overwrite: | ||
clear_directory(path) | ||
generate_folder_clip(name) | ||
|
||
|
||
def clear_directory(path: str) -> None: | ||
""" | ||
Clear the given directory | ||
""" | ||
if os.path.exists(path): | ||
shutil.rmtree(path) | ||
|
||
|
||
def generate_clean_name(name: str) -> str: | ||
""" | ||
Generate the path from the name | ||
Remove the delim characters from the file name | ||
Add hash so (hello world) and (hello_world) are different | ||
""" | ||
|
||
def custom_hash(string: str) -> str: | ||
""" | ||
Generate a hash from the name, same for each session | ||
""" | ||
h = 0 | ||
for ch in string: | ||
h = (h * 281 ^ ord(ch) * 997) & 0xFFFFFFFF | ||
return str(h) | ||
|
||
init_name = name | ||
name = name.replace(" ", "__") | ||
name = name.replace("-", "__") | ||
name = name.replace("/", "__") | ||
name = name.replace("\\", "__") | ||
|
||
return name + "-" + custom_hash(init_name) | ||
|
||
|
||
def remove_extension(name: str) -> str: | ||
""" | ||
Remove the extension from the file name | ||
""" | ||
return name.split(".")[0] | ||
|
||
|
||
def clean_cuts(folder: str) -> None: | ||
""" | ||
Clean the cuts folder | ||
""" | ||
path = os.path.join(TMP_PATH, folder, CUT) | ||
if os.path.exists(path): | ||
shutil.rmtree(path) | ||
os.makedirs(path) |
Oops, something went wrong.