Mykhaylo Logo Mykhaylo Aushev Logo Mykhaylo Music Logo

, ,

Random Music Video Generator (MRvidGen Version 0.1)

Home » Random Music Video Generator (MRvidGen Version 0.1)
Your Random Music Video Generator

Introduction for the Random Music Video Generator

Are you a music artist looking to create unique and engaging music videos? Look no further! This small program uses the power of the Python programming language to generate random music videos by syncing them to the beats of your audio. You can achieve it by this Random Music Video Generator a.k.a MRvidGen Version 0.1.

How does MRvidGen works?

  1. The program will first fetch random videos from Pexels API based on the search query provided.
  2. It will then load the audio file and detect the beats using the librosa library.
  3. Then it will convert the audio file to mp3 format.
  4. Next, it will process each video and create subclips that align with the beats of the audio.
  5. Finally, it will combine all the subclips into a final video and synchronize it with the audio file.
  6. The final video will be saved in the same directory as the code with the name “final_video.mp4

MRvidGen is still in development

  1. The program is still in development and I hope to host it on my site at some point so that you can just drag and drop your audio to get a cool video.
  2. The second things is that the automatic video editing process is not perfect yet so I am still working on that.
Random music video Generator image 2
A screenshot from a music Video created by MRvidGen

Prerequisites for MRvidGen

  • Anaconda (Download Anaconda)
  • Python 3.6
  • A Pexels API key (
  • The following Python libraries installed: requests, json, random, librosa, soundfile, pydub, wave, moviepy (don’t worry if you are not a coder I will tell you in just a minute how to easily install them )


  • In the Conda Terminal, install the dependencies (libraries) with 1 line
pip install requests json random librosa soundfile pydub wave moviepy
  • Create file in the folder of your choice, open it with a text editor or anything else, and post this code into it:
import json
import random
import requests
import librosa
import soundfile as sf
import pydub
import wave

from moviepy.editor import VideoFileClip, concatenate_videoclips

# Fetch multiple random videos from Pexels API
response = requests.get("", headers={"Authorization": "YOUR_AUTH_KEY"})
response_json = json.loads(response.text)
video_urls = [v['video_files'][0]['link'] for v in response_json['videos']]

# Load audio file and detect beats
audio, sr = librosa.load("YOUR_AUDIO.mp3", mono=True)
tempo, beat_frames = librosa.beat.beat_track(y=audio, sr=sr)
beat_times = librosa.frames_to_time(beat_frames, sr=sr)

# Convert audio data to mp3 file

# write the numpy array to a wave file
with"audio.wav", "w") as wav_file:
    wav_file.setparams((1, 2, sr, 0, "NONE", "not compressed"))

# Convert audio data to mp3 file
audio_mp3 = pydub.AudioSegment.from_file("audio.wav", format="wav")
audio_mp3.export("audio.mp3", format="mp3")
audio_mp3.export("audio.mp3", format="mp3")

# Prepare a list to store the subclips
subclips = []

#Process each video

for i, video_url in enumerate(video_urls):
    # Load video file
    video = VideoFileClip(video_url)
    video_duration = 2
    beat_times_filtered = [time for time in beat_times if time < video_duration]
    for beat_time in beat_times_filtered:
        subclip = video.subclip(0, beat_time)

final_video = concatenate_videoclips(subclips)
final_audio = pydub.AudioSegment.from_file("YOUR_AUDIO.mp3", format="mp3")
final_audio.export("audio.mp3", format="mp3")
final_video.write_videofile("final_video.mp4", audio="audio.mp3", codec='libx264', audio_codec='aac')

#Creative Commons license Mykhaylo Aushev
  • Go to that folder that you created through the Conda Terminal
cd "C:\Users\yourfolder\"
  • Put your audio.mp3 in your folder
  • In the code, replace YOUR_AUTH_KEY with your Pexels API key (that you get here when you register as a Pexels developer)
  • Replace YOUR_AUDIO.mp3 with the audio file title you would like to use.
  • Replace chnage+this+part with a search query that you would like to use to fetch the videos.
  • Save the file (Shift +S)
  • Run the code in your preferred Python environment.
  • Wait a couple of minutes and your video should be saved in the same folder as final_video.mp4 and you are done!

Troubleshooting MRvidGen

  • Make sure that you have all the necessary libraries installed, and that the versions of the libraries are compatible with the code.
  • Make sure that the audio file and the search query are correct.
  • Make sure that you have a stable internet connection while running the code.
  • Make sure that the Pexels API key is correct.

Conclusion MRvidGen, for now.

With this program, you can easily create fresh glitchy and engaging music videos that align with the beats of your audio. The program is easy to use and customizable, making it a great tool for any music artist looking to make their music videos (or make parts of the videos special). Give it a try and see what kind of music videos you can create!

Make sure to share this with your friends, send me what you make and tell me how to improve it and what you might like in the final version.

If you are looking for new Beats

Check out my beats if you are looking for new inspiration and new fresh pop sound!
My Beats

2 Responses

    1. Спасибо! Скоро будет онлайн версия где просто кидаешь аудио и оно тебе даёт видео вместе с аудио. Но если хочешь уже сейчас попробывать то можещь попробывать пройти этот не большой туториал 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Share this Blog!

Similar Articles

Mykhaylo Aushev

Music Producer

Hi, I am Mykhaylo, a music producer, artist, and designer based in Würzburg, Germany. I create music daily and help the artist achieve their dreams by creating awesome things together. I also write and produce my own songs and tracks. Music is my passion and I want to spread good vibes to the world.

Check out my Beats

Discover fresh Pop and Hip Hop Instrumentals

sign up for beats

get 10 free beats

Mykhaylo 31 by Ellinor Brandenberg