Investigate slow 'preparing' phase #18

Open
opened 2026-06-21 18:01:14 +00:00 by Kessinen · 0 comments
Owner

The 'preparing' phase (everything before the video encode) can last a long time. Likely contributors, roughly in order:

  • Audio extraction decodes the entire audio to a PCM wav (a full decode pass per audio stream), then opusenc encodes it - a serial pass before video starts. For multi-audio sources this is done one stream at a time.
  • Interlace detection runs 'ffmpeg -vf idet -frames:v 400' (decodes 400 frames).
  • Several ffprobe calls (media info, stream languages, zscale, duration) + the OMDb/TVmaze fetch.

Optimisation ideas (KEEP opusenc - see constraint below):

  • Pipe ffmpeg PCM straight into opusenc stdin to skip the intermediate wav FILE (avoids writing+reading a possibly multi-GB wav; keeps opusenc).
  • Extract/encode multiple audio streams in parallel instead of sequentially.
  • Sample fewer idet frames, or skip detection when the source is known progressive.

CONSTRAINT: do NOT replace opusenc with ffmpeg's libopus to 'save a pass'. ffmpeg's opus encoder mis-handles multichannel (e.g. 5.1 side channels are not detected correctly and need special mapping); opusenc is deliberate and required (see SPEC.md). The decode->wav->opusenc split exists for this reason.

UX side: the dashboard collapses the 'probing' and 'audio' phases into one 'preparing' label; surfacing the real phase (probing vs extracting/encoding audio) would make the wait self-explanatory. The tracker already distinguishes them.

The 'preparing' phase (everything before the video encode) can last a long time. Likely contributors, roughly in order: - Audio extraction decodes the entire audio to a PCM wav (a full decode pass per audio stream), then opusenc encodes it - a serial pass before video starts. For multi-audio sources this is done one stream at a time. - Interlace detection runs 'ffmpeg -vf idet -frames:v 400' (decodes 400 frames). - Several ffprobe calls (media info, stream languages, zscale, duration) + the OMDb/TVmaze fetch. Optimisation ideas (KEEP opusenc - see constraint below): - Pipe ffmpeg PCM straight into opusenc stdin to skip the intermediate wav FILE (avoids writing+reading a possibly multi-GB wav; keeps opusenc). - Extract/encode multiple audio streams in parallel instead of sequentially. - Sample fewer idet frames, or skip detection when the source is known progressive. CONSTRAINT: do NOT replace opusenc with ffmpeg's libopus to 'save a pass'. ffmpeg's opus encoder mis-handles multichannel (e.g. 5.1 side channels are not detected correctly and need special mapping); opusenc is deliberate and required (see SPEC.md). The decode->wav->opusenc split exists for this reason. UX side: the dashboard collapses the 'probing' and 'audio' phases into one 'preparing' label; surfacing the real phase (probing vs extracting/encoding audio) would make the wait self-explanatory. The tracker already distinguishes them.
Kessinen added the enhancement label 2026-06-21 18:01:14 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Kessinen/av1dae#18