Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing OGG produces an empty file #130

Closed
mgeier opened this issue Apr 14, 2015 · 22 comments
Closed

Writing OGG produces an empty file #130

mgeier opened this issue Apr 14, 2015 · 22 comments
Labels
Milestone

Comments

@mgeier
Copy link
Contributor

mgeier commented Apr 14, 2015

I don't know if I'm doing something wrong, but this produces an OGG file with zero frames:

import soundfile as sf
import numpy as np
a = np.empty(100000)
sf.write(a, 'delme.ogg', 44100)

This doesn't seem to depend on my libsndfile binary, since the same error happens both on Debian Linux and on Windows XP 32bit.
To be sure, I compiled a little test program in C, which correctly writes a non-empty OGG file (this I tried only on Linux), so it cannot really be related to my installed version of libsndfile, or can it?

Any ideas what's wrong?

Can anybody write OGG files with PySoundFile?

Reading OGGs works perfectly, BTW ...
Writing other formats, too ...

@bastibe bastibe added the bug label Apr 15, 2015
@bastibe
Copy link
Owner

bastibe commented Apr 15, 2015

I can confirm this on OS X. Ideally, our tests should have caught this!

@mgeier
Copy link
Contributor Author

mgeier commented Apr 15, 2015

Thanks for confirming this ... I have still no clue what's going on here ...

I originally thought it was enough to test only one format and rely on libsndfile that all others work, too.
But it looks like this isn't libsndfile's fault ... does that mean we have to test every single supported file format?
I think this would be quite tedious ...
See also #52.

Regardless of this bug, we should probably add tests for FLAC and OGG anyway, since those could mistakenly be disabled in the shared library file.

I guess a test for writing and afterwards reading FLAC is simple, since it's lossless, but I'm not sure how to test the contents of an OGG file.
But even checking only the length of the stored data would have exposed the current issue.

@mgeier mgeier modified the milestone: 0.7.1 Apr 15, 2015
@mgeier mgeier modified the milestones: 0.7.1, 0.7.x May 16, 2015
@bastibe
Copy link
Owner

bastibe commented Oct 2, 2015

More experiments:

import numpy as np
import soundfile as sf
f = sf.SoundFile('delme.ogg', 'w', 44100, 1)
f.write(np.random.randn(10000)) 

works fine on my machine (Linux, libsndfile 1.0.25-9.1, pysoundfile HEAD).

However, if I write more than a few seconds, I get a SIGSEGV instead.

Furthermore, if I write less than 10000 frames or so, subsequent long writes segfault as well.

Yet, if I first write something between 10000 frames and a few seconds, then subsequent writes work perfectly fine, but do not write the last half second or so to the file. flush does not help with the last second.

And then all audio data vanishes from the file on close.

To be honest, it seems very unlikely that this is a problem on our end.

@mgeier
Copy link
Contributor Author

mgeier commented Oct 2, 2015

That's very interesting!

When I replace np.empty() with np.random.randn() in my original example, the written file is not empty anymore! But there are still a few samples missing, I was writing 100000 frames and only 77504 ended up in the OGG file. However, if I try the same thing in C, I get exactly 100000 frames in the OGG file.

The thing with the segmentation fault is also interesting ... I couldn't find a fixed size where this happens, I had a crash with 1.500.000 samples once, but another time it just worked.
This crash also happens in the C version, so this definitely doesn't have anything to do with us.

Here's the C test file ogg_problem.c:

#include <stdlib.h>
#include <sndfile.h>

static const unsigned int LENGTH = 100000;

int main() {
  float data[LENGTH];
  SNDFILE* sf;
  SF_INFO sfinfo;
  sfinfo.samplerate = 44100;
  sfinfo.channels = 1;
  sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS;
  sf = sf_open("delme.ogg", SFM_WRITE, &sfinfo);
  if (!sf)
  {
    printf("error!\n");
    exit(99);
  }
  sf_count_t written = sf_writef_float(sf, data, LENGTH);
  printf("written: %d\n", written);
  sf_close(sf);
}

And a Makefile:

LDLIBS = -lsndfile

all: ogg_problem

@bastibe bastibe modified the milestones: 0.8.x, future Oct 4, 2015
@tico-tico
Copy link

