Spaces:
Running
Running
Update generator_function/video_hashid_function.py
Browse files
generator_function/video_hashid_function.py
CHANGED
|
@@ -67,9 +67,11 @@ def augment_video_random(
|
|
| 67 |
output_path: Optional[str] = None,
|
| 68 |
crf: int = 20,
|
| 69 |
preset: str = "medium",
|
|
|
|
| 70 |
) -> str:
|
| 71 |
import random
|
| 72 |
-
k_b
|
|
|
|
| 73 |
brightness = max(-1.0, min(1.0, k_b * 0.05))
|
| 74 |
contrast = max(0.0, min(2.0, 1.0 + k_c * 0.05))
|
| 75 |
hue_rad = math.radians(k_h * 5.0)
|
|
@@ -78,7 +80,8 @@ def augment_video_random(
|
|
| 78 |
vf = f"hue=h={hue_rad:.6f}:s={sat_scale:.4f},eq=contrast={contrast:.4f}:brightness={brightness:.4f}"
|
| 79 |
|
| 80 |
inp = Path(input_path)
|
| 81 |
-
|
|
|
|
| 82 |
|
| 83 |
cmd = [
|
| 84 |
"ffmpeg", "-nostdin", "-y",
|
|
@@ -112,12 +115,12 @@ def upload_video_to_r2(video_bytes: bytes, file_name: str) -> str:
|
|
| 112 |
return f"{os.getenv('NEW_BASE').rstrip('/')}/{key}"
|
| 113 |
|
| 114 |
# ---------- PROCESS + UPLOAD ----------
|
| 115 |
-
def process_video_with_hash_info(input_path: str, output_path: Optional[str] = None) -> dict:
|
| 116 |
in_sha = _sha256(Path(input_path))
|
| 117 |
in_id = _hashid_short(in_sha)
|
| 118 |
|
| 119 |
# Augment and get output
|
| 120 |
-
out_path = augment_video_random(input_path=input_path, output_path=output_path)
|
| 121 |
|
| 122 |
# output hashid
|
| 123 |
out_sha = _sha256(Path(out_path))
|
|
|
|
| 67 |
output_path: Optional[str] = None,
|
| 68 |
crf: int = 20,
|
| 69 |
preset: str = "medium",
|
| 70 |
+
variation_idx: int = 0
|
| 71 |
) -> str:
|
| 72 |
import random
|
| 73 |
+
k_b = random.randint(3, 3)
|
| 74 |
+
k_c, k_h, k_s = [random.randint(-3, 3) for _ in range(3)]
|
| 75 |
brightness = max(-1.0, min(1.0, k_b * 0.05))
|
| 76 |
contrast = max(0.0, min(2.0, 1.0 + k_c * 0.05))
|
| 77 |
hue_rad = math.radians(k_h * 5.0)
|
|
|
|
| 80 |
vf = f"hue=h={hue_rad:.6f}:s={sat_scale:.4f},eq=contrast={contrast:.4f}:brightness={brightness:.4f}"
|
| 81 |
|
| 82 |
inp = Path(input_path)
|
| 83 |
+
suffix = f"_augmented_{variation_idx}" if variation_idx > 0 else "_augmented"
|
| 84 |
+
out = Path(output_path) / f"{inp.stem}{suffix}.mp4" if output_path else inp.with_name(f"{inp.stem}{suffix}.mp4")
|
| 85 |
|
| 86 |
cmd = [
|
| 87 |
"ffmpeg", "-nostdin", "-y",
|
|
|
|
| 115 |
return f"{os.getenv('NEW_BASE').rstrip('/')}/{key}"
|
| 116 |
|
| 117 |
# ---------- PROCESS + UPLOAD ----------
|
| 118 |
+
def process_video_with_hash_info(input_path: str, output_path: Optional[str] = None, variation_idx: int = 0) -> dict:
|
| 119 |
in_sha = _sha256(Path(input_path))
|
| 120 |
in_id = _hashid_short(in_sha)
|
| 121 |
|
| 122 |
# Augment and get output
|
| 123 |
+
out_path = augment_video_random(input_path=input_path, output_path=output_path, variation_idx=variation_idx)
|
| 124 |
|
| 125 |
# output hashid
|
| 126 |
out_sha = _sha256(Path(out_path))
|