raju014 commited on
Commit
d6f7849
Β·
verified Β·
1 Parent(s): 0f8f338

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +24 -20
  2. app.py +182 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,31 +1,35 @@
1
  ---
2
- title: Cobalt API
3
  emoji: 🎬
4
  colorFrom: blue
5
  colorTo: purple
6
- sdk: docker
 
 
7
  pinned: false
8
- license: mit
9
  ---
10
 
11
- # Cobalt API - YouTube Video Downloader
12
 
13
- This is a self-hosted Cobalt API instance for downloading YouTube videos with Hindi audio.
 
 
 
 
14
 
15
- ## API Endpoint
 
 
 
16
 
17
- POST to `/` with JSON body:
 
 
 
 
 
18
 
19
- ```json
20
- {
21
- "url": "https://youtube.com/watch?v=VIDEO_ID",
22
- "youtubeDubLang": "hi"
23
- }
24
- ```
25
-
26
- ## Features
27
-
28
- - Free to use
29
- - No authentication required
30
- - Hindi dubbed audio support
31
- - 1080p video quality
 
1
  ---
2
+ title: Video Upscaler 4K
3
  emoji: 🎬
4
  colorFrom: blue
5
  colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 4.44.0
8
+ app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
+ # 🎬 Video Upscaler to Ultra HD (4K)
13
 
14
+ Upload any video and upscale it to:
15
+ - 720p (HD)
16
+ - 1080p (Full HD)
17
+ - 1440p (2K)
18
+ - 2160p (4K Ultra HD)
19
 
20
+ ## Features:
21
+ - High-quality **Lanczos scaling** algorithm
22
+ - Multiple quality presets (Fast, Balanced, Best)
23
+ - CPU-optimized (works on free HuggingFace Spaces)
24
 
25
+ ## Usage:
26
+ 1. Upload your video
27
+ 2. Select target resolution
28
+ 3. Choose quality preset
29
+ 4. Click "Upscale Video"
30
+ 5. Download the result!
31
 
