Overview
Audio extraction processor family.
This package provides processors for extracting audio tracks from video files for audio-to-text conversion.
Exported Classes
AudioExtractionProcessor-- Abstract base for audio extraction.GstAudioExtractionProcessor-- GStreamer-based audio extraction.GstAudioExtractionConfig-- GStreamer audio extraction configuration.GstAudioExtractionProcessConfig-- GStreamer audio extraction process config.
AudioExtractionProcessor()
Bases: BackendSelectableProcessor[Attachment, Attachment], ABC
Family base for extracting audio tracks from video attachments.
This class serves as a unified entry point for audio extraction operations. It automatically routes requests to the most appropriate, available backend implementation based on your system environment.
Why use this base class?
- Portability: Your code will run regardless of which underlying libraries are installed on the host machine.
- Simplicity: No need to handle fallback logic or conditional imports yourself.
- Future-proofing: New backends can be added to the library without requiring changes to your application code.
Usage Example
from gllm_multimodal.media_toolkit.processor.audio_extraction_processor import AudioExtractionProcessor
from gllm_inference.schema import Attachment
# Instantiates the best available backend automatically
processor = AudioExtractionProcessor.build()
attachment = Attachment(url="file:///path/to/video.mp4")
audio_attachment = processor(attachment)
from gllm_multimodal.media_toolkit.processor.audio_extraction_processor import AudioExtractionProcessor
from gllm_inference.schema import Attachment
# Explicitly force the ffmpeg backend
processor = AudioExtractionProcessor.build(backend="ffmpeg")
attachment = Attachment(url="file:///path/to/video.mp4")
audio_attachment = processor(attachment)
from gllm_multimodal.media_toolkit.processor.audio_extraction_processor import AudioExtractionProcessor
from gllm_inference.schema import Attachment
# Explicitly force the moviepy backend
processor = AudioExtractionProcessor.build(backend="moviepy")
attachment = Attachment(url="file:///path/to/video.mp4")
audio_attachment = processor(attachment)
GstAudioExtractionConfig
Bases: GstBaseConfig
Configuration for GstAudioExtractionProcessor.
Attributes:
| Name | Type | Description |
|---|---|---|
sample_rate |
int | None
|
Force output sample rate in Hz (e.g. |
channels |
int | None
|
Force output channel count (e.g. |
output_format |
str | None
|
Preferred container/extension to extract to
( |
audio_encoder |
str | None
|
Pin a specific GStreamer audio encoder element
(e.g. |
GstAudioExtractionProcessConfig
Bases: ProcessorProcessConfig
Per-invocation configuration for process.
Attributes:
| Name | Type | Description |
|---|---|---|
sample_rate |
int | None
|
Force output sample rate in Hz. |
channels |
int | None
|
Force output channel count. |
GstAudioExtractionProcessor(config=None)
Bases: BaseGstreamerProcessor, AudioExtractionProcessor
Extracts the audio track from a video Attachment using GStreamer.
The processor demuxes the input video, re-encodes (or passes through) the
audio into the best available format, and returns the result as an
Attachment whose mime_type reflects the audio container.
If the video has no audio track the original Attachment is returned
unchanged, so callers do not need to handle None.
Attributes:
| Name | Type | Description |
|---|---|---|
audio_encoder_info |
EncoderFormatInfo | None
|
Selected audio encoder format info. |
config |
GstAudioExtractionConfig
|
Runtime configuration. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If GStreamer is unavailable or no suitable audio encoder is found. |
ValueError
|
If |
Example
processor = GstAudioExtractionProcessor(config={"output_format": "mp3"})
audio_attachment = await processor.process(video_attachment)
# audio_attachment.mime_type == "audio/mpeg"
# audio_attachment.filename == "audio_my_video.mp3"
Initialise GStreamer and select the audio encoder / output format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | GstAudioExtractionConfig | None
|
Optional
configuration. A plain |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If GStreamer is unavailable or no audio encoder is found. |
ValueError
|
If |
config_model()
classmethod
Return the stable configuration model for this processor.
Returns:
| Type | Description |
|---|---|
type[GstAudioExtractionConfig]
|
type[GstAudioExtractionConfig]: The configuration class used at |
type[GstAudioExtractionConfig]
|
construction time for stable (per-instance) settings. |
process_config_model()
classmethod
Return the per-invocation configuration model for this processor.
Returns:
| Type | Description |
|---|---|
type[GstAudioExtractionProcessConfig]
|
type[GstAudioExtractionProcessConfig]: The configuration class |
type[GstAudioExtractionProcessConfig]
|
accepted by |