|
import streamlit as st |
|
import os |
|
from moviepy.editor import VideoFileClip |
|
|
|
st.title("Video Playback and Duplication") |
|
|
|
|
|
def convert_to_mp4(input_path, output_path): |
|
try: |
|
video_clip = VideoFileClip(input_path) |
|
video_clip.write_videofile(output_path, codec="libx264", audio_codec="aac") |
|
return True |
|
except Exception as e: |
|
st.error(f"Error converting video: {e}") |
|
return False |
|
|
|
|
|
uploaded_file = st.file_uploader("Choose a video...", type=["mp4", "avi", "mov", "mkv"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
os.makedirs("temp", exist_ok=True) |
|
input_video_path = os.path.join("temp", uploaded_file.name) |
|
output_video_path = os.path.join("temp", "converted_video.mp4") |
|
|
|
|
|
with open(input_video_path, "wb") as f: |
|
f.write(uploaded_file.getbuffer()) |
|
|
|
|
|
file_type = uploaded_file.type.split('/')[1] |
|
if file_type in ['mp4', 'webm', 'ogg']: |
|
st.video(input_video_path, start_time=0) |
|
st.write("Original Video") |
|
else: |
|
if convert_to_mp4(input_video_path, output_video_path): |
|
st.success("Video converted successfully!") |
|
st.video(output_video_path, start_time=0) |
|
st.write("Original Video (Converted)") |
|
else: |
|
st.error("Failed to convert video.") |
|
|
|
|
|
if st.button('Generate'): |
|
st.video(output_video_path if file_type not in ['mp4', 'webm', 'ogg'] else input_video_path, start_time=0) |
|
st.write("Duplicated Video") |