Created
May 8, 2024 06:46
-
-
Save sohang3112/4de77e3fef944fbfeaf2a1bbaca8f14f to your computer and use it in GitHub Desktop.
Notes on processing & generation of video / audio in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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