[BUG] MJPEGEncoder video always shows as 25 FPS

Open
#1,313 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
embedded-iot

Research direction

Start with the modified examples/dual_encode.py flow, focusing on MJPEGEncoder, FileOutput, and the configured framerate and FrameDurationLimits. Reproduce the issue at 20, 30, and 40 FPS, then compare the recorded frame counts with the FPS reported by OpenCV and ffmpeg; done means the reported FPS matches the configured and observed rate.

Written by the indexing model from the issue text.

Description

Hello

I'm having issues with recording MJPEG videos: No matter what I set the framerate (and sensor FrameDurationLimits) to, the resulting video is always reported as 25 FPS.

I can reproduce this with a slightly modified version of the dual_encode.py example:

"""
https://github.com/raspberrypi/picamera2/blob/main/examples/dual_encode.py
H264 encoding removed

"""

import time
from picamera2 import Picamera2
from picamera2.encoders import MJPEGEncoder
from picamera2.outputs import FileOutput

FPS = 40    # tried with 20, 30, 40 FPS

picam2 = Picamera2()
config = picam2.create_video_configuration({"size": (1280, 720)}, lores={"size": (640, 360)})
picam2.configure(config)

# Limiting exposure time to be sure we don't interfere with the FrameDuration
picam2.set_controls({"ExposureTime": 2000, "AnalogueGain": 1.0})

# Forcing framerate by setting sensor FrameDurationLimits
t_frame_us = round(1e6/FPS)
picam2.set_controls({"FrameDurationLimits": (t_frame_us, t_frame_us)})

mjpeg_encoder = MJPEGEncoder()
mjpeg_encoder.framerate = FPS
mjpeg_encoder.size = config["lores"]["size"]
mjpeg_encoder.format = config["lores"]["format"]
mjpeg_encoder.bitrate = 5000000
mjpeg_encoder.output = FileOutput("out.mjpeg")
mjpeg_encoder.start()

picam2.start()

start = time.time()
while time.time() - start < 5:
    request = picam2.capture_request()
    mjpeg_encoder.encode("lores", request)
    request.release()

mjpeg_encoder.stop()
picam2.stop()

I tried 20, 30 and 40 FPS so far. I know I'm getting the correct framerate, as I'm recording a blinking LED with known on/off period, and I'm getting the right number of frames with the LED on and off. I'm also not getting any dropped frames.
However, both OpenCV and ffmpeg report a FPS of 25.0 for all of them.

Do I misunderstand how to configure the library for this, or is this a bug somewhere?

HW: Compute Module 4
Sensor: OV9281

picamera2: 0.3.30
libcamera: v0.5.1+100-e53bdf1f
OS (uname -a): Linux cm4 6.12.34+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.34-1+rpt1~bookworm (2025-06-26) aarch64 GNU/Linux

Thank you
Felix

Dominant language
Python
Stars
1.2k
Forks
258
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from raspberrypi/picamera2

All issues in raspberrypi/picamera2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.