Skip to content

Commit

Permalink
Will throw exceptions on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethjiang committed Jun 2, 2024
1 parent ebb6ea5 commit 5177e51
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions octoprint_obico/webcam_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sarge
import sys
import flask
import traceback
from collections import deque
try:
import queue
Expand Down Expand Up @@ -85,15 +86,18 @@ def get_webcam_resolution(webcam_config):
def find_ffmpeg_h264_encoder():
test_video = os.path.join(FFMPEG_DIR, 'test-video.mp4')
FNULL = open(os.devnull, 'w')
for encoder in ['h264_omx', 'h264_v4l2m2m']:
ffmpeg_cmd = '{} -re -i {} -pix_fmt yuv420p -vcodec {} -an -f rtp rtp://127.0.0.1:8014?pkt_size=1300'.format(FFMPEG, test_video, encoder)
_logger.debug('Popen: {}'.format(ffmpeg_cmd))
ffmpeg_test_proc = subprocess.Popen(ffmpeg_cmd.split(' '), stdout=FNULL, stderr=FNULL)
if ffmpeg_test_proc.wait() == 0:
if encoder == 'h264_omx':
return '-flags:v +global_header -c:v {} -bsf dump_extra'.format(encoder) # Apparently OMX encoder needs extra param to get the stream to work
else:
return '-c:v {}'.format(encoder)
try:
for encoder in ['h264_omx', 'h264_v4l2m2m']:
ffmpeg_cmd = '{} -re -i {} -pix_fmt yuv420p -vcodec {} -an -f rtp rtp://127.0.0.1:8014?pkt_size=1300'.format(FFMPEG, test_video, encoder)
_logger.debug('Popen: {}'.format(ffmpeg_cmd))
ffmpeg_test_proc = subprocess.Popen(ffmpeg_cmd.split(' '), stdout=FNULL, stderr=FNULL)
if ffmpeg_test_proc.wait() == 0:
if encoder == 'h264_omx':
return '-flags:v +global_header -c:v {} -bsf dump_extra'.format(encoder) # Apparently OMX encoder needs extra param to get the stream to work
else:
return '-c:v {}'.format(encoder)
except Exception as e:
_logger.exception('Failed to find ffmpeg h264 encoder. Exception: %s\n%s', e, traceback.format_exc())

_logger.warn('No ffmpeg found, or ffmpeg does NOT support h264_omx/h264_v4l2m2m encoding.')
return None
Expand Down

0 comments on commit 5177e51

Please sign in to comment.