0

I'm using a real simple python script to capture a video file to a file, taken from the "simple recipes" guide :

import picamera
camera = picamera.PiCamera()
camera.resolution = (640, 480)
camera.start_recording('my_video.h264')
camera.wait_recording(30)
camera.stop_recording()

When I play 'my_video.h264' with vlc or omxplayer, the video speed is slowed, so the video last 35 seconds instead of the 30 expected.

Converting the video to AVI with ffmpeg

ffmpeg -i test.h264 -c:v copy -f avi test.avi

or to mp4 with MP4Box :

MP4Box -add test.h264 test.mp4

don't solve anything, video is still slow and last 35 seconds.

Here is the informations I gathered about the video files : ffprobe -i test.h264 :

Duration: N/A, bitrate: N/A Stream #0:0: Video: h264 (High), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 1200k tbn, 50 tbc

ffprobe -i test.avi :

Duration: 00:00:35.76, start: 0.000000, bitrate: 685 kb/s Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 640x480, 675 kb/s, 50 fps, 25 tbr, 50 tbn, 100 tbc

ffprobe -i test.mp4 :

Duration: 00:00:35.76, start: 0.000000, bitrate: 675 kb/s Stream 0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 674 k b/s, 25 fps, 25 tbr, 25k tbn, 50k tbc (default)

Am I missing something obvious ?

Note : raspivid is capturing without this problem.

1 Answer 1

2

If you do not specify the default framerate in python then it will be set to 30fps. The players you are using expect a frame rate of 25fps. So your 30 second video should last 30seconds x 30fps/25fps = 36 seconds. See documentation, 10. API - picamera.camera Module, for the default frame rate.

Try using

camera.framerate=25

Camera must not be recording for this change to take effect.

1
  • Bingo ! Thank you, this seems so obvious once explained :) Commented Aug 16, 2018 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.