Skip to content

[BUG] MJPEGEncoder video always shows as 25 FPS #1313

@falthaus

Description

@falthaus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions