Skip to content

Commit

Permalink
fallback to opencv to detect resolution and allow config to specify
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Feb 22, 2020
1 parent 6263912 commit cd05737
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ cameras:
# hwaccel_args: []
# input_args: []
# output_args: []

################
## Optionally specify the resolution of the video feed. Frigate will try to auto detect if not specified
################
# height: 1280
# width: 720

################
## Optional mask. Must be the same dimensions as your video feed.
Expand Down
15 changes: 13 additions & 2 deletions frigate/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ def get_frame_shape(source):

video_info = [s for s in info['streams'] if s['codec_type'] == 'video'][0]

return (video_info['height'], video_info['width'], 3)
if video_info['height'] != 0 and video_info['width'] != 0:
return (video_info['height'], video_info['width'], 3)

# fallback to using opencv if ffprobe didnt succeed
video = cv2.VideoCapture(source)
ret, frame = video.read()
frame_shape = frame.shape
video.release()
return frame_shape

def get_ffmpeg_input(ffmpeg_input):
frigate_vars = {k: v for k, v in os.environ.items() if k.startswith('FRIGATE_')}
Expand Down Expand Up @@ -170,7 +178,10 @@ def __init__(self, name, ffmpeg_config, global_objects_config, config, prepped_f
'show_timestamp': self.config.get('snapshots', {}).get('show_timestamp', True)
}
self.regions = self.config['regions']
self.frame_shape = get_frame_shape(self.ffmpeg_input)
if 'width' in self.config and 'height' in self.config:
self.frame_shape = (self.config['height'], self.config['width'], 3)
else:
self.frame_shape = get_frame_shape(self.ffmpeg_input)
self.frame_size = self.frame_shape[0] * self.frame_shape[1] * self.frame_shape[2]
self.mqtt_client = mqtt_client
self.mqtt_topic_prefix = '{}/{}'.format(mqtt_prefix, self.name)
Expand Down

0 comments on commit cd05737

Please sign in to comment.