picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

[HOW-TO] h264 Timestamp File for mkv Conversion

Open ccostes opened this issue 2 years ago • 3 comments

I'm trying to convert the .h264 output files from this library to .mkv for playback. Is there any way to save a timestamp file like you can with the libcamera --save-pts option?

ccostes avatar Jun 28 '22 03:06 ccostes

At the moment this isn't possible. @chrisruk what do you think?

As an alternative/workaround you could do this:

from picamera2 import Picamera2
from picamera2.encoders import H264Encoder
from picamera2.outputs import FfmpegOutput

picam2 = Picamera2()
picam2.configure(picam2.video_configuration())
encoder = H264Encoder(bitrate=10000000)
output = FfmpegOutput('test.mkv')
picam2.start_recording(encoder, output)

though the timestamps in the file won't be as accurate.

davidplowman avatar Jun 28 '22 08:06 davidplowman

Good question, I'll have a look at this.

chrisruk avatar Jun 29 '22 07:06 chrisruk

@ccostes Hi, In the 'next' branch I added support for generating a file with timestamps, along with an example - https://github.com/raspberrypi/picamera2/blob/next/examples/capture_video_timestamp.py

chrisruk avatar Aug 15 '22 13:08 chrisruk

The changes for this are now in main. Please re-open if there's any remaining issue.

chrisruk avatar Aug 24 '22 10:08 chrisruk

@ccostes Hi, would it be useful for you if we added # timestamp format v2 as the first line of the timestamp file (like the --save-pts option does for libcamera-vid) so you can import it straight into mkvmerge? If so I can add that feature

will-v-pi avatar Aug 25 '22 10:08 will-v-pi