Giter VIP home page Giter VIP logo

python-fsb5's Introduction

python-fsb5

Python library and tool to extract FSB5 (FMOD Sample Bank) files.

Supported formats

  • MPEG
  • Vorbis (OGG)
  • WAVE (PCM8, PCM16, PCM32)

Other formats can be identified but will be extracted as .dat files and may not play as the headers may be missing.

Tool Usage

usage: extract.py [-h] [-o OUTPUT_DIRECTORY] [-p] [-q]
                  [fsb_file [fsb_file ...]]

Extract audio samples from FSB5 files

positional arguments:
  fsb_file              FSB5 container to extract audio from (defaults to
                        stdin)

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY
                        output directory to write extracted samples into
  -q, --quiet           suppress output of header and sample information
                        (samples that failed to decode will still be printed)

Resource files

Unity3D packs multiple FSB5 files each containing a single sample into it's .resource files. python-fsb5 will automatically extract all samples if multiple FSB5s are found within one file. Output files will be prefixed with the (0 based) index of their FSB container within the resource file e.g. out/sounds-15-track1.wav is the path for a WAVE sample named track1 which is contained within the 16th FSB file within sounds.resource.

Unnamed samples

FSB5 does not require samples to store a name. If samples are stored without a name they will use their index within the FSB e.g. sounds-0000.mp3 is the first sample in sounds.fsb.

Requirements

python-fsb5 should work with python3 from version 3.2 and up.

libogg and libvorbis are required to decode ogg samples. For linux simply install from your package manager. For windows ensure the dlls are avaliable (ie. in System32 or the directory you are running the script from). Known working dlls are avaliable as part of the release.

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

Library usage

import fsb5

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

print(fsb.header)

# get the extension of samples based off the sound format specified in the header
ext = fsb.get_sample_extension()

# 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}.{1}'.format(sample.name, ext), 'wb') as f:
    rebuilt_sample = fsb.rebuild_sample(sample)
    f.write(rebuilt_sample)

Useful header properties

  • numSamples: The number of samples contained in the file
  • mode: The audio format of all samples. Can be one of:
  • fsb5.SoundFormat.NONE
  • fsb5.SoundFormat.PCM8
  • fsb5.SoundFormat.PCM16
  • fsb5.SoundFormat.PCM24
  • fsb5.SoundFormat.PCM32
  • fsb5.SoundFormat.PCMFLOAT
  • fsb5.SoundFormat.GCADPCM
  • fsb5.SoundFormat.IMAADPCM
  • fsb5.SoundFormat.VAG
  • fsb5.SoundFormat.HEVAG
  • fsb5.SoundFormat.XMA
  • fsb5.SoundFormat.MPEG
  • fsb5.SoundFormat.CELT
  • fsb5.SoundFormat.AT9
  • fsb5.SoundFormat.XWMA
  • fsb5.SoundFormat.VORBIS

Useful sample properties

  • name : The name of the sample, or a 4 digit number if names are not provided.
  • frequency : The sample rate of the audio
  • channels : The number of channels of audio (either 1 or 2)
  • samples : The number of samples in the audio
  • metadata : A dictionary of fsb5.MetadataChunkType to tuple (sometimes namedtuple) or bytes.

All contents of sample.metadata is optional and often not provided. Several metadata types seem to override sample properties.

Supported fsb5.MetadataChunkTypes are:

  • CHANNELS: A 1-tuple containing the number of channels
  • FREQUENCY: A 1-tuple containing the sample rate
  • LOOP: A 2-tuple of the loop start and end
  • XMASEEK: Raw bytes
  • DSPCOEFF: Raw bytes
  • XWMADATA: Raw bytes
  • VORBISDATA: A named tuple with properties crc32 (int) and unknown (bytes)

If a metadata chunk is unrecognized it will be included in the dictionary as an interger mapping to a bytes.

Rebuilding samples

Samples also have the data property. This contains the raw, unprocessed audio data for that sample from the FSB file. To reconstruct a playable version of the audio use rebuild_sample on the FSB5 object passing the sample desired to be rebuilt.

License

python-fsb5 is licensed under the terms of the MIT license. The full text of the license is available in the LICENSE file.

python-fsb5's People

