Generating Lofi Pomodoro Streams
Default output: a ~60-minute 1080p video (MP4) containing procedurally generated lofi music, a looping background, and a Pomodoro overlay (25 min focus / 5 min break, long break after cycle 4).
Bashpip install numpy scipy pedalboard soundfile pillow # ffmpeg must be on PATH python lofi_gen.py --minutes 60 --bpm 78 --key Am --bg bg_loop.mp4 \ --focus 25 --short 5 --long 15 --out lofi_pomodoro.mp4
If lofi_gen.py doesn't exist yet, build it following the Workflow below. Do not ask the user questions first; use defaults and mention what was assumed.
Progress:
- [ ] Step 1: Confirm parameters (use defaults if unspecified)
- [ ] Step 2: Generate a 2-4 minute music "seed" section
- [ ] Step 3: Extend to 60 min via varied loop arrangement
- [ ] Step 4: Apply lofi mastering chain
- [ ] Step 5: Build or loop the background
- [ ] Step 6: Render the Pomodoro overlay
- [ ] Step 7: Mux audio + video with ffmpeg
- [ ] Step 8: Verify duration, loudness, and sync
Step 1: Defaults
| Parameter | Default |
|---|---|
| Length | 60 min (3600 s) |
| BPM | 70-85 (use 78) |
| Key | A minor |
| Pomodoro | 25 focus / 5 short break / 15 long break every 4 |
| Resolution | 1920x1080 @ 24 fps |
| Audio | 44.1 kHz stereo, -16 LUFS |
Step 2: Music Seed
Generate in Python with numpy. Structure the seed as 8-16 bars.
- Chords: 7th and 9th voicings, 4-bar progressions. Default:
Am9 - Dm9 - G13 - Cmaj9. Alternates:Fmaj7 - Em7 - Dm9 - Cmaj7,Cmaj7 - Am7 - Dm7 - G7. - Chord sound: Rhodes-style electric piano (sine + soft FM, slow attack, medium decay), or soft pad. Add slight timing and velocity jitter (±15 ms, ±10%) for a human feel.
- Drums: Kick on 1 and the "and" of 2; snare/clap on 2 and 4, softly; hi-hats in 8ths. Apply swing of 55-62%. Use filtered noise bursts and sine thumps (no sample packs needed).
- Bass: Sine or triangle on chord roots, low-passed at ~250 Hz.
- Melody (optional): Sparse pentatonic notes (A C D E G), 1-3 notes per bar, with rests.
- Texture: Vinyl crackle (sparse random impulses + filtered noise at -38 dB). Optional rain layer.
Step 3: Extending to an Hour
A 4-minute loop repeated 15 times is fatiguing. Create variation with a section plan:
Intro (1 bar of chords only, fade in) -> A (chords+drums) -> B (add melody) ->
A' (drop melody, change drum pattern slightly) -> Break (chords+crackle only) -> repeat
- Rotate through 2-3 chord progressions every 16 bars.
- Randomly mute/unmute layers per section (seeded RNG for reproducibility).
- Transpose up or down 2 semitones every ~15 min.
- Crossfade section boundaries by 1 bar.
- Generate in chunks (e.g., 4 min each) and write to disk to avoid RAM blowups; concatenate with ffmpeg
concat.
Step 4: Lofi Mastering Chain
Use pedalboard, applied per chunk:
Pythonfrom pedalboard import Pedalboard, LowpassFilter, HighpassFilter, Compressor, Reverb, Distortion, Limiter board = Pedalboard([ HighpassFilter(cutoff_frequency_hz=40), LowpassFilter(cutoff_frequency_hz=9000), Distortion(drive_db=3), Compressor(threshold_db=-18, ratio=3), Reverb(room_size=0.25, wet_level=0.15), Limiter(threshold_db=-1.0), ])
Add subtle tape wobble (pitch modulation ±5 cents at 0.3-0.8 Hz) before the chain. Normalize to about -16 LUFS afterward.
Step 5: Background
Priority order:
- User-supplied video/image: loop it. For an image, apply a slow zoom/pan (Ken Burns) via ffmpeg
zoompan. - AI-generated image (if image tools are available): prompt for "cozy lofi room at night, desk lamp, rain on window, anime-style, 16:9". Then animate with slow zoom plus a subtle rain overlay.
- Procedural fallback: gradient sky + Pillow-drawn window silhouette + animated rain streaks, rendered as a 10-20 s loop.
Loop the clip using -stream_loop -1 with -t 3600. Ensure the loop point is seamless (crossfade the last 1 s into the first 1 s).
Step 6: Pomodoro Overlay
Render the timer with ffmpeg drawtext driven by a generated timeline, or with Pillow frames piped to ffmpeg.
Build a schedule array first:
Pythonschedule = [] # (label, duration_s) for cycle in range(1, 5): schedule.append((f"FOCUS {cycle}/4", 25*60)) schedule.append(("LONG BREAK" if cycle == 4 else "SHORT BREAK", (15 if cycle == 4 else 5)*60))
Four full cycles = 25+5+25+5+25+5+25+15 = 130 min. For a 60-min video, truncate the schedule at 3600 s (typically 2 full cycles: Focus, Break, Focus, Break = 60 min exactly). State this in the output.
Overlay design:
- Top-right or bottom-center, semi-transparent rounded panel (~40% opacity black).
- Large
MM:SScountdown, label underneath ("FOCUS 1/4"), thin progress bar. - Focus = warm white text; break = soft green text.
- Font: a monospace or rounded sans (e.g., DejaVu Sans Mono) at 72-96 px.
- Play a soft chime (a 1.5 s sine bell) at each phase change; mix it into audio at the exact second.
Update the timer text once per second via drawtext with enable='between(t,start,end)' per second, or by generating overlay frames at 1 fps and compositing.
Step 7: Mux
Bashffmpeg -stream_loop -1 -i bg_loop.mp4 -i lofi_full.wav -i overlay.mov \ -filter_complex "[0:v][2:v]overlay=W-w-40:40[v]" \ -map "[v]" -map 1:a -t 3600 \ -c:v libx264 -preset medium -crf 20 -pix_fmt yuv420p \ -c:a aac -b:a 192k -movflags +faststart lofi_pomodoro.mp4
Step 8: Verify
Bashffprobe -v error -show_entries format=duration -of csv=p=0 lofi_pomodoro.mp4 # ~3600 ffmpeg -i lofi_pomodoro.mp4 -af ebur128 -f null - 2>&1 | grep "I:" # ~ -16 LUFS
Extract frames at 0:00, 25:00, 25:01, and 59:59 to confirm the timer states and the focus-to-break transition.
Example 1:
Input: "Make me a 1 hour lofi video with pomodoro"
Output: Runs with all defaults. Delivers lofi_pomodoro.mp4 (60:00, 1080p), 78 BPM A minor, rain-window procedural background, 2 full 25/5 cycles. Notes: "Used default 25/5 timing; the schedule fits exactly 2 cycles in 60 min."
Example 2:
Input: "Lofi beats, 90 minutes, 50/10 pomodoro, use my background.png"
Output: --minutes 90 --focus 50 --short 10, background.png animated with slow zoom, schedule: Focus 50, Break 10, Focus 20 (truncated) with a note that the final block is shortened to fit. Suggests --minutes 120 for clean cycles.
Example 3: Input: "Chill jazzy lofi, no drums, just piano and rain" Output: Drums muted, Rhodes chords with 9th voicings, rain layer raised to -22 dB, bass kept subtle, same pipeline.
- Seed the RNG (
--seed 42) so results are reproducible and tweakable. - Render audio in chunks and concatenate; a full hour at 44.1 kHz stereo float64 is ~1.2 GB in RAM if done naively. Use float32 and chunking.
- Keep the mix quiet and low-dynamic: lofi should sit around -16 LUFS with no harsh transients.
- Match phase to music when possible: start break sections with a gentler arrangement (drop drums) so the music itself cues the break.
- Offer extras only after delivering: YouTube chapter timestamps for each focus/break block, a thumbnail frame, or a 30-second preview render.
- Do a 60-second test render first to check sound and overlay layout before committing to the full hour.
- Looping one 8-bar pattern for 60 minutes. It becomes grating; always use the section plan and chord rotation.
- Overlay desync. Timer drift occurs if frame rate is variable. Force constant 24 fps (
-vsync cfr) and generate the overlay from the same schedule array used for chimes. - Clipping after the reverb/distortion stage. Always finish with a limiter and re-check loudness.
- Non-seamless background loop. A visible jump every 10 s ruins the vibe; crossfade the loop point.
- Schedule math errors. Truncate to the total length explicitly; don't let the final label say "FOCUS 3/4" with a countdown past video end.
- Using copyrighted samples or existing songs. Generate everything procedurally or from user-owned assets so the result is safe to upload.
- Asking multiple clarifying questions before starting. Use the defaults, deliver, then offer adjustments.