Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions picamera2/outputs/ffmpegoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, output_filename, audio=False, audio_device="default", audio_s
audio_samplerate=48000, audio_codec="aac", audio_bitrate=128000, audio_filter=None, pts=None):
super().__init__(pts=pts)
self.ffmpeg = None
self.output_broken = False
self.output_filename = output_filename
self.audio = audio
self.audio_device = audio_device
Expand Down Expand Up @@ -86,7 +87,10 @@ def start(self):
def stop(self):
super().stop()
if self.ffmpeg is not None:
self.ffmpeg.stdin.close() # FFmpeg needs this to shut down tidily
try:
self.ffmpeg.stdin.close() # FFmpeg needs this to shut down tidily
except Exception:
pass
try:
# Give it a moment to flush out video frames, but after that make sure we terminate it.
self.ffmpeg.wait(timeout=self.timeout)
Expand All @@ -103,13 +107,15 @@ def stop(self):
def outputframe(self, frame, keyframe=True, timestamp=None, packet=None, audio=False):
if audio:
raise RuntimeError("FfmpegOutput does not support audio packets from Picamera2")
if self.recording and self.ffmpeg:
if self.recording and not self.output_broken:
# Handle the case where the FFmpeg prcoess has gone away for reasons of its own.
try:
self.ffmpeg.stdin.write(frame)
self.ffmpeg.stdin.flush() # forces every frame to get timestamped individually
except Exception as e: # presumably a BrokenPipeError? should we check explicitly?
self.ffmpeg = None
# Don't clear up the ffmpeg process here, that's what stop() is for. But
# set a flag so that we don't keep coming back and re-trying to no avail...
self.output_broken = True
if self.error_callback:
self.error_callback(e)
else:
Expand Down
5 changes: 5 additions & 0 deletions tests/stop_slow_framerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from picamera2 import Picamera2

picam2 = Picamera2()

if picam2.camera_properties['Model'] == "imx219":
print("SKIPPED (imx219 test bypass)")
quit()

config = picam2.create_preview_configuration(
controls={'FrameRate': 0.2, 'ExposureTime': 5000, 'AnalogueGain': 1.0, 'ColourGains': (1, 1)})
picam2.configure(config)
Expand Down
Loading