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"
ENCODING = os.getenv("ENCODING", "copy")


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

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?


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

| improve this answer | |

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.