Stylique commited on
Commit
bfbb2bb
·
verified ·
1 Parent(s): 129f732

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -116,18 +116,27 @@ def background_process(job_id: str, req: ProcessRequest):
116
  processed_slices = []
117
  total_segments = len(segments)
118
 
119
- BUFFER_START = 0.1
120
- BUFFER_END = 0.5
 
121
 
122
  for i, segment in enumerate(segments):
123
  orig_start = segment.start
124
  orig_end = segment.end
125
- start = max(0, orig_start - BUFFER_START)
126
- end = orig_end + BUFFER_END
 
 
 
 
 
 
 
 
127
  text = segment.text.strip()
128
  duration = end - start
129
 
130
- if duration < 0.5: continue
131
 
132
  step_progress = 40 + int((i / total_segments) * 50)
133
  jobs[job_id].update({"progress": step_progress, "message": f"Slicing segment {i+1}/{total_segments}..."})
@@ -136,6 +145,7 @@ def background_process(job_id: str, req: ProcessRequest):
136
  output_path = temp_dir / output_filename
137
 
138
  try:
 
139
  subprocess.run([
140
  "ffmpeg", "-ss", str(start), "-i", str(video_path), "-t", str(duration), "-y",
141
  "-c:v", "libx264", "-preset", "ultrafast", "-crf", "28",
 
116
  processed_slices = []
117
  total_segments = len(segments)
118
 
119
+ # Reduced buffers to avoid repetition while maintaining clean cuts
120
+ BUFFER_START = 0.05
121
+ BUFFER_END = 0.2
122
 
123
  for i, segment in enumerate(segments):
124
  orig_start = segment.start
125
  orig_end = segment.end
126
+
127
+ # Lookahead to avoid overlapping with next segment
128
+ next_start = segments[i+1].start if i + 1 < total_segments else float('inf')
129
+ # Lookbehind to avoid overlapping with previous segment
130
+ prev_end = segments[i-1].end if i > 0 else 0
131
+
132
+ # Apply padding but stay within boundaries of adjacent segments
133
+ start = max(prev_end, orig_start - BUFFER_START)
134
+ end = min(next_start, orig_end + BUFFER_END)
135
+
136
  text = segment.text.strip()
137
  duration = end - start
138
 
139
+ if duration < 0.2: continue
140
 
141
  step_progress = 40 + int((i / total_segments) * 50)
142
  jobs[job_id].update({"progress": step_progress, "message": f"Slicing segment {i+1}/{total_segments}..."})
 
145
  output_path = temp_dir / output_filename
146
 
147
  try:
148
+ # Precise Slicing
149
  subprocess.run([
150
  "ffmpeg", "-ss", str(start), "-i", str(video_path), "-t", str(duration), "-y",
151
  "-c:v", "libx264", "-preset", "ultrafast", "-crf", "28",