pull in go-ffmpreg v0.4.1

This commit is contained in:
kim 2024-10-27 16:19:59 +00:00
commit 3623f4dd2e
9 changed files with 163 additions and 51 deletions

View file

@ -21,19 +21,13 @@ package ffmpeg
import (
"context"
"os"
ffmpeglib "codeberg.org/gruf/go-ffmpreg/embed/ffmpeg"
ffprobelib "codeberg.org/gruf/go-ffmpreg/embed/ffprobe"
"codeberg.org/gruf/go-ffmpreg/wasm"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
)
// Use all core features required by ffmpeg / ffprobe
// (these should be the same but we OR just in case).
const corefeatures = wasm.CoreFeatures
var (
// shared WASM runtime instance.
runtime wazero.Runtime
@ -91,38 +85,10 @@ func compileFfprobe(ctx context.Context) error {
// initRuntime initializes the global wazero.Runtime,
// if already initialized this function is a no-op.
func initRuntime(ctx context.Context) error {
func initRuntime(ctx context.Context) (err error) {
if runtime != nil {
return nil
}
var cache wazero.CompilationCache
if dir := os.Getenv("GTS_WAZERO_COMPILATION_CACHE"); dir != "" {
var err error
// Use on-filesystem compilation cache given by env.
cache, err = wazero.NewCompilationCacheWithDir(dir)
if err != nil {
return err
}
}
// Prepare config with cache.
cfg := wazero.NewRuntimeConfig()
cfg = cfg.WithCoreFeatures(corefeatures)
cfg = cfg.WithCompilationCache(cache)
// Instantiate runtime with prepared config.
rt := wazero.NewRuntimeWithConfig(ctx, cfg)
// Instantiate wasi snapshot preview features into runtime.
_, err := wasi_snapshot_preview1.Instantiate(ctx, rt)
if err != nil {
return err
}
// Set runtime.
runtime = rt
return nil
runtime, err = wasm.NewRuntime(ctx, nil)
return
}