From e9343cb3275a383c6af74a3d5148f5e0d008f017 Mon Sep 17 00:00:00 2001 From: Luca Conte Date: Wed, 8 Nov 2023 11:19:38 +0100 Subject: [PATCH] initial --- .gitignore | 1 + AudioToDeforumKeyframes.py | 103 +++++++++++++++++++++++++++++++++++++ appunti.md | 10 ++++ requirements.txt | 0 4 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 AudioToDeforumKeyframes.py create mode 100644 appunti.md create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/AudioToDeforumKeyframes.py b/AudioToDeforumKeyframes.py new file mode 100644 index 0000000..2ddb848 --- /dev/null +++ b/AudioToDeforumKeyframes.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Beat tracking example +# Appunti: buono per un video u po' psichedelico ci va: +# an abstract circuit board design with orange yellow green and purple squares over red background in the style of bb3l15 +# su modello colorful_v30 (https://civitai.com/images/3024879?modelVersionId=188803&prioritizedUserIds=913950&period=AllTime&sort=Most+Reactions&limit=20 ) + +# black background, sketch jungle scenery, path, dense su sd 1.5 +# Wilson black background, sketch jungle setting + +import os +import numpy as np +import librosa +import math +from scipy.interpolate import interp1d +import matplotlib.pyplot as plt + +def f(t): + return 1.0025+0.002*np.sin(1.25*3.14*t/30) + #return x ** 2 + + +strength_min = 0.4 +strength_max = 0.6 + + +# Assuming that into "generated" directoruy U've already create "project_name" subfolder +#audio_input_file = '/home/lalo/data/studio_grafica/deforum/wilson_r1_mm_sample.wav' +#audio_input_file = '/home/lalo/data/studio_suono/spx/231104_001_m01.wav' +#audio_input_file = '/home/lalo/data/studio_grafica/deforum/eucrasy_r1_sample.wav' +#audio_input_file = '/home/lalo/data/studio_grafica/deforum/eucrasy_r1.wav' +#audio_input_file = '/home/lalo/data/studio_suono/231014_002_mastered_r2_clip.WAV' +audio_input_file = 'C:/Users/LucaConte/Music/lc_music/wilson_r1_mm.wav' + + +# Store the sampling rate as `sr` + +fps = 24 + +flength = 22050//fps +#audio frame size is 22050/30=735 + + + +y, sr = librosa.load(audio_input_file) +rms = librosa.feature.rms(y=y, frame_length=flength, hop_length=flength) + +#rms = librosa.feature.rms(y=y, frame_length=735, hop_length=735) +cent = librosa.feature.spectral_centroid(y=y, sr=sr,n_fft=flength, hop_length=flength) +duration = int(math.ceil(librosa.get_duration(y=y, sr=sr))) + +frames = duration * fps + + + +print("RMS SIZE: " + str(len(rms[0]))) +print("CEN SIZE: " + str(len(cent[0]))) +print("TOTAL FRAMES: " + str(frames)) + +# sr.len /22050 = duration +# rms.len * 30 = duration +# rms[i] mi da la potenza media del frame iesimo + +m = interp1d([rms.min(), rms.max()], [strength_min, strength_max]) +c = interp1d([cent.min(), cent.max()], [-0.5, 0.5]) +print("Cent min/max: " + str(cent.min()) + "/" + str(cent.max())) + +print("Audio duration in secs: " + str(duration)) +# Creating the sctipt file (the real unique aoutput of this script) +try: + for frame in range(len(rms[0])): + print(str(frame) + ":(" + str(1-m(rms[0][frame])) + "),", end="") + + print("") + print("---------------") + print("") + + for frame in range(rms.size): + print(str(frame) + ":(" + str(cent[0][frame]) + "),", end="") +except: + print(exception) + + + +x = np.array(range(200)) +#x = np.array(range(len(cent[0]))) +y = np.array(cent[0]) + + +plt.hist(cent[0], color = 'blue', edgecolor = 'black', + bins = int(cent.max()/100)) + + +plt.show() + + +x = np.linspace(1, 4000, 4000) +y = f(x) + +plt.plot(x, y) +plt.show() + diff --git a/appunti.md b/appunti.md new file mode 100644 index 0000000..f4883b6 --- /dev/null +++ b/appunti.md @@ -0,0 +1,10 @@ +Per giungla: +p: (vktr), lowres, impressive rainforest, ((mist)), strong rain, film grain +np: ((bad hands)), text, missing finger, extra digits, fewer digits, ((mutated hands and fingers)), (poorly drawn face), ((deformed face)), extra face, (double head), (extra head), ((extra feet)), logo, (cropped), worst quality, low quality, normal quality, jpeg, humpbacked, ((jpeg artifacts)),(((typography))) +model: vmazGENESIS +seed: + + +PEr stelle: +seed: 79545309 + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29