Skip to content

fix(ffmpeg): frame threading for software H.264/HEVC decode; log CPU fallback (#96) - #121

Merged
mcoliver merged 1 commit into
mainfrom
fix/96-hevc-decode-threads
Oct 13, 2026
Merged

mcoliver merged 1 commit into
mainfrom
fix/96-hevc-decode-threads

Conversation

@mcoliver

@mcoliver mcoliver commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #96 (Windows HEVC 4K60 doesn't play smoothly).

What changes

Software decode threading. UTV has set thread_type = FF_THREAD_SLICE on every FFmpeg decoder since 980befe. Upstream OpenRV leaves FFmpeg's default (frame + slice). H.264 and HEVC files from cameras usually have one slice per frame, so slice-only threading decodes them on one core. Now:

  • intra-only codecs (ProRes, DNxHR, ...: AV_CODEC_PROP_INTRA_ONLY) keep slice threading;
  • hardware decoders keep slice threading, unchanged, since we can't test NVIDIA or AMD here;
  • everything else gets frame + slice threading. The decode loop already uses send/receive with EAGAIN, the same as upstream, so the frame-threading delay is handled.

Logging. When a codec UTV can hardware-decode (ProRes, H.264, HEVC, VP9, AV1) is decoded on the CPU, the log says why, once per codec:

  • INFO: Decoding 'hevc' on the CPU: hardware decoding is turned off in Preferences > Caching.
  • INFO: Decoding 'hevc' on the CPU: no hardware decoder could be opened for it (this FFmpeg build has dxva2, d3d11va, d3d12va).
  • INFO: Decoding 'hevc' on the CPU: the cuda hardware decoder can't decode this stream. (FFmpeg opened the GPU decoder but fell back, e.g. an unsupported profile)

get_format fallback. When the chosen hardware format isn't offered, it now returns the first software format instead of pixelFormats[0], which is usually another hardware format with no device context.

Testing (macOS, M-series)

hevc_4k60P_main_dji_mavic3.mov (the clip from #96), 35 s of playback, RV_PLAYBACK_DIAG=1:

baseline (main) this PR
UTV_HWACCEL=none (CPU) 23.4 fps 40.1 fps
  • ffmpeg -f null on the same clip: 33 fps with -thread_type slice, 115 fps with -thread_type frame.
  • Default (VideoToolbox) still logs Using videotoolbox hardware acceleration for 'hevc' decoding.
  • UTV_HWACCEL=none and UTV_HWACCEL=cuda (not in this build) print the first two messages above.

Not tested: Windows, Linux, or any NVIDIA/AMD GPU.

…fallback (#96)

UTV forced slice-only threading on every FFmpeg decoder (980befe). H.264
and HEVC files often have one slice per frame, so software decoding used
one core. Intra-only codecs (ProRes, DNxHR) and hardware decoders keep
slice threading; other codecs get FFmpeg's default frame + slice threading,
as upstream OpenRV does. A 4K60 HEVC clip with hardware decoding off went
from 23 to 40 fps in UTV on an M-series Mac.

When a codec UTV can hardware-decode ends up on the CPU, log once why:
turned off in Preferences, no hardware decoder could be opened (listing
the methods the FFmpeg build has), or the GPU decoder can't decode the
stream. The get_format fallback now picks the first software format
instead of the first entry, which can be another hardware format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: Michael Oliver <mcoliver@gmail.com>
@mcoliver mcoliver changed the title fix(ffmpeg): frame threading for software H.264/HEVC decode, and log why a codec is decoded on the CPU (#96) fix(ffmpeg): frame threading for software H.264/HEVC decode; log CPU fallback (#96) Oct 13, 2026
@mcoliver
mcoliver force-pushed the fix/96-hevc-decode-threads branch from d6e46a2 to 6e807f5 Compare October 13, 2026 17:13
@mcoliver
mcoliver merged commit 3a38e41 into main Oct 13, 2026
16 of 21 checks passed
@mcoliver
mcoliver deleted the fix/96-hevc-decode-threads branch October 13, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant