-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b2ff7d
commit 61aac8c
Showing
8 changed files
with
137 additions
and
5 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 |
---|---|---|
|
@@ -14,4 +14,5 @@ | |
flagged/ | ||
datasets/ | ||
runs/ | ||
__pycache__/ | ||
__pycache__/ | ||
horus_prj-*/ |
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,23 @@ | ||
import gradio as gr | ||
from horus import video_processing | ||
|
||
|
||
with gr.Blocks() as main_ui: | ||
with gr.Tab("Upload Video to Database"): | ||
with gr.Row(): | ||
with gr.Column(): | ||
input_videos = gr.File(label="Upload Video", file_count="multiple", file_types=[".mp4", ".mov", ".mpg"]) | ||
input_project_name = gr.Text(label="Project Name") | ||
|
||
upload_button = gr.Button("Start Upload") | ||
with gr.Column(): | ||
output_status = gr.Text(label="Status") | ||
|
||
upload_button.click( | ||
video_processing.video_processing_ui, | ||
inputs=[input_videos, input_project_name], | ||
outputs=[output_status]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main_ui.queue().launch(server_name="0.0.0.0", server_port=7861) |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import uuid | ||
from datetime import datetime | ||
import yaml | ||
import os | ||
|
||
|
||
def make_project(project_name: str, project_host_dir="/workspace/horus_inference_server/projects"): | ||
project_id = str(uuid.uuid1())[0:11].replace("-", "") | ||
project_dir = os.path.join(project_host_dir, "horus_prj-" + project_id) | ||
os.makedirs(project_dir, exist_ok=True) | ||
|
||
project_description_file_path = os.path.join(project_dir, "horus.yaml") | ||
|
||
project_data = {} | ||
project_data["project_name"] = project_name | ||
project_data["create_date"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||
|
||
with open(project_description_file_path, 'w') as f: | ||
yaml.dump(project_data, f, default_flow_style=False, allow_unicode=True) | ||
|
||
print(f"プロジェクトファイルが作成されました: {project_description_file_path}") | ||
return project_dir |
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import os | ||
import subprocess | ||
import tempfile | ||
import cv2 | ||
from pathlib import Path | ||
from horus import util | ||
from horus import project_manager | ||
|
||
|
||
def make_video_list_file(video_files: list[str]): | ||
file_name = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name | ||
f = open(file_name, 'w') | ||
|
||
for video_file in video_files: | ||
p = Path(video_file) | ||
video_path = p.resolve() | ||
|
||
f.write(f"file '{video_path}'\n") | ||
|
||
return file_name | ||
|
||
|
||
def run_ffmpeg_concat_av1(input_list: str, output_file: str, preset="fast"): | ||
command = [ | ||
"ffmpeg", | ||
"-safe", "0", | ||
"-f", "concat", | ||
"-i", input_list, | ||
"-c:v", "av1_nvenc", | ||
"-preset", preset, | ||
"-b:v", "500k", | ||
output_file | ||
] | ||
|
||
try: | ||
result = subprocess.run(command, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
print("ffmpegコマンドの実行に成功しました。") | ||
print(result.stdout) | ||
except subprocess.CalledProcessError as e: | ||
print("ffmpegコマンドの実行中にエラーが発生しました。") | ||
print(e.stderr) | ||
|
||
|
||
def run_ffmpeg_timelaps_av1(input_file: str, output_file: str, max_time_sec: int): | ||
cap = cv2.VideoCapture(input_file) | ||
video_time_sec = cap.get(cv2.CAP_PROP_FRAME_COUNT) / cap.get(cv2.CAP_PROP_FPS) | ||
scale = video_time_sec / max_time_sec | ||
|
||
command = [ | ||
"ffmpeg", | ||
"-i", input_file, | ||
"-r", "30", | ||
"-c:v", "av1_nvenc", | ||
"-b:v", "500k", | ||
"-filter:v", f"setpts={(1.0 / scale)}*PTS", | ||
output_file | ||
] | ||
|
||
try: | ||
result = subprocess.run(command, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
print("ffmpegコマンドの実行に成功しました。") | ||
print(result.stdout) | ||
except subprocess.CalledProcessError as e: | ||
print("ffmpegコマンドの実行中にエラーが発生しました。") | ||
print(e.stderr) | ||
|
||
|
||
def video_processing_ui(video_files: list[str], project_name: str): | ||
project_dir = project_manager.make_project(project_name) | ||
|
||
video_files = util.natural_sort(video_files) | ||
video_list_path = make_video_list_file(video_files) | ||
merge_video_path = os.path.join(project_dir, "all_video_merge.webm") | ||
run_ffmpeg_concat_av1(video_list_path, merge_video_path) | ||
timelaps_video_path = os.path.join(project_dir, "timelaps.webm") | ||
run_ffmpeg_timelaps_av1(merge_video_path, timelaps_video_path, 15 * 60) | ||
|
||
return video_files | ||
|
Empty file.
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