Spaces:
Paused
Paused
Upload 2 files
Browse files
html.html
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Video Processing</title>
|
7 |
+
|
8 |
+
<!-- Add some basic styling for better visuals -->
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
background-color: #f3f3f3;
|
13 |
+
margin: 0;
|
14 |
+
padding: 0;
|
15 |
+
display: flex;
|
16 |
+
justify-content: center;
|
17 |
+
align-items: center;
|
18 |
+
height: 100vh;
|
19 |
+
}
|
20 |
+
|
21 |
+
h1 {
|
22 |
+
color: #333;
|
23 |
+
text-align: center;
|
24 |
+
}
|
25 |
+
|
26 |
+
.form-container {
|
27 |
+
background-color: #fff;
|
28 |
+
padding: 20px;
|
29 |
+
border-radius: 10px;
|
30 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
31 |
+
width: 300px;
|
32 |
+
}
|
33 |
+
|
34 |
+
label {
|
35 |
+
font-size: 16px;
|
36 |
+
margin-bottom: 5px;
|
37 |
+
color: #333;
|
38 |
+
}
|
39 |
+
|
40 |
+
input, select, button {
|
41 |
+
width: 100%;
|
42 |
+
padding: 10px;
|
43 |
+
margin: 10px 0;
|
44 |
+
border: 1px solid #ccc;
|
45 |
+
border-radius: 5px;
|
46 |
+
box-sizing: border-box;
|
47 |
+
}
|
48 |
+
|
49 |
+
input[type="file"] {
|
50 |
+
padding: 5px;
|
51 |
+
}
|
52 |
+
|
53 |
+
button {
|
54 |
+
background-color: #007BFF;
|
55 |
+
color: #fff;
|
56 |
+
border: none;
|
57 |
+
cursor: pointer;
|
58 |
+
font-size: 16px;
|
59 |
+
}
|
60 |
+
|
61 |
+
button:hover {
|
62 |
+
background-color: #0056b3;
|
63 |
+
}
|
64 |
+
|
65 |
+
.options-container {
|
66 |
+
margin-top: 10px;
|
67 |
+
padding-left: 15px;
|
68 |
+
}
|
69 |
+
|
70 |
+
.hidden {
|
71 |
+
display: none;
|
72 |
+
}
|
73 |
+
|
74 |
+
#copy-streams-container {
|
75 |
+
background-color: #f9f9f9;
|
76 |
+
padding: 10px;
|
77 |
+
border: 1px solid #ddd;
|
78 |
+
border-radius: 5px;
|
79 |
+
margin-top: 15px;
|
80 |
+
}
|
81 |
+
|
82 |
+
#copy-streams-container label {
|
83 |
+
font-size: 14px;
|
84 |
+
color: #555;
|
85 |
+
}
|
86 |
+
|
87 |
+
.form-container select,
|
88 |
+
.form-container input {
|
89 |
+
background-color: #f9f9f9;
|
90 |
+
}
|
91 |
+
</style>
|
92 |
+
</head>
|
93 |
+
<body>
|
94 |
+
<div class="form-container">
|
95 |
+
<h1>Video Processing</h1>
|
96 |
+
<form id="video-form" action="/process" method="POST" enctype="multipart/form-data">
|
97 |
+
<label for="video">Select Video:</label>
|
98 |
+
<input type="file" name="video" id="video" required><br><br>
|
99 |
+
|
100 |
+
<label for="action">Select Action:</label>
|
101 |
+
<select name="action" id="action" required>
|
102 |
+
<option value="Convert Format">Convert Format</option>
|
103 |
+
<option value="Trim Video">Trim Video</option>
|
104 |
+
<option value="Resize Video">Resize Video</option>
|
105 |
+
<option value="Extract Audio">Extract Audio</option>
|
106 |
+
<option value="Extract Frames">Extract Frames</option>
|
107 |
+
<option value="Change Video Speed">Change Video Speed</option>
|
108 |
+
</select><br><br>
|
109 |
+
|
110 |
+
<!-- Show Copy Streams checkbox only for Convert Format and Trim Video -->
|
111 |
+
<div id="copy-streams-container" class="hidden">
|
112 |
+
<label for="copy_streams">Copy Streams (No Re-encoding):</label>
|
113 |
+
<input type="checkbox" name="copy_streams" id="copy_streams"><br><br>
|
114 |
+
</div>
|
115 |
+
|
116 |
+
<!-- Inputs for Convert Format action -->
|
117 |
+
<div id="format-options" class="hidden options-container">
|
118 |
+
<label for="format">Select Output Format:</label>
|
119 |
+
<select name="format" id="format">
|
120 |
+
<option value="mp4">MP4</option>
|
121 |
+
<option value="avi">AVI</option>
|
122 |
+
<option value="mkv">MKV</option>
|
123 |
+
<option value="mov">MOV</option>
|
124 |
+
<option value="flv">FLV</option>
|
125 |
+
<option value="webm">WEBM</option>
|
126 |
+
</select><br><br>
|
127 |
+
</div>
|
128 |
+
|
129 |
+
<!-- Inputs for Trim Video action -->
|
130 |
+
<div id="trim-options" class="hidden options-container">
|
131 |
+
<label for="start_time">Start Time (for Trim Video):</label>
|
132 |
+
<input type="text" name="start_time" id="start_time"><br><br>
|
133 |
+
|
134 |
+
<label for="duration">Duration (for Trim Video):</label>
|
135 |
+
<input type="text" name="duration" id="duration"><br><br>
|
136 |
+
</div>
|
137 |
+
|
138 |
+
<!-- Inputs for Resize Video action -->
|
139 |
+
<div id="resize-options" class="hidden options-container">
|
140 |
+
<label for="width">Width (for Resize Video):</label>
|
141 |
+
<input type="text" name="width" id="width"><br><br>
|
142 |
+
|
143 |
+
<label for="height">Height (for Resize Video):</label>
|
144 |
+
<input type="text" name="height" id="height"><br><br>
|
145 |
+
</div>
|
146 |
+
|
147 |
+
<!-- Inputs for Change Video Speed action -->
|
148 |
+
<div id="speed-options" class="hidden options-container">
|
149 |
+
<label for="speed_factor">Speed Factor (for Change Video Speed):</label>
|
150 |
+
<input type="text" name="speed_factor" id="speed_factor"><br><br>
|
151 |
+
</div>
|
152 |
+
|
153 |
+
<button type="submit">Submit</button>
|
154 |
+
</form>
|
155 |
+
</div>
|
156 |
+
|
157 |
+
<script>
|
158 |
+
// Show or hide the corresponding inputs based on selected action
|
159 |
+
document.getElementById('action').addEventListener('change', function() {
|
160 |
+
const action = this.value;
|
161 |
+
const copyStreamsContainer = document.getElementById('copy-streams-container');
|
162 |
+
const formatOptions = document.getElementById('format-options');
|
163 |
+
const trimOptions = document.getElementById('trim-options');
|
164 |
+
const resizeOptions = document.getElementById('resize-options');
|
165 |
+
const speedOptions = document.getElementById('speed-options');
|
166 |
+
|
167 |
+
// Hide all extra options initially
|
168 |
+
formatOptions.classList.add('hidden');
|
169 |
+
trimOptions.classList.add('hidden');
|
170 |
+
resizeOptions.classList.add('hidden');
|
171 |
+
speedOptions.classList.add('hidden');
|
172 |
+
copyStreamsContainer.classList.add('hidden');
|
173 |
+
|
174 |
+
// Show options based on selected action
|
175 |
+
if (action === 'Trim Video') {
|
176 |
+
trimOptions.classList.remove('hidden');
|
177 |
+
copyStreamsContainer.classList.remove('hidden'); // Show the copy streams option for Trim Video
|
178 |
+
} else if (action === 'Resize Video') {
|
179 |
+
resizeOptions.classList.remove('hidden');
|
180 |
+
} else if (action === 'Change Video Speed') {
|
181 |
+
speedOptions.classList.remove('hidden');
|
182 |
+
} else if (action === 'Convert Format') {
|
183 |
+
formatOptions.classList.remove('hidden'); // Show the format selection for Convert Format
|
184 |
+
copyStreamsContainer.classList.remove('hidden'); // Show the copy streams option for Convert Format
|
185 |
+
}
|
186 |
+
});
|
187 |
+
|
188 |
+
// Trigger the change event to set initial visibility based on the default selection
|
189 |
+
document.getElementById('action').dispatchEvent(new Event('change'));
|
190 |
+
</script>
|
191 |
+
</body>
|
192 |
+
</html>
|
python.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, send_file
|
2 |
+
import os
|
3 |
+
import tempfile
|
4 |
+
import subprocess
|
5 |
+
import zipfile
|
6 |
+
|
7 |
+
# Initialize the Flask app, tell it to look in the current directory for templates
|
8 |
+
app = Flask(__name__, template_folder='.')
|
9 |
+
|
10 |
+
@app.route('/')
|
11 |
+
def home():
|
12 |
+
return render_template('html.html') # Flask will look in the current directory
|
13 |
+
|
14 |
+
@app.route('/process', methods=['POST'])
|
15 |
+
def process_video():
|
16 |
+
video_file = request.files['video']
|
17 |
+
action = request.form['action']
|
18 |
+
copy_streams = 'copy_streams' in request.form # Check if the user selected "copy streams"
|
19 |
+
|
20 |
+
# Save the uploaded video to a temporary file
|
21 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
22 |
+
video_file.save(temp_file.name)
|
23 |
+
|
24 |
+
output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name # Default output format
|
25 |
+
|
26 |
+
# Process video based on action
|
27 |
+
if action == 'Convert Format':
|
28 |
+
selected_format = request.form['format']
|
29 |
+
output_path = tempfile.NamedTemporaryFile(delete=False, suffix=f'.{selected_format}').name # Adjust output format based on user selection
|
30 |
+
|
31 |
+
if copy_streams:
|
32 |
+
# If "copy streams" is selected, try to copy streams without re-encoding
|
33 |
+
result = subprocess.run(['ffmpeg', '-i', temp_file.name, '-c:v', 'copy', '-c:a', 'copy', '-y', output_path], capture_output=True)
|
34 |
+
if result.returncode != 0:
|
35 |
+
# If copying the streams failed, re-encode the video
|
36 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-y', output_path])
|
37 |
+
else:
|
38 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-y', output_path])
|
39 |
+
elif action == 'Trim Video':
|
40 |
+
start_time = request.form['start_time']
|
41 |
+
duration = request.form['duration']
|
42 |
+
output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name # Example output format
|
43 |
+
|
44 |
+
if copy_streams:
|
45 |
+
# Try to copy streams during trim operation (if selected)
|
46 |
+
result = subprocess.run(['ffmpeg', '-i', temp_file.name, '-ss', start_time, '-t', duration, '-c:v', 'copy', '-c:a', 'copy', '-y', output_path], capture_output=True)
|
47 |
+
if result.returncode != 0:
|
48 |
+
# If copying the streams failed, re-encode the video
|
49 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-ss', start_time, '-t', duration, '-y', output_path])
|
50 |
+
else:
|
51 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-ss', start_time, '-t', duration, '-y', output_path])
|
52 |
+
elif action == 'Resize Video':
|
53 |
+
width = request.form['width']
|
54 |
+
height = request.form['height']
|
55 |
+
output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name # Example output format
|
56 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-vf', f'scale={width}:{height}', '-y', output_path])
|
57 |
+
elif action == 'Extract Audio':
|
58 |
+
output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3').name # Output audio in MP3 format
|
59 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-vn', '-acodec', 'mp3', '-y', output_path])
|
60 |
+
elif action == 'Extract Frames':
|
61 |
+
# Extract frames and save as .jpg files
|
62 |
+
frame_dir = tempfile.mkdtemp() # Create a temporary directory to store frames
|
63 |
+
output_zip = tempfile.NamedTemporaryFile(delete=False, suffix='.zip').name # Output ZIP file
|
64 |
+
|
65 |
+
# Extract frames from the video (saving as JPG files)
|
66 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-an', f'{frame_dir}/frame_%04d.jpg', '-y'])
|
67 |
+
|
68 |
+
# Create a ZIP file containing the frames
|
69 |
+
with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
70 |
+
for frame in os.listdir(frame_dir):
|
71 |
+
if frame.endswith('.jpg'):
|
72 |
+
zipf.write(os.path.join(frame_dir, frame), frame) # Write each frame into the ZIP
|
73 |
+
|
74 |
+
# Clean up the extracted frames directory
|
75 |
+
for frame in os.listdir(frame_dir):
|
76 |
+
os.remove(os.path.join(frame_dir, frame))
|
77 |
+
os.rmdir(frame_dir)
|
78 |
+
|
79 |
+
# Send the ZIP file containing the frames
|
80 |
+
return send_file(output_zip, as_attachment=True, mimetype='application/zip')
|
81 |
+
elif action == 'Change Video Speed':
|
82 |
+
speed_factor = request.form['speed_factor']
|
83 |
+
output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name # Example output format
|
84 |
+
subprocess.run(['ffmpeg', '-i', temp_file.name, '-filter:v', f'setpts={1/speed_factor}*PTS', '-y', output_path])
|
85 |
+
|
86 |
+
# Send the processed file back as a download (if applicable)
|
87 |
+
if os.path.exists(output_path):
|
88 |
+
return send_file(output_path, as_attachment=True)
|
89 |
+
|
90 |
+
return 'Error processing video', 500
|
91 |
+
|
92 |
+
if __name__ == '__main__':
|
93 |
+
app.run(debug=True)
|