Solve 2 transcription problems: Video input and big input
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- php
- Ambito
- audio-video-rtc, backend
Direzione di ricerca
Start with OpenAiAPIService::transcribeFile() and the existing size check in AudioToTextSubtitlesProvider; compare the movie preview approach in lib/private/Preview/Movie.php. The issue proposes a new lib/Service/AudioTranscodingService.php, admin settings, and tests for transcoding decisions, ffmpeg handling, and output formats. First clarify the open questions about target format and segmentation; done means video and oversized audio are handled safely, with the 25 MB limit and subtitle timing behavior covered.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
TL;DR: We could try to use ffmpeg to extract the audio track of a video input. We could also transcode the audio to something light like 32 Kbps MP3 which is enough for voice content and safe in term of compatibility with the services we can connect to.
We could just fail if ffmpeg is not found.
Optional but quite necessary in the long run: If the transcoded audio is still > 25 MB, we could cut it into chunks, make one request per chunk, and reassemble the chunk transcriptions. For core:audio2text:subtitles, this is a little bit tricky to reassemble subtitle files but doable: we need to accurately shift the timestamps.
The following text was generated:
Audio extraction & transcoding for the transcription providers
Problem
The task-processing providers for speech-to-text (AudioToTextProvider, AudioToTextSubtitlesProvider, AudioToAudioTranslateProvider, AudioToAudioChatProvider) all converge on OpenAiAPIService::transcribeFile(), which sends the file content to the API as-is. Two consequences:
- Video files are sent untouched. OpenAI's Whisper API accepts
mp4/webmcontainers, but many self-hosted or OpenAI-compatible backends only accept real audio formats and reject them. - Large files fail. The API limit is 25 MB. An hour of compressed stereo video is easily 1 to 2 GB, and even a long audio recording often exceeds 25 MB. Today users just get a hard error (see the size check in
AudioToTextSubtitlesProvider).
Whisper itself always downsamples to 16 kHz mono, so everything above that is wasted bytes for our use case. Re-encoding to 16 kHz mono before upload loses nothing for transcription quality.
Proposed solution
Extract the audio stream from video files and transcode audio to a compact format before uploading, using ffmpeg on the Nextcloud server. This is the same approach core uses for movie previews (lib/private/Preview/Movie.php).
Typical results (16 kHz mono):
| Input | Output format | Size |
|---|---|---|
| 1 h 1080p H.264 video (~1.5 GB) | mp3 48 kbps | ~21 MB |
| 1 h stereo 256 kbps mp3 (~115 MB) | mp3 48 kbps | ~21 MB |
| 1 h 1080p video | opus 24 kbps | ~11 MB |
| 1 h WAV (~300 MB) | flac | ~30-40 MB |
1. Detecting when to transcode
In the pre-processing step (below), decide based on the node's mime type and size:
video/*→ extract audio (-vn) and compress → always transcode.audio/*under 25 MB in a format the API accepts (see the allowlist inAudioToTextSubtitlesProvider) → send as-is (current fast path, no CPU cost).audio/*over 25 MB, or in an exotic container → transcode.- Anything else (mime not
audio/orvideo/) → current validation error.
FileFormatDetector::getAudioExtension() (magic-byte based) can detect the actual format of the source bytes when the stored mime type is unreliable.
2. ffmpeg commands
Extraction and compression happen in one pass, no intermediate file needed:
# default target: mp3, safe for every Whisper-compatible API
ffmpeg -y -i input.mp4 -vn -ac 1 -ar 16000 -c:a libmp3lame -b:a 48k output.mp3
# smaller option (verify the backend accepts ogg/oga first)
ffmpeg -y -i input -vn -ac 1 -ar 16000 -c:a libopus -b:a 24k output.ogg
# lossless option (no quality debate, ~50-60% of WAV)
ffmpeg -y -i input -vn -ac 1 -ar 16000 -c:a flac output.flac
-vndrops the video stream (this alone handles the video case).-ac 1 -ar 16000downmixes to mono / 16 kHz, exactly what Whisper does internally, so no information relevant to transcription is lost.- Target format and bitrate should be a config choice; mp3 48k is the recommended default.
3. Implementation
New service: lib/Service/AudioTranscodingService.php
Responsibilities:
Server::get(IBinaryFinder::class)->findBinaryPath('ffmpeg')to locate the binary (result is cached by core). Distinguish "not installed" from "failed to run" in logs.- Write the source to a temp file via
Server::get(ITempManager::class)->getTemporaryFile(); runproc_openwith an array of arguments (never a shell string, so no escaping issues); read stderr before stdout to avoid the 64 KB pipe-buffer deadlock core already documented inMovie.php; always clean up temp files infinally. - Enforce a timeout (e.g. 10 min, configurable) and kill the process if exceeded.
- Return the transcoded content plus the detected extension (reuse
FileFormatDetector::getAudioExtension()on the output bytes).
Hook point: OpenAiAPIService::transcribeFile()
transcribeFile() is the single funnel for all four providers, so the logic belongs there (or in a method it delegates to), not in the providers:
File → mime/size decision → [transcode if needed] → transcribe(content)
transcribeBase64Mp3()(audio-recorder input) stays untouched, since it is already a small mp3.- The quota accounting in
transcribe()is duration-based (parsed from response timestamps), so transcoding does not affect it.
Filename detail
request() currently hardcodes the multipart filename file.mp3 for the audio part (around line 1470 of OpenAiAPIService.php). That happens to match the default target format, but it should derive from the actual bytes/extension so non-mp3 targets don't get mislabeled.
Admin configuration
Settings in the existing admin section (lib/Settings/Admin.php / OpenAiSettingsService):
- Transcoding mode:
auto(default, transcode only when needed per the rules above) /always(helpful to shrink uploads even when under the limit) /off. - ffmpeg binary path: optional override; falls back to
IBinaryFinder. - Target format & bitrate: default mp3 / 48k.
4. Edge cases and fallbacks
- ffmpeg not installed: degrade gracefully. Audio input under the limit works exactly as today; video input or oversized audio gets a clear user-facing error ("ffmpeg is required for video transcription / files over 25 MB"). Log a one-time warning at the admin level.
- Output still > 25 MB (very long recordings): fall back to time-based segmentation (
-f segment -segment_time 1200), transcribe chunks sequentially, concatenate text. For subtitles, timestamps must be offset-corrected per segment. This is the most complex part and could be phase 2; for phase 1, a clear error is acceptable. - Encrypted files: fine, because
File::getContent()returns decrypted content. The temp-file route works (unlike core's direct-download optimization). - Quota check order: the existing quota check in
transcribe()happens before any upload; transcoding costs CPU locally, so a cheap quota-rejected task should not transcode first. Keep the decision order: quota → transcode → upload.
5. Security considerations
proc_openwith array args only; no user-controlled strings reach the command line (paths are temp files we created).- Restrict the input to
audio/*/video/*before touching ffmpeg. - Timeouts and temp-file cleanup mandatory; never let a hung ffmpeg pin a task-processing worker.
- Admin-provided binary path: validate it points to an executable;
IBinaryFinderalready restricts to standard paths.
6. Testing
- Unit tests (
tests/): mockIBinaryFinderand the temp manager; cover the mime/size decision matrix, command construction, "ffmpeg missing" fallback, extension detection of the output bytes. When adding the new PHP file, runbuild/autoloaderchecker.sh. - Live validation: transcribe an
.mp4from a back end that rejects video containers, and a >25 MB audio file, with and without ffmpeg installed; confirm the 25 MB error path, quota bookkeeping, and subtitle timestamps for a video source.
Open questions
- Target format default: mp3 (safe) vs opus (smallest, backend-dependent) vs flac (lossless)?
- Should segmentation + timestamp offsetting be phase 2?
- Should
AudioToAudioTranslateProvideralso use transcoded audio as its translation input (it's speech-to-text based) while keeping the output audio path untouched? Presumably yes.
Assisted by OpenCode:GLM-5.3-Flash
- Lingua principale
- PHP
- Stelle
- 78
- Fork
- 42
- Merge medio
- 2g 21h
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nextcloud/integration_openai
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
nextcloud/integration_openai#480 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
nextcloud/integration_openai#477 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
nextcloud/integration_openai#471 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Vllm rejecting requests that have empty tools listForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
nextcloud/integration_openai#448 · 3 commenti · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Chunked text processing silently drops the end of long textsForse già presa @nonofr91 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
nextcloud/integration_openai#478 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di nextcloud/integration_openai
Issue simili
-
Document lexicon.default.userconfig and lexicon.default.userconfig.enforced in config.sample.phpApertaenhancement feature: settings good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
a11y
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
omeka/plugin-Contribution#84 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
recca0120/vscode-phpunit#620 ·
I maintainer di solito rispondono entro 1 giorno
-
Validation rule generation for recursive Data objects is unbounded (O(payload depth))Forse già presa @irfanm96 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
spatie/laravel-data#1226 ·