avant-gourd.mov

Category 19. Experimental / Open

AUDIO ANALYSIS

y, sr = librosa.load(audio_filename, sr=None, mono=True) duration = librosa.get_duration(y=y, sr=sr) FPS = 30

RMS envelope

hop_length = int(sr / FPS) rms = librosa.feature.rms(y=y, hop_length=hop_length)[0] rms = rms / rms.max()

Beat detection

tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr, hop_length=hop_length) beats = librosa.frames_to_time(beat_frames, sr=sr, hop_length=hop_length)

Frequency bands

S = np.abs(librosa.stft(y, n_fft=4096, hop_length=hop_length)) freqs = librosa.fft_frequencies(sr=sr, n_fft=4096)

def band_env(low, high): idx = np.where((freqs >= low) & (freqs <= high))[0] if len(idx) == 0: return np.zeros(S.shape[1]) env = S[idx].mean(axis=0) return env / env.max()

bass = band_env(20, 200) mid = band_env(200, 2000) treble = band_env(2000, 6000)

print("Audio analyzed. Duration:", duration, "seconds")

VIDEO RENDERING

WIDTH, HEIGHT = 1920, 1080 BG_COLOR = (8, 8, 14) GEOM_COLOR = (40, 180, 255) ACCENT_COLOR = (255, 200, 80) CHAR_COLOR = (240, 240, 250)

def frame_index(t): i = int(t * FPS) return min(i, len(rms)-1)

def draw_character(draw, cx, cy, scale, shift): w = int(60 * scale) h = int(150 * scale) draw.ellipse((cx-w, cy-h//2+shift, cx+w, cy+h//2+shift), fill=CHAR_COLOR) head = int(30 * scale) draw.ellipse((cx-head, cy-h-head+shift, cx+head, cy-h+head+shift), fill=CHAR_COLOR)

def make_frame(t): idx = frame_index(t) amp = rms[idx] b = bass[idx] m = mid[idx] tr = treble[idx]

img = Image.new("RGB", (WIDTH, HEIGHT), BG_COLOR)
draw = ImageDraw.Draw(img)

cx, cy = WIDTH//2, HEIGHT//2

# --- Geometry ---
R = int(150 + b * 350)
angle = t * (0.6 + m*3)
pts = []
for i in range(6):
    a = angle + i * (2*np.pi/6)
    pts.append((cx + R*np.cos(a), cy + R*np.sin(a)))
draw.polygon(pts, outline=GEOM_COLOR, width=4)

# --- Character ---
shift = int(-amp * 120)
draw_character(draw, cx, cy + 80 + shift, 1 + tr*0.5, shift)

return np.array(img)

video = VideoClip(make_frame, duration=duration) video = video.set_audio(AudioFileClip(audio_filename))

out_name = "avant_gourd" video.write_videofile(out_name, fps=FPS, codec="libx264")

print("Rendering complete. Output:", out_name)

Built With

Share this project:

Updates