Skip to content

Instantly share code, notes, and snippets.

@sohang3112
Created May 8, 2024 06:46
Show Gist options
  • Save sohang3112/4de77e3fef944fbfeaf2a1bbaca8f14f to your computer and use it in GitHub Desktop.
Save sohang3112/4de77e3fef944fbfeaf2a1bbaca8f14f to your computer and use it in GitHub Desktop.
Notes on processing & generation of video / audio in Python
# Create a silent MP3 audio
# Requires ffmpeg library, install with: sudo apt install -y ffmpeg
from pydub import AudioSegment
silence = AudioSegment.silent(duration=5000) # duration in milliseconds
silence.export("silence.mp3", format="mp3")
# Extract audio from video
import moviepy.editor
video = moviepy.editor.VideoFileClip("/path/to/video.mp4")
if video.audio is None:
print("Video has no audio (silence)")
else:
video.audio.write_audiofile("/path/to/audio.mp3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment