obsproject / obsproject/obs-studio

v4l2 input sets incorrect framerate

Open
#13,388 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
76.4k
Forks
10.2k
Avg merge
4d 23h
Merged PRs (30d)
12

Description

Operating System Info

Other

Other OS

Manjaro Linux

OBS Studio Version

Other

OBS Studio Version (Other)

OBS 32.1.0, 32.1.2 (distro packages), also present in Flatpak; v4l2 plugin distro packaged or latest from git (optionally w/ patch below)

OBS Studio Log URL

https://obsproject.com/logs/d9PdKsvIEWLOYDTt

OBS Studio Crash Log URL

No response

Expected Behavior

When setting the framerate in Source Properties, the device would be set to the framerate selected. (30 in my case)

Current Behavior

The device in my case ends up set to 60fps.
It attempts to set the device to inf (selected FPS / 0) which results in v4l2 picking the best it can (60 in my case).

Steps to Reproduce
  1. (optional) In v4l2-input.c, at line 944 add the following:v4l2_unpack_tuple(&fps_num, &fps_denom, data->framerate); blog(LOG_DEBUG, "Attempting to set framerate: %.2f fps, (%d / %d)", (float)fps_denom / fps_num, fps_denom, fps_num); v4l2-input_better_debug.patch
  2. (assuming a v4l2 source is already set up, if not add one)
  3. change the framerate in the source properties
  4. observe that the chosen framerate has not been applied correctly
  5. (in my case) get mad because input device stops working
    ...
Anything else we should know?

Best I can tell, the packed framerate is being truncated to 32 bits somewhere in OBS's properties storage, which results in an FPS denominator of 0. If I edit the relevant line in ~/.config/obs-studio/basic/scenes/[scene name].json to have the correct 64bit packed value (4294967326 for 30FPS), the device is initially set correctly (until Properties is opened). (Why does simply opening the Properties even set anything??? see #3092) If setting is changed and saved, the JSON will contain only the numerator (30), rather than the correct packed value.

This is a significant problem for some (probably cheap) video devices like mine which do not actually work at 60FPS at full resolution.

v4l2-input_better_debug.patch

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in v4l2-input.c around line 944 and trace how the selected framerate is stored and passed to v4l2. Compare the packed value in the scene JSON with the value after changing Source Properties, using the supplied debug patch or log as needed. Done means selecting 30 FPS persists the correct value and the device receives that framerate.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
audio-video-rtc, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.