Skip to main content

BestSource

build codespell

BestSource (abbreviated as BS) is a cross-platform wrapper library around FFmpeg that ensures always sample and frame accurate access to audio and video with good seeking performance for everything except some lossy audio formats.

It can be used as either a C++ library directly or through the combined VapourSynth and Avisynth+ plugin that's included.

Dependencies

  • FFmpeg 8.1.x and FFmpeg 8.0.x supported. Later releases may or may not work but FFmpeg API breakages are quite common and don't always generate compilation errors. Only libavcodec, libavformat, libavutil libraries are required.
  • xxHash

Windows Compilation

On Windows the easiest way to compile the the dependencies is to use vcpkg to install ffmpeg[avcodec,avdevice,avfilter,avformat,swresample,swscale,zlib,bzip2,core,dav1d,gpl,version3,lzma,nvcodec,qsv,vulkan,openssl,xml2]:x64-windows-static and xxhash:x64-windows-static. Do however note that this is without Little CMS2 support. Use the latest version of Visual Studio. It should automatically find all the required libraries if you used vcpkg.

Linux and MacOS Compilation

Requires pkg-config, meson and ninja-build.

git clone https://github.com/vapoursynth/bestsource.git --depth 1
cd bestsource
meson setup build
meson compile -C build
meson install -C build

Known issues and limitations

  • Seeking performance in mpeg/ts/vob files can be quite poor due to the FFmpeg demuxer
  • Seeking and decoding performance for lossy audio formats (aac, mp3, dts, ac3, vorbis) can be poor
  • VC1 codec is unseekable due to FFmpeg not having bitexact output after seeking
  • The unholy combination of VFR H264 in AVI has poor seeking performance
  • Needs FFmpeg compiled with Little CMS2 or the color information reported for most image files will be less complete
  • Mod files can't be decoded correctly using libmodplug due to the library not having repeatable bitexact output
  • Gray+alpha format isn't supported in Avisynth+ and as a result only the Y component is returned
  • Files with dimensions that aren't a multiple of the subsampling value will be cropped

VapourSynth usage

bs.AudioSource(string source[, int track = -1, int adjustdelay = -1, int threads = 0, bint enable_drefs = False, bint use_absolute_path = False, float drc_scale = 0, int cachemode = 1, string cachepath, int cachesize = 100, bint showprogress = True, maxdecoders = 0])

bs.VideoSource(string source[, int track = -1, int variableformat = -1, int fpsnum = -1, int fpsden = 1, bint rff = False, int threads = 0, int seekpreroll = 20, bint enable_drefs = False, bint use_absolute_path = False, int cachemode = 1, string cachepath , int cachesize = 100, string hwdevice, int extrahwframes = 9, string timecodes, int start_number, int viewid = 0, bint showprogress = True, maxdecoders = 0, bool hwfallback = True, exporttimestamps = False, bint apply_rotation = True])

bs.TrackInfo(string source[, bint enable_drefs = False, bint use_absolute_path = False])

bs.Metadata(string source[, int track, bint enable_drefs = False, bint use_absolute_path = False])

bs.SetDebugOutput(bint enable = False)

bs.SetFFmpegLogLevel(int level = <quiet log level>)

The TrackInfo function only returns the most basic information about a track which is the type, codec and disposition. Its main use is to be able to implement custom track selection logic for the source functions.

The Metadata function returns all the file or track metadata as key-value pairs depending on whether or not track is specified.

Avisynth+ usage

BSAudioSource(string source[, int track = -1, int adjustdelay = -1, int threads = 0, bool enable_drefs = False, bool use_absolute_path = False, float drc_scale = 0, int cachemode = 1, string cachepath, int cachesize = 100, int maxdecoders = 0])

BSVideoSource(string source[, int track = -1, int fpsnum = -1, int fpsden = 1, bool rff = False, int threads = 0, int seekpreroll = 20, bool enable_drefs = False, bool use_absolute_path = False, int cachemode = 1, string cachepath, int cachesize = 100, string hwdevice, int extrahwframes = 9, string timecodes, int start_number, int variableformat = 0, int viewid = 0, int maxdecoders = 0, bool hwfallback = True, bool apply_rotation = True])

BSSource(string source[, int atrack = -1, int vtrack = -1, int fpsnum = -1, int fpsden = 1, bool rff = False, int threads = 0, int seekpreroll = 20, bool enable_drefs = False, bool use_absolute_path = False, int cachemode = 1, string cachepath, int acachesize = 100, int vcachesize = 100, string hwdevice, int extrahwframes = 9, string timecodes, int start_number, int variableformat = 0, int adjustdelay = -1, float drc_scale = 0, int viewid = 0, int maxdecoders = 0, bool hwfallback = True, bool apply_rotation = True])