32
+ ## Technical Details:
33
+ - Uses FFmpeg with lanczos filter for best upscaling quality
34
+ - x264 encoder with configurable CRF
35
+ - Audio preserved at 192kbps AAC
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Video Upscaler - HuggingFace Spaces
3
+ Upscale videos to Ultra HD (4K) using FFmpeg with high-quality lanczos scaling.
4
+ Optimized for CPU-only environments (2 CPU, 16GB RAM).
5
+ """
6
+
7
+ import gradio as gr
8
+ import subprocess
9
+ import os
10
+ import tempfile
11
+ import shutil
12
+
13
+ # Upscale resolutions
14
+ RESOLUTIONS = {
15
+ "720p (HD)": "1280:720",
16
+ "1080p (Full HD)": "1920:1080",
17
+ "1440p (2K)": "2560:1440",
18
+ "2160p (4K Ultra HD)": "3840:2160",
19
+ }
20
+
21
+ def get_video_info(input_path):
22
+ """Get video duration and resolution using ffprobe."""
23
+ cmd = [
24
+ 'ffprobe', '-v', 'error',
25
+ '-select_streams', 'v:0',
26
+ '-show_entries', 'stream=width,height,duration',
27
+ '-show_entries', 'format=duration',
28
+ '-of', 'csv=p=0',
29
+ input_path
30
+ ]
31
+ try:
32
+ result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
33
+ output = result.stdout.strip().split('\n')
34
+ # Parse width, height
35
+ if output and ',' in output[0]:
36
+ parts = output[0].split(',')
37
+ width, height = int(parts[0]), int(parts[1])
38
+ return width, height
39
+ except:
40
+ pass
41
+ return None, None
42
+
43
+ def upscale_video(input_video, target_resolution, quality_preset):
44
+ """
45
+ Upscale video to target resolution using FFmpeg.
46
+
47
+ Args:
48
+ input_video: Path to input video file
49
+ target_resolution: Target resolution string (e.g., "3840:2160")
50
+ quality_preset: Encoding quality preset
51
+
52
+ Returns:
53
+ Path to upscaled video
54
+ """
55
+ if input_video is None:
56
+ return None, "❌ Please upload a video first!"
57
+
58
+ # Get target dimensions
59
+ target_dims = RESOLUTIONS.get(target_resolution, "3840:2160")
60
+ target_width, target_height = map(int, target_dims.split(':'))
61
+
62
+ # Get input video info
63
+ input_width, input_height = get_video_info(input_video)
64
+
65
+ if input_width and input_height:
66
+ if input_width >= target_width and input_height >= target_height:
67
+ return None, f"⚠️ Video already {input_width}x{input_height}. No upscaling needed!"
68
+
69
+ # Create output path
70
+ output_dir = tempfile.mkdtemp()
71
+ output_path = os.path.join(output_dir, "upscaled_video.mp4")
72
+
73
+ # Quality settings based on preset
74
+ quality_settings = {
75
+ "Fast (Lower Quality)": ["-crf", "23", "-preset", "fast"],
76
+ "Balanced": ["-crf", "18", "-preset", "medium"],
77
+ "Best Quality (Slow)": ["-crf", "15", "-preset", "slow"],
78
+ }
79
+
80
+ crf_preset = quality_settings.get(quality_preset, quality_settings["Balanced"])
81
+
82
+ # FFmpeg command for high-quality upscaling
83
+ cmd = [
84
+ 'ffmpeg', '-y',
85
+ '-i', input_video,
86
+ # Video scaling with lanczos (highest quality scaling algorithm)
87
+ '-vf', f'scale={target_width}:{target_height}:flags=lanczos',
88
+ # Video codec settings
89
+ '-c:v', 'libx264',
90
+ *crf_preset,
91
+ # Audio copy (no re-encoding)
92
+ '-c:a', 'aac', '-b:a', '192k',
93
+ # Output format
94
+ '-movflags', '+faststart',
95
+ output_path
96
+ ]
97
+
98
+ try:
99
+ # Run FFmpeg
100
+ process = subprocess.Popen(
101
+ cmd,
102
+ stdout=subprocess.PIPE,
103
+ stderr=subprocess.PIPE,
104
+ text=True
105
+ )
106
+
107
+ stdout, stderr = process.communicate(timeout=3600) # 1 hour timeout
108
+
109
+ if process.returncode == 0 and os.path.exists(output_path):
110
+ file_size_mb = os.path.getsize(output_path) / (1024 * 1024)
111
+ status = f"βœ… Success! Upscaled to {target_width}x{target_height}\nπŸ“ File size: {file_size_mb:.1f} MB"
112
+ return output_path, status
113
+ else:
114
+ return None, f"❌ FFmpeg error:\n{stderr[-500:]}"
115
+
116
+ except subprocess.TimeoutExpired:
117
+ process.kill()
118
+ return None, "❌ Process timed out (>1 hour). Try a shorter video."
119
+ except Exception as e:
120
+ return None, f"❌ Error: {str(e)}"
121
+
122
+ def create_interface():
123
+ """Create Gradio interface."""
124
+
125
+ with gr.Blocks(title="🎬 Video Upscaler", theme=gr.themes.Soft()) as app:
126
+ gr.Markdown("""
127
+ # 🎬 Video Upscaler to Ultra HD (4K)
128
+
129
+ Upload a video and upscale it to higher resolution using high-quality lanczos scaling.
130
+
131
+ **Supported:** MP4, MKV, AVI, MOV, WEBM
132
+
133
+ **Note:** Processing time depends on video length. ~2-5 minutes per minute of video.
134
+ """)
135
+
136
+ with gr.Row():
137
+ with gr.Column(scale=1):
138
+ input_video = gr.Video(label="πŸ“€ Upload Video")
139
+
140
+ target_res = gr.Dropdown(
141
+ choices=list(RESOLUTIONS.keys()),
142
+ value="2160p (4K Ultra HD)",
143
+ label="🎯 Target Resolution"
144
+ )
145
+
146
+ quality = gr.Dropdown(
147
+ choices=["Fast (Lower Quality)", "Balanced", "Best Quality (Slow)"],
148
+ value="Balanced",
149
+ label="βš™οΈ Quality Preset"
150
+ )
151
+
152
+ upscale_btn = gr.Button("πŸš€ Upscale Video", variant="primary", size="lg")
153
+
154
+ with gr.Column(scale=1):
155
+ output_video = gr.Video(label="πŸ“₯ Upscaled Video")
156
+ status_text = gr.Textbox(label="πŸ“Š Status", lines=3)
157
+
158
+ gr.Markdown("""
159
+ ---
160
+ ### πŸ’‘ Tips:
161
+ - **4K (2160p)**: Best for large screens, 4x resolution of 1080p
162
+ - **2K (1440p)**: Good balance of quality and file size
163
+ - **Best Quality (Slow)**: Use CRF 15, takes longer but looks amazing
164
+ - For very long videos, consider processing in parts
165
+
166
+ ---
167
+ *Powered by FFmpeg with Lanczos scaling algorithm*
168
+ """)
169
+
170
+ # Event handlers
171
+ upscale_btn.click(
172
+ fn=upscale_video,
173
+ inputs=[input_video, target_res, quality],
174
+ outputs=[output_video, status_text]
175
+ )
176
+
177
+ return app
178
+
179
+ # Launch the app
180
+ if __name__ == "__main__":
181
+ app = create_interface()
182
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio>=4.0.0
2
+ ffmpeg-python