Skip to content

Commit

Permalink
fix: Fixed a bug on fake positives
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowtter committed Jul 17, 2022
1 parent 2afde5c commit e6137c7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 4 additions & 1 deletion backend/src/crispy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def main(videos: List[str]) -> None:
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()
Expand All @@ -50,7 +53,7 @@ def main(videos: List[str]) -> None:

l.debug(f"Arguments: {args}")

videos_path = ["4.mp4"]
videos_path = ["4.mp4", "quadra chrlie mice.mp4"]

# FIXME: should be sort with the frontend ?
videos_path.sort()
Expand Down
5 changes: 5 additions & 0 deletions backend/src/crispy/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
help="Do not extract frames",
action="store_true")

_parser.add_argument("--no-merge",
default=False,
help="Do not merge final videos",
action="store_true")

args = _parser.parse_args()

if args.debug:
Expand Down
21 changes: 21 additions & 0 deletions backend/src/crispy/utils/ffmpeg_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import random
import string
import shutil
from typing import Optional, Any, List, Tuple

import ffmpeg
Expand Down Expand Up @@ -148,3 +149,23 @@ def create_new_path(video_path: str) -> str:
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)
21 changes: 20 additions & 1 deletion backend/src/crispy/video/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,29 @@ def get_kill_array_from_query_array(

result = []
for kill in kill_array:
if len(kill) < framerate // 2:
# Remove fake-positives
if len(kill) <= 2:
continue

start = kill[0] - frames_before
end = kill[-1] + frames_after
result.append((start, end))
return result


def merge_cuts() -> None:
"""
Merge the cuts
"""
folders = os.listdir(TMP_PATH)
folders = [f for f in folders if os.path.isdir(os.path.join(TMP_PATH, f))]
folders.sort()
cuts: List[str] = []
for folder in folders:
cut = os.listdir(os.path.join(TMP_PATH, folder, CUT))
cut.sort()
for i in range(len(cut)):
cut[i] = os.path.join(TMP_PATH, folder, CUT, cut[i])
cuts.extend(cut)

ff.merge_videos(cuts, os.path.join(TMP_PATH, "merged.mp4"))

0 comments on commit e6137c7

Please sign in to comment.