bbc / audiowaveform

C++ program to generate waveform data and render waveform images from audio files
https://waveform.prototyping.bbc.co.uk
GNU General Public License v3.0
1.93k stars 242 forks source link

Limit processing when using pixels-per-second #165

Open xeruf opened 2 years ago

xeruf commented 2 years ago

When using pixels-per-second, one cannot add --end - understandable, since it is redundant to --width then. But unfortunately, --end is the only flag that limits the time of audio that is processed, so that even on a short width, long audio files take a long time to process with pixels-per-second. Through a simple division this should be limited internally :)

sgloe commented 10 months ago

I am creating a json data file and only need a specific piece of my whole audio file as waveform. I use the --pixels-per-second 15 to reduce the filesize. For the whole file, this works perfectly. Now I tried to only get the part between 00:10 and 00:40 by using --start 10 --end 40. But this fails due with the message Specify either --end or --pixels-per-second but not both. I do not understand why. Is there a way to achieve this?

chrisn commented 10 months ago

Now I tried to only get the part between 00:10 and 00:40 by using --start 10 --end 40. But this fails due with the message Specify either --end or --pixels-per-second but not both. I do not understand why. Is there a way to achieve this?

I think this should be allowed, i.e., set --start, --end, and --pixels-per-second, and use these to determine the width. I'll work on a fix.

As a workaround, you can set the --width option instead of --pixels-per-second. So in your example, you want a 30 second waveform at 15 pixels per second, so the width is 450 pixels: --start 10 --end 40 --width 450.

xeruf commented 10 months ago

It would also be nice to automatically calculate the end from the width. From the behavior I observed when setting width it still processes the audio file till the end and then cuts it off, incurring significant extra processing.

sgloe commented 10 months ago

Hey Chris, I tried your suggested workaround. It does work, if I output a PNG file. The image looks correct and does fit the audio. But as far as I can see, it does not work, if I output a JSON data file. The JSON data always contains the peaks for the complete length of the original audio file. @xeruf what output format do you use?

chrisn commented 10 months ago

Ah, sorry, I should have checked that would actually work before suggesting it. The options are handled differently for creating images vs creating data files, hence the discrepancy - for historical reasons, as we only needed full duration data files, whereas images could be any period within the audio.

xeruf commented 10 months ago

output as image for display with timg

sgloe commented 10 months ago

Ok, I understand. Unfortunately, I am not a CPP Developer, so I am unable to contribute here. But is there a chance, you and your contributors could implement that feature, that enables me to create Waveform JSON Files, the same way as it is possible for PNG Images respecting --start and --end arguments? I can create a dedicated Issue here, if that helps. Otherwise I will find a way to workaround this limitation by using an already shortened WAV File.

chrisn commented 10 months ago

Well, it's just me in my spare time really - but yes. There's no need to create an issue.

chrisn commented 10 months ago

I'm going to look at this together with https://github.com/bbc/audiowaveform/issues/157, as they're related.