HearthSim/python-fsb5

libogg and libvorbis requirement + note for Windows

murkymark opened this issue · 7 comments

The readme says

libogg and libvorbis are required to decode ogg samples

What do you mean with "decode"? It sounds like decompressing to PCM format. But probably means reading some format header attributes or verify the file format?

Then it says

If ogg files are not required to be decoded then the libraries are not required.

There is no option to skip "decoding" when using "extract.py". But it seems if the input file contains Ogg Vorbis, then it automatically tries to load the shared libraries and aborts if library loading fails.

Can you add a simple "raw" option without the need for extra libraries to "extract.py"?

Note for Windows:
Working DLL files are available here: http://www.rarewares.org/ogg-libraries.php
When using "extract.py" you may copy the libs into the same directory.
Make sure the name is (rename if needed):
"libvorbis.dll" (just "vorbis.dll" fails)
"libogg.dll"

I've tested on a Unity3D ".resource" file containing hundreds of FSB5 files under Windows and it worked great.

What do you mean with "decode"? It sounds like decompressing to PCM format. But probably means reading some format header attributes or verify the file format?

for PCM sound files fsb just stores the sound, for MPEG it stores the content but cuts off the header but for vorbis it encodes the sound into a stream of vorbis packets.

Currently to decode the packets back to an ogg file I use libogg and libvorbis through ctypes which are only imported when a vorbis sample is requested to be decoded.

If you want the raw vorbis packet stream then you could use the code from the library usage in the example but don't use rebuild_sample which is the function that does the ogg rebuilding.

i.e.

import fsb5

# read the file into a FSB5 object
with open('sample.fsb', 'rb') as f:
  fsb = fsb5.FSB5(f.read())

print(fsb.header)

# iterate over samples
for sample in fsb.samples:
  # print sample properties
  print('''\t{sample.name}.{extension}:
  Frequency: {sample.frequency}
  Channels: {sample.channels}
  Samples: {sample.samples}'''.format(sample=sample, extension=ext))

  # rebuild the sample and save
  with open('{0}.bin'.format(sample.name), 'wb') as f:
    f.write(sample)

Copying the libs to the same directory doesn't work for me :(

Traceback (most recent call last):
  File "D:\Users\Kim\Documents\DuOS-shared\bundles\extractfsb.py", line 131, in <module>
    main()
  File "D:\Users\Kim\Documents\DuOS-shared\bundles\extractfsb.py", line 127, in main
    exit(app.run(sys.argv[1:]))
  File "D:\Users\Kim\Documents\DuOS-shared\bundles\extractfsb.py", line 121, in run
    self.handle_file(f)
  File "D:\Users\Kim\Documents\DuOS-shared\bundles\extractfsb.py", line 110, in handle_file
    for sample_fakepath, sample_name, sample_data in self.read_samples(fakepath_prefix, fsb, ext):
  File "D:\Users\Kim\Documents\DuOS-shared\bundles\extractfsb.py", line 86, in read_samples
    yield sample_fakepath, sample.name, fsb.rebuild_sample(sample)
  File "D:\Python\Python35\lib\site-packages\fsb5\__init__.py", line 212, in rebuild_sample
    from . import vorbis
  File "D:\Python\Python35\lib\site-packages\fsb5\vorbis.py", line 12, in <module>
    vorbis = load_lib('vorbis')
  File "D:\Python\Python35\lib\site-packages\fsb5\utils.py", line 76, in load_lib
    raise LibraryNotFoundException('Could not load the library %r' % (names[0]))
fsb5.utils.LibraryNotFoundException: Could not load the library 'vorbis'

Note for Windows:
...
Make sure the name is (rename if needed):
"libvorbis.dll" (just "vorbis.dll" fails)
"libogg.dll"

I did rename them like that, but it doesn't work.
By "same directory" do you mean the directory in which unityextract.py is stored? If so, that's where I have the libraries.

Also I'm not sure if I got the correct libogg.dll, could that be an issue?
for libvorbis I downloaded "libvorbis.dll using libVorbis v1.3.5", and copied libvorbis.dll
for libogg I downloaded "ogg vorbis dlls using libVorbis v1.3.5" and renamed ogg.dll to libogg.dll (is it supposed to be vorbis.dll in this case?)

Copy the two DLL files to the same directory as "extract.py". Open a command line window and make sure the current working directory is the one with "extract.py".

I have the directory "fsb5" and "scripts" as subdirectory of "extract.py". Then I run "py extract.py ..."

In general whenever you have a "file not found" error "https://technet.microsoft.com/en-us/sysinternals/processmonitor" can log all IO accesses of a process, also the failed ones.

Those versions should be fine, as @murkymark said just make sure the DLLs are next to extract.py

I've created a release with the correct directory structure and DLLs that work for me on windows
https://github.com/HearthSim/python-fsb5/releases/tag/b7bf605

Okay, it works only with the DLLs bundled with the release zip. It didn't work with the DLLs I grabbed from the Rarewares website for some reason. I use Windows 10 x64 build 14393