[HOW-TO] Encode frame rate in mp4, on Pi5

Open
#1,013 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, raspberry-pi

Research direction

Start by reproducing the issue with the Picamera2 snippet using create_video_configuration and start_and_record_video on the stated Bookworm and picamera2 0.3.17 setup. Inspect the resulting test.mp4 metadata alongside its frame timestamps; done means the output reports the configured 10 Hz frame rate without breaking recording.

Written by the indexing model from the issue text.

Description

Hi,
I'm recording from a Raspberry Pi HQ camera on a Pi 5. Despite trying a whole bunch of different ways, I'm having trouble getting a correct frame rate written into the output file's metadata.

Here's the simplest code fragment to reproduce the issue:

from picamera2 import Picamera2
picam2 = Picamera2()
video_config = picam2.create_video_configuration(controls={'FrameRate': 10})
picam2.start_and_record_video("test.mp4", config=video_config, duration=10)

The resulting video is recorded at the proper 10 Hz framerate +- some jitter (confirmed by filming a stopwatch over several minutes, or by reading out individual timestamps for each frame), but the mp4 reports the framerate as about 11.1 Hz (as read by Windows, VLC or Matlab). For longer videos, the discrepancy is smaller (e.g. 10.05Hz for a 3 minute video). Now, when analysing the videos, I could read out the individual timestamps for each frame, but for longer videos that would slow down analysis quite a bit.
Is there any way to correct this, or manually write the correct frame rate into output files?

Many thanks in advance for your help!

For reference, I'm running picamera2 version 0.3.17 on a fresh Bookworm installation.

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.