diff --git a/README.md b/README.md index cbb2762..a7c0306 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,32 @@ # milkbucket +## Build +milkbucket depends on the +[projectM](https://github.com/projectM-visualizer/projectm) library. To run +milkbucket, you'll need to install this library either by building it yourself, +or installing one of the builds from +[here](https://github.com/projectM-visualizer/projectm/actions). (If you've +never done this before, you'll want to download one of the "shared" artifacts +for your system. Then, copy the contents of the artifact's `include` folder to +`/usr/local/include` and the contents of the `lib` folder to `/usr/local/lib`.) + +After installing projectM, build milkbucket with `go build`. + +## Usage +milkbucket reads a PCM stream from standard input to generate visualizations. +If you have an audio file and a preset in mind, you can use `ffmpeg` to +generate the PCM stream, then pipe to milkbucket, like so: +``` +ffmpeg -i $audio -ar 44100 -f s16le - | ./milkbucket -p $preset +``` + +Note that neither of these commands will output any audio! If you want to hear the audio at the same time (and assuming your machine uses pipewire), run: ``` ffmpeg -i $audio -ar 44100 -f s16le - | tee >(pw-play --rate=44100 --format=s16 -) | ./milkbucket -p $preset ``` +(If you don't use pipewire try using `aplay` instead of `pw-play`, or some other command for playing PCM streams.) + +You can also generate a visualization from your system sound. Assuming pipewire again, and that you have audio coming from Firefox, run: +``` +pw-record --target Firefox - | ./milkbucket -p $preset +``` diff --git a/cmd/root.go b/cmd/root.go index 156461f..3ff6da8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,6 +17,7 @@ along with this program. If not, see . package cmd import ( + "log" "os" "github.com/spf13/cobra" @@ -46,7 +47,16 @@ func handleEvent(event sdl.Event, m *milkDropWindow) bool { } func milkbucket(cmd *cobra.Command, args []string) { - err := sdl.Init(sdl.INIT_VIDEO) + fi, err := os.Stdin.Stat() + if err != nil { + panic(err) + } + size := fi.Size() + if size <= 0 { + log.Fatal("stdin is empty") + } + + err = sdl.Init(sdl.INIT_VIDEO) if err != nil { panic(err) }