<p>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). </p>

<p>For segments, you should save to <code>.ts</code> or <code>.mp4</code> or <code>.mkv</code></p>

CC BY-SA 4.0
2019-09-07T17:58:21.073Z
2019-09-07T17:58:21.073Z
Gyan
<p>I am setting up a Raspberry Pi with a USB webcam to use as a dashcam. The code is as follows:</p>

<pre><code>#!/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)
</code></pre>

<p>From: <a href="https://era86.github.io/2018/04/10/pi-zero-w-usb-dashcam.html" rel="nofollow noreferrer">https://era86.github.io/2018/04/10/pi-zero-w-usb-dashcam.html</a></p>

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

<p><a href="https://i.sstatic.net/a4FLO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/a4FLO.png" alt="enter image description here"></a></p>

<p><strong>Any ideas why?</strong></p>

<ffmpeg>
Recording webcam video - ffmpeg - error
AlfroJang80
# Recording webcam video - ffmpeg - error

(Asked by: username_0 on 2019-09-07)

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:

Any ideas why?

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2019-09-07. Score: 2

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`


---

