From 34fbbdb1c4efb8c9e145bc841f7bc83280e23426 Mon Sep 17 00:00:00 2001 From: I K Kevin Samuels <153888213+Kevin0Samuels@users.noreply.github.com> Date: Sat, 22 Feb 2025 03:14:09 +0530 Subject: [PATCH] 112_CutZero_FrameHackers --- CutZero.py | 341 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 341 insertions(+) create mode 100644 CutZero.py diff --git a/CutZero.py b/CutZero.py new file mode 100644 index 00000000..eefd17ff --- /dev/null +++ b/CutZero.py @@ -0,0 +1,341 @@ +import streamlit as st +import os +import tempfile +from moviepy.editor import VideoFileClip, concatenate_videoclips +import numpy as np + +st.markdown(""" + +""", unsafe_allow_html=True) + +def process_video(input_path, threshold, progress_callback): + try: + progress_callback(10, "Loading video...") + video = VideoFileClip(input_path) + + progress_callback(20, "Analyzing audio...") + audio_chunks = [] + duration = video.duration + chunk_duration = 0.1 + + chunk_count = int(duration / chunk_duration) + for i, t in enumerate(np.arange(0, duration, chunk_duration)): + end_t = min(t + chunk_duration, duration) + chunk = video.subclip(t, end_t).audio + if chunk is not None: + audio_chunks.append((t, np.sqrt(np.mean(chunk.to_soundarray()**2)))) + progress = 20 + int((i / chunk_count) * 30) + progress_callback(progress, "Analyzing audio...") + + progress_callback(50, "Detecting silent parts...") + nonsilent_chunks = [t for t, volume in audio_chunks if volume > threshold] + + if not nonsilent_chunks: + raise Exception("No non-silent parts found!") + + progress_callback(60, "Creating clips...") + clips = [] + start_time = nonsilent_chunks[0] + prev_time = start_time + + for t in nonsilent_chunks[1:]: + if t - prev_time > chunk_duration * 1.5: + clips.append(video.subclip( + max(0, start_time - chunk_duration), + min(duration, prev_time + chunk_duration) + )) + start_time = t + prev_time = t + + clips.append(video.subclip( + max(0, start_time - chunk_duration), + min(duration, prev_time + chunk_duration) + )) + + progress_callback(80, "Combining clips...") + final_video = concatenate_videoclips(clips) + + output_path = os.path.splitext(input_path)[0] + "_processed.mp4" + final_video.write_videofile( + output_path, + codec='libx264', + audio_codec='aac', + logger=None + ) + + video.close() + final_video.close() + return output_path + + except Exception as e: + raise e + +def main(): + + logo_url = "https://blogger.googleusercontent.com/img/a/AVvXsEhDHXYq6vkcAo6H22qQ-8_M6btXkRpih6Kb9W0f4a_0KBnP5OEhvXGeLN6B0rv25qrv-ytHmEJgQ7M_wnAmTDMSJlqVIsVWbeShlcI7cz8IUeJuKswge7IzkUkTYUyOK5QQonDxrBri2Q-M5mGV7FpjmwbKP1vcReJT8RrmUPFSwQwcr33Y_DT6Z_GKh4Q" + + col1, col2 = st.columns([4, 1]) + + with col1: + st.title("CutZero - Your Video Editing Assistant") + + with col2: + st.image(logo_url, use_container_width=True, caption="", width=100) + + + st.markdown(""" +

+ Upload your video and let our AI-powered system remove blank and silent frames in seconds. +

+ """, unsafe_allow_html=True) + + uploaded_file = st.file_uploader("Select video file", + type=["mp4", "avi", "mov", "mkv"], + accept_multiple_files=False) + + threshold = st.slider("Silence Threshold", + min_value=0.001, + max_value=0.2, + value=0.041, + step=0.001, + format="%.3f") + + if uploaded_file is not None: + if st.button("Process Video"): + progress_bar = st.progress(0) + status_text = st.empty() + + def update_progress(progress, message): + progress_bar.progress(progress) + status_text.markdown(f"**Status:** {message}") + + with tempfile.TemporaryDirectory() as tmp_dir: + input_path = os.path.join(tmp_dir, uploaded_file.name) + with open(input_path, "wb") as f: + f.write(uploaded_file.getbuffer()) + + try: + output_path = process_video(input_path, threshold, update_progress) + + st.markdown("---") + st.subheader("Your Processed Video is Ready!") + with open(output_path, "rb") as f: + st.download_button( + label="Download Edited Video", + data=f, + file_name=os.path.basename(output_path), + mime="video/mp4" + ) + + except Exception as e: + st.error(f"Error processing video: {str(e)}") + + st.markdown("---") + st.subheader("Smart Video Processing Features") + + col1, col2, col3 = st.columns(3) + with col1: + st.markdown(""" +
+

AI-Powered Silence Detection

+

Advanced algorithms identify and remove silent intervals with perfect accuracy

+
+ """, unsafe_allow_html=True) + + with col2: + st.markdown(""" +
+

Multi-Format Support

+

Works with MP4, MOV, AVI, and other popular video formats

+
+ """, unsafe_allow_html=True) + + with col3: + st.markdown(""" +
+

Fast Processing

+

Typically processes videos 2-4x faster than realtime duration

+
+ """, unsafe_allow_html=True) + + st.markdown( + """ +
+ +
+ """, + unsafe_allow_html=True +) + +if __name__ == "__main__": + main() \ No newline at end of file