Spaces:
Running
Running
File size: 2,020 Bytes
4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 4e0d1e9 c2a2840 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import streamlit as st
import ffmpeg
import os
from PIL import Image
def create_video(image_path, audio_path, output_path):
"""
Create a video from an image and an audio file using FFmpeg.
:param image_path: Path to the image file
:param audio_path: Path to the audio file
:param output_path: Path to save the output video
"""
try:
# FFmpeg command to create a video
input_image = ffmpeg.input(image_path, loop=1, t=ffmpeg.probe(audio_path)['format']['duration'])
input_audio = ffmpeg.input(audio_path)
ffmpeg.output(input_image, input_audio, output_path, vcodec='libx264', acodec='aac', pix_fmt='yuv420p', shortest=None).run()
except Exception as e:
st.error(f"Error during video creation: {e}")
# Streamlit UI
st.title("Video Creator")
st.write("Upload an image and an audio file to create a video.")
# File uploaders
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
uploaded_audio = st.file_uploader("Upload an MP3 file", type=["mp3"])
if uploaded_image and uploaded_audio:
# Save uploaded files locally
image_path = f"temp_image.{uploaded_image.name.split('.')[-1]}"
audio_path = "temp_audio.mp3"
output_path = "output_video.mp4"
with open(image_path, "wb") as f:
f.write(uploaded_image.getbuffer())
with open(audio_path, "wb") as f:
f.write(uploaded_audio.getbuffer())
st.write("Files uploaded successfully.")
# Create video
st.write("Creating video...")
create_video(image_path, audio_path, output_path)
# Show and download video
if os.path.exists(output_path):
st.video(output_path)
with open(output_path, "rb") as f:
st.download_button(
label="Download Video",
data=f,
file_name="output_video.mp4",
mime="video/mp4"
)
# Cleanup temporary files
os.remove(image_path)
os.remove(audio_path)
os.remove(output_path)
|