Add video effects toggle, change random clip duration

This commit is contained in:
Chev 2020-10-12 15:42:33 -07:00
parent 03ba7427de
commit 0cef20d304
2 changed files with 12 additions and 4 deletions

View file

@ -15,7 +15,7 @@ Here's how it works:
1. Put a list of desired video sources into the `VideoSources` folder, and a list of desired audio sources into the `AudioSources` folder. I recommend keeping the video file formats the same, but it shouldn't matter. The resolution of videos does not matter, either.
2. Run the script, and choose a seed if you want to reproduce the same video. Otherwise, type 'any' to choose a random seed.
3. Choose the amount of videos you want the script to merge together to produce the final result. I recommend 30 for roughly minute-long videos.
4. The script will do the rest, and generate the final video in the root folder, which will be formatted as `final_result_<seed>_<number-of-videos>.mp4`.
4. The script will do the rest, and generate the final video in the root folder, which will be formatted as `final_result_<seed>_<number-of-videos>_<effects-enabled>.mp4`.
## Performance
This script uses moviepy - due to the amount of ffmpeg processes moviepy opens from this script, it has really high memory usage. I have seen this script use upwards of about ~2.5GB of memory for 40 random videos.

View file

@ -97,6 +97,12 @@ while not videoAmount.isdecimal():
videoAmount = int(videoAmount)
shouldUseEffects = input("Apply video effects? (y/n): ")
while not shouldUseEffects in ["y", "yes", "true", "n", "no", "false"]:
shouldUseEffects = input("Apply video effects? (y/n): ")
shouldUseEffects = True if shouldUseEffects in ["y", "yes", "true"] else False
randomVideos = rng.sample(videoFiles, min(videoAmount, len(videoFiles)))
if videoAmount > len(videoFiles): #if there is a higher chosen amount than total, re-use videos
videoAmountToAdd = videoAmount - len(videoFiles)
@ -116,7 +122,7 @@ for video in randomVideos:
startOffset = rng.uniform(0, newClip.duration - randomDuration)
newClip = newClip.subclip(startOffset, startOffset+randomDuration)
if rng.choice([True, True, False]):
if rng.choice([True, True, False]) and shouldUseEffects:
newClip = rng.choice(videoEffects)(newClip) #apply a random effect
videoObjects.append(newClip)
@ -145,7 +151,7 @@ for audio in randomSounds:
newClip = moviepy.audio.fx.volumex.volumex(newClip, 0.5) # modify volume
if newClip.duration > 5: #for long clips
randomDuration = rng.uniform(0.7, 6) # crop audio duration
randomDuration = rng.uniform(0.7, 13) # crop audio duration
if newClip.duration > randomDuration: # if the audio is longer than the cropped duration, crop the audio at a random position
startOffset = rng.choice([rng.uniform(0, newClip.duration - randomDuration), 0]) #either use a random offset, or start at beginning of audio clip
newClip = newClip.subclip(startOffset, startOffset+randomDuration)
@ -171,8 +177,10 @@ print(f"Finished compiling audio. Added {copiedSoundAmount} duplicate sounds, to
newAudioClip = editor.CompositeAudioClip([finalVideo.audio] + audioObjects)
finalVideoFilename = f'final_result_{seed}_{videoAmount}{"_effects" if shouldUseEffects else ""}.mp4'
finalVideo.audio = newAudioClip
finalVideo.write_videofile(f'final_result_{seed}_{videoAmount}.mp4', fps=30, audio_bitrate="96k")
finalVideo.write_videofile(finalVideoFilename, fps=30, audio_bitrate="96k")
for video in videoObjects:
video.close()