-
Notifications
You must be signed in to change notification settings - Fork 241
Description
Describe the bug
I am trying to set up a CCTV camera using a Raspberry Pi (2B+) with a Noir OV5647 camera.
My goal is to change the framerate dynamically to control exposure at night.
During daytime → FPS = 16
During nighttime → FPS = 10
However, the H.264 header always seems to be set to 30 FPS, regardless of the actual framerate.
This causes ffmpeg to encode the video at half speed.
I also tried using -vsync vfr, but the problem persists.
To Reproduce
Minimal script that reproduces the issue:
ffmpeg_cmd = [
"ffmpeg",
"-fflags", "+genpts",
"-analyzeduration", "5000000",
"-probesize", "5000000",
"-vsync", "vfr",
"-thread_queue_size", "512",
"-dts_delta_threshold", "1",
"-f", "h264", "-i", "pipe:0",
"-thread_queue_size", "512",
"-f", "pulse", "-i", pulse_device,
"-af", (
"aresample=async=1,adelay=5000|5000,"
"highpass=f=200,lowpass=f=3000,"
"afftdn=nf=-35,equalizer=f=440:t=q:w=1:g=-20,"
"volume=10dB"
),
"-c:v", "copy",
"-fflags", "nobuffer",
"-c:a", "libopus",
"-b:a", "32k",
"-ac", "1",
"-ar", "16000",
"-use_wallclock_as_timestamps", "1",
"-f", "rtsp", "-rtsp_transport", "tcp",
"rtsp://127.0.0.1:8554/mystream"
]
ffmpeg = subprocess.Popen(ffmpeg_cmd, stdin=subprocess.PIPE)
initial_fps = 16
frame_us = int(1_000_000 / initial_fps)
video_config = picam2.create_video_configuration(
main={"size": (1920, 1080)},
controls={
"FrameDurationLimits": (frame_us, frame_us),
"Sharpness": 4.0,
"Contrast": 2.0,
"Saturation": 1.3,
}
)
video_config["transform"] = libcamera.Transform(hflip=1, vflip=1)
picam2.configure(video_config)
Expected behavior
ffmpeg should publish the RTSP stream at normal (1×) speed, matching the dynamically set framerate.
Actual behavior
At 16 FPS → works correctly.
At 10 FPS → ffmpeg publishes the RTSP stream at half speed.
When using rpicam-vid, the H.264 header is set properly and playback speed is correct.
However, I need to be able to change FPS dynamically without RTSP disconnection.
Console output / screenshots
If applicable, please see attached logs/screenshots that show the error or playback issue.
Hardware
Raspberry Pi 2B+
OV5647 Noir camera
Additional context
Problem only occurs when framerate is reduced dynamically.
With a fixed framerate (e.g., 16 FPS), everything works fine.
With dynamic framerate (16 → 10 FPS), ffmpeg stream playback slows down.