Have you tried libsndfile-1.0.26pre6 from here http://www.mega-nerd.com/tmp/ ? I can't reproduce the bug (empty OGG) with this pre on Win x64.

@lcouka
Copy link

lcouka commented Apr 12, 2017

Hello,
Does the issue get fixed please ? I just downloaded the last version of libsndfile 1.0.28, but I always get the .ogg bug.
Cheers,
Louis

@bastibe
Copy link
Owner

bastibe commented Apr 12, 2017

I believe we are currently shipping libsndfile 1.0.27 in the Windows and macOS wheels.

At what version was this supposed to be fixed?

@lcouka
Copy link

lcouka commented Apr 12, 2017

I believe we are currently shipping libsndfile 1.0.27 in the Windows and macOS wheels.

Exactly, that's why I tested with the lastest version but with no success.

At what version was this supposed to be fixed?

No one, but since the topic is 2 years old I wanted to know if there was any news.
Anyway thanks for your lib, which is very clean to use.
Cheers,
Louis

@bastibe
Copy link
Owner

bastibe commented Apr 13, 2017

It appears that the problem still exists today with libsndfile 1.0.27.

@lcouka
Copy link

lcouka commented Apr 13, 2017

Unfortunately yes, and still with libsndfile 1.0.28.

@wgaylord
Copy link

Still broken apparently.

@wgaylord
Copy link

wgaylord commented Sep 8, 2017

No ideas to fix this?

@greaber
Copy link

greaber commented Oct 4, 2018

This still seems to be broken. I haven't experienced seg faults, but when I write ogg files, the ends are very often cut off, which makes it sort of unusable. We care considering switching back to wav, but that would be unfortunate since ogg really saves a lot of space.

@hagenw
Copy link

hagenw commented Oct 26, 2018

I can confirm that this issue depends on the libsndfile version used.
I tested it by creating ogg files with a duration of 1s using different sampling rates and number of channels. Under libsndfile 1.0.27-3 on Debian it works as expected. With libsndfile 1.0.25-10ubuntu0.16.04.1 on Ubuntu I got the following strange results that show even an interaction with the number of channels:

Number of samples Number of channels Written number of samples in ogg file
48000 1 0
8000 1 0
48000 2 0
8000 2 0
48000 8 32320
8000 8 0
48000 255 43584
8000 255 5888

@lcouka and @bastibe: as I was not able to reproduce the error under libsndfile 1.0.27 what did you do to get the error there?

@xhain
Copy link

xhain commented Feb 2, 2021

I have this same error.
For me, soundfile even crashes the Python kernel - both when running on Google colab or locally on OSX (via Spyder).
A file is written to disk before the crash, but it's empty: the channels contain no data at all.
So far it only happened with files of a certain length.

/Edit:
How can I find out which libsoundfile version my soundfile module is using?
Which would be the correct libsoundfile version to use?

@bastibe
Copy link
Owner

bastibe commented Feb 3, 2021

You can query soundfile.__libsndfile_version__ to get the version of soundfile you are using.

By the way, you say you are using "PySoundFile", which is severely outdated. Please install "soundfile" instead, which is the current version.

@xhain
Copy link

xhain commented Feb 3, 2021

Thanks for the advice!
I am using soundfile not PySoundfile. I corrected that typo.

@cwainwright
Copy link

cwainwright commented Sep 8, 2021

Any updates on this issue? Using Python 3.7 with the latest version of soundfile and anytime I try to write a sample numpy array to .ogg I always get an empty file.

@hagenw
Copy link

hagenw commented Sep 10, 2021

Which version of libsndfile and file are you using?
As stated above for me it did work with 1.0.27, but not 1.0.25

@RonaldAJ
Copy link

RonaldAJ commented Sep 14, 2021

I seem to have the same problem using libsndfile1 1.0.28-7ubuntu0.1 with soundfile.__version__: 0.10.3.post1.

I see no easy option for downgrading libsndfile1 to 1.0.27.

@umlaeute
Copy link

i just tested with libsndfile-1.2.0 (as packaged in Debian, and afaict, the issue is gone)

@bastibe
Copy link
Owner

bastibe commented Feb 21, 2023

That's wonderful news, thank you for following up on this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests