Skip to main content

encode_for_upload

Function encode_for_upload 

Source
pub async fn encode_for_upload(
    samples: &[f32],
    max_bytes: usize,
) -> Result<(PathBuf, &'static str)>
Expand description

Encode samples to a compressed temp file for remote upload (JOE-1648).

Returns (path, format) where format is "mp3" or "wav". Caller must delete path when done.

MP3 encoding uses the same supervised FFmpeg lifecycle as decode: -nostdin, concurrent stderr drain, wall-clock deadline, kill+reap on failure. Destination is exclusively created (no -y clobber).

WAV fallback is only for encoder/codec conversion failures (missing libmp3lame, non-zero FFmpeg exit for encode reasons). Cancellation, absolute deadline expiry, and size-cap violations never fall back to a successful WAV (JOE-1648 third-pass residual).