factblink514 commited on
Commit
76e8731
·
verified ·
1 Parent(s): 81c9a1a

Upload 2 files

Browse files
Files changed (2) hide show
  1. processor.py +62 -0
  2. requirements.txt +1 -0
processor.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import random
4
+
5
+ def process_video(input_path, output_path, duration=None):
6
+ # Get input video resolution
7
+ cmd_info = f"ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 \"{input_path}\""
8
+ res = subprocess.check_output(cmd_info, shell=True).decode().strip()
9
+ width, height = map(int, res.split('x'))
10
+
11
+ # Calculate perspective coordinates
12
+ x0, y0 = int(width * 0.05), int(height * 0.05)
13
+ x1, y1 = int(width * 0.95), int(height * 0.02)
14
+ x2, y2 = int(width * 1.0), int(height * 0.95)
15
+ x3, y3 = int(width * 0.0), int(height * 1.0)
16
+
17
+ perspective = f"perspective=x0={x0}:y0={y0}:x1={x1}:y1={y1}:x2={x2}:y2={y2}:x3={x3}:y3={y3}"
18
+ shake = "crop=iw*0.95:ih*0.95:iw*0.025+iw*0.01*sin(2*t):ih*0.025+ih*0.01*cos(2.3*t)"
19
+ color = "eq=saturation=0.8:contrast=0.9:brightness=-0.05"
20
+ vignette = "vignette=angle=PI/4"
21
+ noise = "noise=alls=10:allf=t+u"
22
+
23
+ # Audio: Reverb + Lowpass + Noise
24
+ # Using 'amplitude' instead of 'amp' for anoisesrc
25
+ audio_filter = (
26
+ "[0:a]aecho=0.8:0.8:40:0.3,lowpass=f=3000[reverb];"
27
+ "anoisesrc=d=3600:c=white:amplitude=0.01,lowpass=f=1000,highpass=f=100[bgnoise];"
28
+ "[reverb][bgnoise]amix=inputs=2:duration=first[aout]"
29
+ )
30
+
31
+ video_filter = f"{perspective},{color},{vignette},{noise},{shake},pad=iw*1.2:ih*1.2:(ow-iw)/2:(oh-ih)/2:black"
32
+
33
+ command = [
34
+ "ffmpeg", "-y"
35
+ ]
36
+
37
+ if duration:
38
+ command.extend(["-t", str(duration)])
39
+
40
+ command.extend([
41
+ "-i", input_path,
42
+ "-filter_complex", f"[0:v]{video_filter}[vout];{audio_filter}",
43
+ "-map", "[vout]",
44
+ "-map", "[aout]",
45
+ "-c:v", "libx264",
46
+ "-preset", "ultrafast",
47
+ "-crf", "28",
48
+ "-c:a", "aac",
49
+ "-b:a", "128k",
50
+ output_path
51
+ ])
52
+
53
+ print(f"Running command: {' '.join(command)}")
54
+ subprocess.run(command, check=True)
55
+
56
+ if __name__ == "__main__":
57
+ import sys
58
+ if len(sys.argv) < 3:
59
+ print("Usage: python processor.py input.mp4 output.mp4 [duration]")
60
+ else:
61
+ dur = sys.argv[3] if len(sys.argv) > 3 else None
62
+ process_video(sys.argv[1], sys.argv[2], dur)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio