Module: Cohere::Transcribe::Audio::FFmpegNative

Defined in:
lib/cohere/transcribe/audio/ffmpeg_native.rb

Overview

Lazy binding for the gem's subprocess-free libav decoder adapter. The adapter itself dynamically selects a compatible FFmpeg 4-8 runtime; Ruby never launches ffmpeg and does not retain a Python codec runtime.

Defined Under Namespace

Classes: Library

Constant Summary collapse

ERROR_CAPACITY =
1_024
CANCELLED_STATUS =
6
DECODED_AUDIO_LIMIT_STATUS =
4
CANCELLATION_JOIN_INTERVAL =
0.01

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


277
278
279
280
281
282
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 277

def available?
  library
  true
rescue TranscriptionRuntimeError
  false
end

.avutil_majorObject



290
291
292
293
294
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 290

def avutil_major
  library.avutil_major
rescue TranscriptionRuntimeError
  nil
end

.cancel_active!Object

Pipeline cleanup must not load FFmpeg merely to discover that no native decode has ever started. If the adapter is already resident, this wakes every operation that captured an older cancellation generation while preserving later independent calls.



320
321
322
323
324
325
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 320

def cancel_active!
  Library.loaded&.cancel_all!
  nil
rescue Fiddle::DLError, TranscriptionRuntimeError
  nil
end

.cancel_all!Object



310
311
312
313
314
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 310

def cancel_all!
  library.cancel_all!
rescue TranscriptionRuntimeError
  nil
end

.decode(path, sample_rate:, max_decoded_bytes:) ⇒ Object



302
303
304
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 302

def decode(path, sample_rate:, max_decoded_bytes:)
  library.decode(path, sample_rate: sample_rate, max_decoded_bytes: max_decoded_bytes)
end

.diagnosticObject



284
285
286
287
288
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 284

def diagnostic
  library.diagnostic
rescue TranscriptionRuntimeError => e
  e.message
end

.duration(path) ⇒ Object



306
307
308
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 306

def duration(path)
  library.duration(path)
end

.ffmpeg_versionsObject



296
297
298
299
300
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 296

def ffmpeg_versions
  library.ffmpeg_versions
rescue TranscriptionRuntimeError
  nil
end

.libraryObject



273
274
275
# File 'lib/cohere/transcribe/audio/ffmpeg_native.rb', line 273

def library
  Library.load
end