Contributors

jleclanche avatar mactastic1-5 avatar robert-nix avatar synap5e avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-fsb5's Issues

Extract Using Android

Extract using Android I found this error when extract fsb.

"/data/data/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/1ib-dynload/_ctypes.cpython-39.so" is not accessible for the namespace "(default)"

Unknown CRC32 for some vorbis samples

Some vorbis samples fail to decode as the crc32 is not known, so the encoding options cannot be derived.

This seems to have something to do with specifying quality when creating samples with Unity3D's fsbtool.

Files automatically overwritten...

I'm trying to extract an FSB wich contain some duplicated name...

So if i have 5 time DUPLICA1.OGG i got only 1 file and not 5 with a number ex:

DUPLICA1.WAV
DUPLICA1-2.WAV
DUPLICA1-3.WAV
DUPLICA1-4.WAV
DUPLICA1-5.WAV

How i can extract all the 1275 files and not the half 700 because of that conflict?

Thank

What's with the discrepancy in the b7bf605 release?

I don't know how github releases are usually supposed to work, but I noticed that in here, the "fsb5" folder between the source code release (python-fsb5-b7bf605.zip) and the standalone program releases (both Win32 and Win64) contain different versions of some files. (In the standalone program, vorbis_headers.py is 2.2MB rather than 5KB and covers some lookup cases that the latter definitely misses.)

I don't know if this is the source of the problem, but I also noticed that trying to install python-fsb5 as a module (via pip - I think? It was a while back...) installs the source code version of the relevant files. It was a bit of a drag for me to figure out what was the problem, and probably will be a drag for others too. How can we fix this?

无法运行

python extract.py -o a 8013_1.fsb

Traceback (most recent call last):
File "extract.py", line 131, in
main()
File "extract.py", line 127, in main
exit(app.run(sys.argv[1:]))
File "extract.py", line 121, in run
self.handle_file(f)
File "extract.py", line 110, in handle_file
for sample_fakepath, sample_name, sample_data in self.read_samples(fakepath_prefix, fsb, ext):
File "extract.py", line 86, in read_samples
yield sample_fakepath, sample.name, fsb.rebuild_sample(sample)
File "C:\1\fsb5jb\fsb5_init_.py", line 211, in rebuild_sample
from . import vorbis
File "C:\1\fsb5jb\fsb5\vorbis.py", line 12, in
vorbis = load_lib('vorbis')
File "C:\1\fsb5jb\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'

libogg and libvorbis requirement + note for Windows

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.

Occasionally failed output

Hello,

I'm trying to retrieve .ogg's from .fsb files extracted from Deus Ex: Mankind Divided, using your program (64-bit version). While most of them process correctly, some of files produce illegible noise. Here's an example of such a file. Would you know what could be wrong with it and how can it be fixed?

Thanks.

one question&bug

win 7 64
python27

There is a mistake

cmd
python extract.py

File "extract.py",line 29
def print <self,*args>:
SyntaxError: invalid syntax

How to deal with it???

ValueError: 16 is not a valid SoundFormat

I am unable to convert FSB version 5 files.

Command:

python3 extract.py file.fsb

Error Message:

Traceback (most recent call last):
  File "C:\python-fsb5_win64\extract.py", line 131, in <module>
    main()
  File "C:\python-fsb5_win64\extract.py", line 127, in main
    exit(app.run(sys.argv[1:]))
  File "C:\python-fsb5_win64\extract.py", line 121, in run
    self.handle_file(f)
  File "C:\python-fsb5_win64\extract.py", line 99, in handle_file
    fsb, ext = self.load_fsb(data)
  File "C:\python-fsb5_win64\extract.py", line 55, in load_fsb
    fsb = fsb5.load(data)
  File "C:\python-fsb5_win64\fsb5\__init__.py", line 230, in load
    return FSB5(data)
  File "C:\python-fsb5_win64\fsb5\__init__.py", line 124, in __init__
    self.header = self.header._replace(mode=SoundFormat(self.header.mode), size=buf.tell())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\enum.py", line 384, in __call__
    return cls.__new__(cls, value)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\enum.py", line 702, in __new__
    raise ve_exc
ValueError: 16 is not a valid SoundFormat

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.