diff --git a/README.md b/README.md index c15d9e7..8e7eea6 100644 --- a/README.md +++ b/README.md @@ -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__.mp4`. +4. The script will do the rest, and generate the final video in the root folder, which will be formatted as `final_result___.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. diff --git a/ShitpostGenerator.py b/ShitpostGenerator.py index 4e301ca..8f14d49 100644 --- a/ShitpostGenerator.py +++ b/ShitpostGenerator.py @@ -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()