Skip to content

Encode MJPEG cameras as 4:2:0 and add a resolution menu - #4

Closed
menobass wants to merge 2 commits into
omacom:masterfrom
menobass:resolution-menu-and-420-encoding
Closed

menobass wants to merge 2 commits into
omacom:masterfrom
menobass:resolution-menu-and-420-encoding

Conversation

@menobass

@menobass menobass commented Oct 6, 2026

Copy link
Copy Markdown

Fixes #3.

What

Cameras that only offer their top resolution as MJPEG could not be recorded at that resolution on modest hardware ("Video encoding cannot keep up..."). This makes them work, and gives people a way to pick a lower resolution.

  • 4:2:0 encoding for MJPEG cameras. Writer now decodes Format_Jpeg frames itself (libavcodec MJPEG, then libswscale to NV12) and hands the encoder ordinary 8-bit 4:2:0 frames. Before, Qt decoded them to 4:4:4 inside the encoder, which hardware H.264 encoders reject, so it fell back to software x264 at 4:4:4 10-bit. The output is now standard High-profile yuv420p.
  • Off the GUI thread. The decode and conversion run on a 3-thread pool. Frames are queued with their timestamps and sent to the encoder strictly in order, so pause/resume timing, the tail frame, and the "6 frames queued" limit behave as before. Doing the conversion on the GUI thread was too slow and dropped frames.
  • Resolution menu beside Camera and Microphone, listing the sizes the camera offers. The maximum stays the default, so the "never silently reduced" behavior is unchanged; this is an explicit user choice. It is stored as camera/resolution and falls back to the maximum if the camera lacks that size.
  • README notes for both.

libavcodec and libswscale come with the ffmpeg package that is already a dependency.

Testing

  • ./bin/test: backend 15/15 and UI 3/3 pass (the UI test's stand-in backend gained the new resolutions properties).
  • Real hardware: NexiGo N60 (1080p only as MJPEG) on an i5-8279U. A 4 s take with a pause, using ./bin/test-camera, went from failing to completing at about 29 fps, producing High / yuv420p H.264. Switching to 1280x720 in the menu also works.
  • Not covered: other cameras and backends, sustained long takes, or lip sync over time. Software x264 is still what Qt picks on this machine (now at 4:2:0); I did not change how it chooses between hardware and software.

🤖 Generated with Claude Code

menobass and others added 2 commits October 5, 2026 23:44
Cameras that offer their top resolution only as MJPEG delivered Format_Jpeg
frames, which Qt's FFmpeg encoder decoded to 4:4:4. Hardware H.264 encoders
reject that, so Qt fell back to software x264 at 4:4:4 10-bit, which cannot
keep up at 1080p on modest CPUs and produced files most players cannot play.

Decode those frames in Writer on a small worker pool (libavcodec MJPEG, then
libswscale to NV12) and keep them ordered before they reach the encoder, so
the GUI thread and camera delivery are no longer blocked. Output is standard
High-profile yuv420p.

Add a Resolution menu beside Camera and Microphone listing the sizes the
camera offers. The maximum stays the default; an explicit choice is stored
in settings and falls back to the maximum if the camera lacks it.

Fixes omacom#3

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

dhh commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for working through this. The MJPEG-to-4:2:0 half landed in #32, which now decodes MJPEG with libjpeg-turbo, and also handles YUYV and RGB, so NVENC and VA-API apply. The wrong-default half was fixed by #19, which skips 2 fps still sizes. That leaves the resolution menu, which overlaps the format picker in #14, so I'm closing this one.

@dhh dhh closed this Nov 12, 2026
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.

Recording fails at 1080p on slower machines: MJPEG is encoded as 4:4:4 in software; no way to lower resolution

2 participants