BSSetDebugOutput(bool enable = False)

BSSetFFmpegLogLevel(int level = <quiet log level>)

Note that the BSSource function by default will silently ignore errors when opening audio and in that case only return the video track. However if atrack is explicitly set failure to open the audio track will return an error.

Argument explanation

source: The source filename. Note that image sequences also can be opened by using %d or %03d for zero padded numbers. Sequences may start at any number between 0 and 4 unless otherwise specified with start_number. It's also possible to pass urls and other ffmpeg protocols like concat.

track: Either a positive number starting from 0 specifying the absolute track number or a negative number to select the nth audio or video track. Throws an error on wrong type or no matching track.

adjustdelay: Adjust audio start time relative to a video track number. Pass -2 to disable and -1 to be relative to the first video track if one exists. Specifying a non-video track is equivalent to passing -2. Note that the offset is always relative to the first CPU-decodable frame in the stream meaning that it may not be the correct delay when hwmode and variableformat are used.

variableformat: Allow format changes in the output for video. To only allow fixed format output pass 0 or greater to choose the nth encountered format as the output format. Any frames not matching the chosen format are dropped. If the file is constant format (most are) this setting does nothing.

fpsnum: Convert the source material to constant framerate. Cannot be combined with rff.

fpsden: Convert the source material to constant framerate. Used in conjunction with fpsnum.

rff: Apply RFF flags to the video. If the video doesn't have or use RFF flags the output is unchanged compare to when the option is disabled. Cannot be combined with fpsnum.

threads: Number of threads to use for decoding. Pass 0 to autodetect.

seekpreroll: Number of frames before the requested frame to cache when seeking.

enable_drefs: Option passed to the FFmpeg mov demuxer.

use_absolute_path: Option passed to the FFmpeg mov demuxer.

drc_scale: Apply dynamic range compression to ac3 audio. 0 = None and 1.0 = Normal.

cachemode:

0 = Never read or write index to disk
1 = Always try to read index but only write index to disk when it will make a noticeable difference on subsequent runs and store index files in a subtree of *cachepath*
2 = Always try to read and write index to disk and store index files in a subtree of *cachepath*
3 = Always try to read index but only write index to disk when it will make a noticeable difference on subsequent runs and store index files with *cachepath* used as the base filename with track number and index extension automatically appended 
4 = Always try to read and write index to disk and store index files with *cachepath* used as the base filename with track number and index extension automatically appended

cachepath: The path where cache files are written. Note that the actual index files are written into subdirectories using based on the source location. Defaults to %LOCALAPPDATA% on Windows and $XDG_CACHE_HOME/bsindex if set otherwise ~/bsindex on other operation systems in mode 1 and 2. For mode 3 and 4 it defaults to source.

cachesize: Maximum internal cache size in MB.

hwdevice: The interface to use for hardware decoding. Depends on OS and hardware. On windows d3d11va, cuda and vulkan (H264, HEVC and AV1) are probably the ones most likely to work. Defaults to CPU decoding. Will throw errors for formats where hardware decoding isn't possible.

extrahwframes: The number of additional frames to allocate when hwdevice is set. The number required is unknowable and found through trial and error. The default may be too high or too low. FFmpeg unfortunately is this badly designed.

timecodes: Writes a timecode v2 file with all frame times to the file if specified. Note that this option will produce an error if any frame has an unknown timestamp which would result in an invalid timecode file.

start_number: The first number of image sequences.

viewid: The view id to output, this is currently only used for some mv-hevc files and is quite rare.

showprogress: Print indexing progress as VapourSynth information level log messages.

maxdecoders: The maximum number of decoder instances kept around, defaults to 4 but when decoding high resolution content it may be beneficial to reduce it to 1 to reduce peak memory usage. For example 4k h264 material will use approximately 250MB of ram in addition to the specified cache size for decoder instance. Passing a number outside the 1-4 range will set it to the biggest number supported.

hwfallback: Automatically fall back to CPU decoding if hardware decoding can't be used for the current video track when hwdevice is set. Note that the fallback only happens when a hardware decoder is unavailable and not on any other category of error such as hwdevice having an invalid value.

apply_rotation: Apply the vertical flip and the rotation stored in the video track's display matrix so the output has the orientation the video is meant to be shown in. Note that mirroring is always reported as a vertical flip followed by a rotation. The FlipVertical and Rotation frame properties are set to 0 when enabled since the transform has already been applied. Only rotations that are a multiple of 90 degrees can be applied and anything else is an error. A 90 or 270 degree rotation of a format with non-square chroma subsampling, such as 4:2:2, is handled differently by the two plugins. Avisynth+ resamples the chroma planes and is therefore not lossless, whereas VapourSynth swaps the subsampling axes losslessly and outputs a different format than the source, 4:4:0 for a 4:2:2 source. In VapourSynth a rotation that isn't a multiple of 180 degrees additionally requires a constant format clip, so it can't be combined with a variableformat of -1 on a file that actually changes format.

