{"record":{"id":"b257724693339fdb","repo":"deezer/spleeter","slug":"ffmpeg-error-process-stderr-read","errorCode":null,"errorMessage":"FFMPEG error: {process.stderr.read()}","messagePattern":"FFMPEG error: (.+?)","errorType":"exception","errorClass":"SpleeterError","httpStatus":null,"severity":"error","filePath":"spleeter/audio/ffmpeg.py","lineNumber":184,"sourceCode":"        logger.debug(f\"Writing file {path}\")\n        input_kwargs = {\"ar\": sample_rate, \"ac\": data.shape[1]}\n        output_kwargs = {\"ar\": sample_rate, \"strict\": \"-2\"}\n        if bitrate:\n            output_kwargs[\"audio_bitrate\"] = bitrate\n        if codec is not None and codec != \"wav\":\n            output_kwargs[\"codec\"] = self.SUPPORTED_CODECS.get(codec, codec)\n        process = (\n            ffmpeg.input(\"pipe:\", format=\"f32le\", **input_kwargs)\n            .output(path, **output_kwargs)\n            .overwrite_output()\n            .run_async(pipe_stdin=True, pipe_stderr=True, quiet=True)\n        )\n        try:\n            process.stdin.write(data.astype(\"<f4\").tobytes())\n            process.stdin.close()\n            process.wait()\n        except IOError:\n            raise SpleeterError(f\"FFMPEG error: {process.stderr.read()}\")\n        logger.info(f\"File {path} written succesfully\")\n","sourceCodeStart":166,"sourceCodeEnd":186,"githubUrl":"https://github.com/deezer/spleeter/blob/c8854001ac8acad34a9bc2bd15f28475541828b1/spleeter/audio/ffmpeg.py#L166-L186","documentation":"When saving, spleeter pipes raw float32 PCM bytes into a running ffmpeg process's stdin. If writing to stdin, closing it, or waiting on the process raises IOError (typically because ffmpeg died and closed the pipe), spleeter wraps it in a `SpleeterError` containing ffmpeg's stderr output.","triggerScenarios":"Calling `adapter.save(path, data, sample_rate, ...)` where the spawned ffmpeg process exits early or fails: bad codec/bitrate combination, unsupported output extension, ffmpeg crashing on the data shape/channels.","commonSituations":"Requesting an exotic codec or bitrate (e.g. with `codec='aac'` and an unsupported bitrate), writing to a filename with an extension ffmpeg cannot infer a format from, out-of-memory kill of the ffmpeg process, or incompatible `strict -2` format options.","solutions":["Read the embedded ffmpeg stderr in the error message for the concrete ffmpeg failure","Try a safe default first: `codec='wav'` with no bitrate to isolate the issue","Validate the codec/bitrate/filename-extension combination is supported by your ffmpeg build (`ffmpeg -codecs`)"],"exampleFix":"// before\nadapter.save('out.ogg', data, 44100, codec='opus', bitrate='999k')\n// after\nadapter.save('out.wav', data, 44100, codec='wav')  # confirm pipeline works, then retry desired codec","handlingStrategy":"try-catch","validationCode":"# sanity-check inputs before saving\nimport shutil\nassert shutil.which('ffmpeg') is not None\nassert data.ndim == 2, 'data must be (samples, channels)'\nextension = path.rsplit('.', 1)[-1].lower()\nassert extension in ('wav', 'mp3', 'ogg', 'flac', 'm4a'), f'unsupported extension: {extension}'","typeGuard":null,"tryCatchPattern":"try:\n    adapter.save(path, data, sample_rate, codec='wav')\nexcept Exception as e:\n    if 'FFMPEG error' in str(e):\n        logger.error('ffmpeg failed writing %s: %s', path, str(e))\n        adapter.save(path.with_suffix('.wav'), data, sample_rate, codec='wav')\n    else:\n        raise","preventionTips":["Start with codec='wav' and no bitrate; only add codec/bitrate after verifying ffmpeg support","Check `ffmpeg -codecs` for codec/bitrate availability in your build","Ensure data is float32 with shape (samples, channels) and sample_rate matches content"],"tags":["ffmpeg","subprocess","file-io","pipe"],"backgroundTag":"ffmpeg-write-failed","analyzedSha":"c8854001ac8acad34a9bc2bd15f28475541828b1","analyzedAt":"2026-08-28T21:38:40.142Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}