Solve 2 transcription problems: Video input and big input
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- php
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- PHP
- スター
- 78
- フォーク
- 42
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nextcloud/integration_openai のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
nextcloud/integration_openai#480 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
nextcloud/integration_openai#477 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
nextcloud/integration_openai#471 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Vllm rejecting requests that have empty tools list対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
nextcloud/integration_openai#448 · コメント 3 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Chunked text processing silently drops the end of long texts対応中かも @nonofr91 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
nextcloud/integration_openai#478 ·
メンテナーはふだん 1 日以内に返信
nextcloud/integration_openai の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
Automattic/static-site-importer#3462 ·
メンテナーはふだん 1 日以内に返信
-
Document lexicon.default.userconfig and lexicon.default.userconfig.enforced in config.sample.phpオープンenhancement feature: settings good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
a11y
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
omeka/plugin-Contribution#84 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
recca0120/vscode-phpunit#620 ·
メンテナーはふだん 1 日以内に返信