exporttimestamps: Returns an additional array of all frame timestamps and its timebase in timebasenum and timebaseden containing all frame times addition to the video clip. Note that unknown timestamps can be set to AV_NOPTS_VALUE. Cannot be combined with rff and fpsnum modes.

level: The log level of the FFmpeg library. By default quiet. See FFmpeg documentation for allowed constants. Mostly useful for debugging purposes.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vapoursynth_bestsource-20.0.tar.gz (69.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vapoursynth_bestsource-20.0-py3-none-win_amd64.whl (12.3 MB view details)

Uploaded Python 3Windows x86-64

vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_x86_64.whl (14.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_aarch64.whl (13.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_x86_64.whl (13.5 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_aarch64.whl (12.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

vapoursynth_bestsource-20.0-py3-none-macosx_15_0_x86_64.whl (10.6 MB view details)

Uploaded Python 3macOS 15.0+ x86-64

vapoursynth_bestsource-20.0-py3-none-macosx_15_0_arm64.whl (8.9 MB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

Details for the file vapoursynth_bestsource-20.0.tar.gz.

File metadata

  • Download URL: vapoursynth_bestsource-20.0.tar.gz
  • Upload date:
  • Size: 69.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for vapoursynth_bestsource-20.0.tar.gz
Algorithm Hash digest
SHA256 2f49300672f0448daab5e42ac71ca42280132c4442e3cffd2542cebbbc4c9792
MD5 6ce4490d92b68eabf8aab98287c18c77
BLAKE2b-256 293c480d9a6ff1ba9b148b28b075d89fbf1a75c1b17ada065fd235c72cadd331

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0.tar.gz:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_bestsource-20.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for vapoursynth_bestsource-20.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 65e13f30b631238c263a567caeeaae7603b7f773d87bd17b1859e3dc1d5eb068
MD5 4a875c02ec685dc0c786d3f695f99b49
BLAKE2b-256 7ea1d8c3960fc581e704a83465838d9ed3ad076d661a5824c299c9245bd2d0fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0-py3-none-win_amd64.whl:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a947e866feeec4964e93991c5ecbb195430ab7b960fedc506f45eae68d2a0512
MD5 0661ebe0d041b681f0f2bdf86ad1b4ca
BLAKE2b-256 2cb6dfb3bced69c73fb51d716611cf679c078958eeba1e88f1ab76000f5cf49a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_x86_64.whl:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fc8d8c698ae6b22afce4ea75a90076f5655b4cf60b8e998bd0e9ab2a6d1654c2
MD5 31bd77f4835cb338a5fcbfc300c42298
BLAKE2b-256 011f39283872193efd93b775c86916071e3540d634ad12286957c295ac02de41

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0-py3-none-musllinux_1_2_aarch64.whl:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6a3e0a66b85003611fdf511b809b4098351cf094fc3a2a5209f4da88d3f8fedc
MD5 bb19ceb99d482fc1bfd35a61e8f56750
BLAKE2b-256 c92dfa130ad41b1803160a619f0d4b26f233ac105f512d05073ef0d872cb4e23

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f855a78a39ebd2ccce55c8aa80b8d6a770c0fca96a70f2ab4cb5a0326d743f77
MD5 3e0ca47f82d3ea688be7a56d94047374
BLAKE2b-256 028611c34c5404e3ea317c8053a08bcf739796886d1d6dea0df35608829368de

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_bestsource-20.0-py3-none-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_bestsource-20.0-py3-none-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 72ff33cddea47a6adee37decac2abd4a4b76be0b8e02351a912c374486e4c6c2
MD5 fe284c4b48a172a0d6f7fdc3f88ec5de
BLAKE2b-256 56b120a346db7aebff9b34b0d40934ff81f2761931bb170e381505558f7ff093

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0-py3-none-macosx_15_0_x86_64.whl:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_bestsource-20.0-py3-none-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for vapoursynth_bestsource-20.0-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e94a5565749f1ba027e0102cb8eef37608d40a626cf890ecf857d9ffc6dbf8a5
MD5 afab4a026040ff81b23a68f8464caf83
BLAKE2b-256 347e253e418c50a4fb42e850f8a44b294d8d4546039b5e1416cfeeea093dd0e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_bestsource-20.0-py3-none-macosx_15_0_arm64.whl:

Publisher: build.yml on vapoursynth/bestsource

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

21.0

8 files

This release

20.0 This release

8 files

19.0

8 files

18.0

10 files

17.0

6 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page