0

I am setting up a Raspberry Pi with a USB webcam to use as a dashcam. The code is as follows:

#!/usr/bin/env python

import subprocess
import datetime
import os

ROOT_PATH = os.getenv("ROOT_PATH", "/home/pi")
RECORDINGS_PATH = os.getenv("RECORDINGS_PATH", "recordings")
DATE_FMT = "%Y_%m_%d_%H_%M_%S"
SEGMENT_TIME = 30
ENCODING = os.getenv("ENCODING", "copy")

os.mkdir(RECORDINGS_PATH)

new_dir = datetime.datetime.now().strftime(DATE_FMT)
recording_path = os.path.join(ROOT_PATH, RECORDINGS_PATH, new_dir)
os.mkdir(recording_path)

segments_path = os.path.join(recording_path, "%03d.avi")

command = "ffmpeg -i /dev/video0 -c:v {} -an -sn -dn -segment_time {} -f segment {}".format(ENCODING, SEGMENT_TIME, segments_path)

subprocess.call(command, shell=True)

From: https://era86.github.io/2018/04/10/pi-zero-w-usb-dashcam.html

It works fine for about 2 minutes and then ffmpeg crashes with the following error:

enter image description here

Any ideas why?

1

You're saving to AVI which doesn't truly support variable frame rates so ffmpeg writes empty packets to emulate it. Apparently, the time base chosen is very fine and so ffmpeg has to write many skip packets (can't confirm since there's no log).

For segments, you should save to .ts or .mp4 or .mkv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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