v2
This commit is contained in:
parent
68de8ffbc6
commit
d8e76a0420
2 changed files with 75 additions and 19 deletions
|
@ -99,6 +99,9 @@ duration = int(math.ceil(librosa.get_duration(y=wave, sr=sr)))
|
|||
|
||||
frames = duration * fps
|
||||
|
||||
|
||||
|
||||
|
||||
print("RMS SIZE: " + str(len(rms[0])))
|
||||
print("Rms min/max: " + str(rms.min()) + "/" + str(rms.max()))
|
||||
print("CEN SIZE: " + str(len(cent[0])))
|
||||
|
@ -146,6 +149,7 @@ try:
|
|||
|
||||
print("RMS SIZE: " + str(len(rms[0])))
|
||||
print("Rms min/max: " + str(rms.min()) + "/" + str(rms.max()))
|
||||
print("Rms mean: " + str(np.mean(rms[0])))
|
||||
print("CEN SIZE: " + str(len(cent[0])))
|
||||
print("Cent min/max: " + str(cent.min()) + "/" + str(cent.max()))
|
||||
print("TOTAL FRAMES: " + str(frames))
|
||||
|
|
90
sampler.py
90
sampler.py
|
@ -67,21 +67,18 @@ def anlyzeSound(audio_input_file):
|
|||
|
||||
#rms = librosa.feature.rms(y=wave, frame_length=735, hop_length=735)
|
||||
cent = librosa.feature.spectral_centroid(y=wave, sr=sr,n_fft=flength, hop_length=flength)
|
||||
|
||||
zcr = librosa.feature.zero_crossing_rate(y=wave, frame_length=flength, hop_length=flength)
|
||||
duration = int(math.ceil(librosa.get_duration(y=wave, sr=sr)))
|
||||
|
||||
frames = duration * fps
|
||||
#frames = duration * fps
|
||||
|
||||
|
||||
#:w
|
||||
# sr.len /22050 = duration
|
||||
# rms.len * 30 = duration
|
||||
# rms[i] mi da la potenza media del frame iesimo
|
||||
trms= rms[0]
|
||||
|
||||
|
||||
|
||||
seed = 123456
|
||||
seed = random.randint(1, MAX_SEED_VALUE)
|
||||
#generateSoundVariations("bubble-machine", 3793866858, rms,5000,7500)
|
||||
#generateSoundVariations("sands-of-time", 2226183906, rms,-1,2500)
|
||||
#generateSoundVariations("sands-of-time", 2226183906, rms,2500,5000)
|
||||
|
@ -90,7 +87,7 @@ def anlyzeSound(audio_input_file):
|
|||
#generateSoundVariations("sands-of-time", 2226183906, rms,10000,10333)
|
||||
#generateSamples()
|
||||
#postprocessBrightness("/tmp/",cent, 8316,10000)
|
||||
return rms, cent
|
||||
return rms, cent, zcr
|
||||
|
||||
def width_option(default=1024, **attrs):
|
||||
attrs.setdefault("help", "Output width, in pixels")
|
||||
|
@ -111,7 +108,7 @@ def width_option(default=1024, **attrs):
|
|||
@click.option('--preset', type=click.Choice(["random"] + sorted(GENERATOR_PRESETS)))
|
||||
@click.pass_context
|
||||
def genframes(ctx,width, height,preset, seed, framestart, framestop, audiofile, out_dir):
|
||||
rms, centroids = anlyzeSound(audiofile)
|
||||
rms, centroids, zcr = anlyzeSound(audiofile)
|
||||
|
||||
|
||||
|
||||
|
@ -122,11 +119,12 @@ def genframes(ctx,width, height,preset, seed, framestart, framestop, audiofile,
|
|||
time_dividend =500
|
||||
s = interp1d([min(rms[0]), max(rms[0])], [0, 0.9])
|
||||
trms=rms[0]
|
||||
mean = np.mean(trms)
|
||||
if framestop<0:
|
||||
framestop = len(rms[0])
|
||||
for frame in range(framestart, framestop):
|
||||
try:
|
||||
speed=float(format(trms[frame],'.3f'))
|
||||
speed=abs(mean - float(format(trms[frame], '.3f')))
|
||||
#print(f"(speed: {speed}) (trms: {trms[frame]}) )")
|
||||
time = (float)((frame % time_dividend)/time_dividend)
|
||||
filename = out_dir+ '/' + preset + "_" + str(seed)+ "_" + str(frame).zfill(10) +".png"
|
||||
|
@ -137,14 +135,16 @@ def genframes(ctx,width, height,preset, seed, framestart, framestop, audiofile,
|
|||
except Exception as e:
|
||||
print(f"Exception {e} on Preset: {preset}")
|
||||
continue
|
||||
|
||||
|
||||
def testPillow():
|
||||
image = Image.open('/tmp/alt/sands-of-time_2226183906_0000005401.png')
|
||||
|
||||
@main.command()
|
||||
@click.pass_context
|
||||
def testpillow(ctx):
|
||||
image = Image.open('/tmp/the-inward-spiral_3917354306_0_0.23284526795328386.png')
|
||||
brightness_factor = 3.5 # Increase brightness by 50%
|
||||
enhancer = ImageEnhance.Brightness(image)
|
||||
brightened_image = enhancer.enhance(brightness_factor)
|
||||
contrast_factor = 2.2 # Increase contrast by 20%
|
||||
contrast_factor = 4.2 # Increase contrast by 20%
|
||||
enhancer = ImageEnhance.Contrast(image)
|
||||
contrasted_image = enhancer.enhance(contrast_factor)
|
||||
brightened_image.save("/tmp/alt/brightened_image.png")
|
||||
|
@ -195,17 +195,62 @@ def generateSpeedVariations(preset_name):
|
|||
print(f"Exception on Preset: {preset_name}")
|
||||
continue
|
||||
|
||||
def generateVariations(preset_name):
|
||||
@main.command()
|
||||
@click.option('--iterations', required=False, type=int, default=100)
|
||||
@click.option('--preset', type=click.Choice(["random"] + sorted(GENERATOR_PRESETS)))
|
||||
@click.pass_context
|
||||
def gentimevariations(ctx,preset,iterations):
|
||||
seed = random.randint(1, MAX_SEED_VALUE)
|
||||
for time in range(0,999,1):
|
||||
speed = random.random()
|
||||
for time in range(0, iterations, 1):
|
||||
try:
|
||||
ftime = (float)(time/1000)
|
||||
ftime = (float)(time/iterations)
|
||||
print(str(ftime))
|
||||
generate(600,600,ftime,1,seed,"/tmp/"+ preset_name + "_" + str(seed)+ "_" + str(time) +".png",False,False,False,False,False,False,"",False,False,preset_name)
|
||||
filename = tempfile.gettempdir() + "/" + preset+ "_" + str(seed) + "_" + str(time) + "_" + str(speed) + ".png"
|
||||
generate(600,600,ftime,speed,seed, filename,False,False,False,False,False,False,"",False,False,preset)
|
||||
except Exception as e:
|
||||
print(f"Exception on Preset: {preset}")
|
||||
continue
|
||||
|
||||
@main.command()
|
||||
@click.pass_context
|
||||
def gensamples(ctx):
|
||||
for preset_name, preset_data in PRESETS().items():
|
||||
try:
|
||||
|
||||
seed = random.randint(1, MAX_SEED_VALUE)
|
||||
time = random.random()
|
||||
speed = random.random()
|
||||
filename = tempfile.gettempdir() + "/" + preset_name + "_" + str(seed) + "_" + str(time)+ "_" + str(speed) + ".png"
|
||||
print(f"Going to generate: {filename}")
|
||||
generate(1024, 1024, time, speed, seed, filename ,
|
||||
False, False, False, False, False, False, "", False, False, preset_name)
|
||||
except Exception as e:
|
||||
print(f"Exception on Preset: {preset_name}")
|
||||
continue
|
||||
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.option('--iterations', required=False, type=int, default=10)
|
||||
@click.option('--preset', type=click.Choice(["random"] + sorted(GENERATOR_PRESETS)))
|
||||
@click.pass_context
|
||||
def genseedsvariations(ctx,preset,iterations):
|
||||
for i in range(iterations):
|
||||
try:
|
||||
|
||||
seed = random.randint(1, MAX_SEED_VALUE)
|
||||
time = random.random()
|
||||
speed = random.random()
|
||||
filename = tempfile.gettempdir() + "/" + preset + "_" + str(seed) + "_" + str(time) + "_" + str(
|
||||
speed) + ".png"
|
||||
print(f"Going to generate: {filename}")
|
||||
generate(1024, 1024, time, speed, seed, filename,
|
||||
False, False, False, False, False, False, "", False, False, preset)
|
||||
except Exception as e:
|
||||
print(f"Exception on Preset: {preset}")
|
||||
continue
|
||||
|
||||
|
||||
def generate(width, height, time, speed, seed, filename, with_alpha, with_supersample, with_fxaa, with_ai, with_upscale,
|
||||
with_alt_text, stability_model, debug_print, debug_out, preset_name):
|
||||
if not seed:
|
||||
|
@ -483,7 +528,14 @@ def animate(ctx, width, height, seed, effect_preset, filename, save_frames, fra
|
|||
else:
|
||||
util.magick(f'{tmp}/*png', filename)
|
||||
|
||||
|
||||
@main.command(help="Blend a directory of .png or .jpg images")
|
||||
@cli.input_dir_option(required=True)
|
||||
@cli.filename_option(default="collage.png")
|
||||
@click.option("--control-filename", help="Control image filename (optional)")
|
||||
@cli.time_option()
|
||||
@click.option('--speed', help="Animation speed", type=float, default=0.25)
|
||||
@cli.seed_option()
|
||||
@click.pass_context
|
||||
def mashup(ctx, input_dir, filename, control_filename, time, speed, seed):
|
||||
filenames = []
|
||||
|
||||
|
|
Loading…
Reference in a new issue