userIdc2024 commited on
Commit
3ce0520
·
verified ·
1 Parent(s): c68389c

Update generator_function/video_hashid_function.py

Browse files
generator_function/video_hashid_function.py CHANGED
@@ -73,7 +73,9 @@ def augment_video_random(
73
  output_path: Optional[str] = None,
74
  crf: int = 20,
75
  preset: str = "medium",
76
- variation_idx: int = 0
 
 
77
  ) -> str:
78
  import random
79
  k_b = random.randint(3, 3)
@@ -85,6 +87,11 @@ def augment_video_random(
85
 
86
  vf = f"hue=h={hue_rad:.6f}:s={sat_scale:.4f},eq=contrast={contrast:.4f}:brightness={brightness:.4f}"
87
 
 
 
 
 
 
88
  inp = Path(input_path)
89
  suffix = f"_augmented_{variation_idx}" if variation_idx > 0 else "_augmented"
90
  out = Path(output_path) / f"{inp.stem}{suffix}.mp4" if output_path else inp.with_name(f"{inp.stem}{suffix}.mp4")
@@ -121,12 +128,24 @@ def upload_video_to_r2(video_bytes: bytes, file_name: str) -> str:
121
  return f"{_public_base_url()}/{key}"
122
 
123
  # ---------- PROCESS + UPLOAD ----------
124
- def process_video_with_hash_info(input_path: str, output_path: Optional[str] = None, variation_idx: int = 0) -> dict:
 
 
 
 
 
 
125
  in_sha = _sha256(Path(input_path))
126
  in_id = _hashid_short(in_sha)
127
 
128
  # Augment and get output
129
- out_path = augment_video_random(input_path=input_path, output_path=output_path, variation_idx=variation_idx)
 
 
 
 
 
 
130
 
131
  # output hashid
132
  out_sha = _sha256(Path(out_path))
 
73
  output_path: Optional[str] = None,
74
  crf: int = 20,
75
  preset: str = "medium",
76
+ variation_idx: int = 0,
77
+ border_width: int = 0,
78
+ border_color: str = "black",
79
  ) -> str:
80
  import random
81
  k_b = random.randint(3, 3)
 
87
 
88
  vf = f"hue=h={hue_rad:.6f}:s={sat_scale:.4f},eq=contrast={contrast:.4f}:brightness={brightness:.4f}"
89
 
90
+ if border_width > 0:
91
+ ffmpeg_color = border_color.replace("#", "0x") if border_color.startswith("#") else border_color
92
+ bw = int(border_width)
93
+ vf += f",pad=iw+{bw*2}:ih+{bw*2}:{bw}:{bw}:{ffmpeg_color}"
94
+
95
  inp = Path(input_path)
96
  suffix = f"_augmented_{variation_idx}" if variation_idx > 0 else "_augmented"
97
  out = Path(output_path) / f"{inp.stem}{suffix}.mp4" if output_path else inp.with_name(f"{inp.stem}{suffix}.mp4")
 
128
  return f"{_public_base_url()}/{key}"
129
 
130
  # ---------- PROCESS + UPLOAD ----------
131
+ def process_video_with_hash_info(
132
+ input_path: str,
133
+ output_path: Optional[str] = None,
134
+ variation_idx: int = 0,
135
+ border_width: int = 0,
136
+ border_color: str = "black",
137
+ ) -> dict:
138
  in_sha = _sha256(Path(input_path))
139
  in_id = _hashid_short(in_sha)
140
 
141
  # Augment and get output
142
+ out_path = augment_video_random(
143
+ input_path=input_path,
144
+ output_path=output_path,
145
+ variation_idx=variation_idx,
146
+ border_width=border_width,
147
+ border_color=border_color,
148
+ )
149
 
150
  # output hashid
151
  out_sha = _sha256(Path(out_path))