Search code examples
command-lineaudiomp3screenshotaudio-streaming

Take screenshot of audio stream


Alright, what I need is a command-line application that allows you to take a screenshot of a file's audio stream.

For example it should be run like this:

app.exe "C:/artist-title.mp3" "C:/mp3Stream.jpg"
app.exe "C:/artist-title.wav" "C:/wavStream.jpg"

It only has to be able to capture mp3 streams, other streams are a bonus.

Preferably all audio channels are listed in the image, but if all channels are combined into one mono stream it would work just as good for me.

So, is there such a application out there? So that I don't re-invent the wheel.

If not does anyone have tips on how I should go about writing such a application myself? Preferably in Java. I can handle programming pretty well but I'm not exactly an expert on the MP3/WAV formats.

Why do I need it...? Well, it's more fun to link to a file online with some sort of preview image besides the link. It gives you a hint of the audio character before you listen to it (is it loud? does it look like "bit music"? does it have any parts that are more quiet than others? etc).


Solution

  • Never mind, I wrote my own little application in Java.

    It was a piece of cake once I found this excellent guide:
    http://codeidol.com/java/swing/Audio/Build-an-Audio-Waveform-Display/

    Although you can't download the source from that page (as far as I can tell, though he makes it apparent that you should be able to) he does provide some very useful key lines of code that makes it easy to puzzle together the application.

    Adding a little bit of help (easy stuff). You can get a graphics object from doing so:

    BufferedImage img = new BufferedImage(500, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D gfx = (Graphics2D) img.getGraphics();

    And once you have drawn everything you need on the gfx you can save it to disk just by one line:

    ImageIO.write(img, "jpg", new File("waveform.png"));

    It's hard to get it to look very good though. Doesn't look as nice as for example Audacity. Guess they have spent more time on it than a few hours though.

    The biggest pain about this is however that Java don't support MP3 import. They really should get around to that.

    So to get the waveform of MP3s I first convert them into WAV using "javazoom.jl.decoder.Decoder.java", it's on their website. Very easy to use, just give the input path and the output path and it's done.

    javazoom dot net (couldn't post more than one "hyperlink" on this website)

    The big downside of this is of course that a huuge WAV file has to be created, and woe be unto thee if the MP3 happens to be 15 minutes or so... The WAV will be over 100 MiB (maybe even 200 MiB, haven't found out since I got a Java-out-of-memory-error, even though I gave the VM 512mb).

    MP3 support in Java today please. Guess the reason they don't have it is because of copyright issues. Copyright really is slowing man down.