|
7 | 7 | import sarge |
8 | 8 | import sys |
9 | 9 | import flask |
| 10 | +import traceback |
10 | 11 | from collections import deque |
11 | 12 | try: |
12 | 13 | import queue |
@@ -85,15 +86,18 @@ def get_webcam_resolution(webcam_config): |
85 | 86 | def find_ffmpeg_h264_encoder(): |
86 | 87 | test_video = os.path.join(FFMPEG_DIR, 'test-video.mp4') |
87 | 88 | FNULL = open(os.devnull, 'w') |
88 | | - for encoder in ['h264_omx', 'h264_v4l2m2m']: |
89 | | - 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) |
90 | | - _logger.debug('Popen: {}'.format(ffmpeg_cmd)) |
91 | | - ffmpeg_test_proc = subprocess.Popen(ffmpeg_cmd.split(' '), stdout=FNULL, stderr=FNULL) |
92 | | - if ffmpeg_test_proc.wait() == 0: |
93 | | - if encoder == 'h264_omx': |
94 | | - return '-flags:v +global_header -c:v {} -bsf dump_extra'.format(encoder) # Apparently OMX encoder needs extra param to get the stream to work |
95 | | - else: |
96 | | - return '-c:v {}'.format(encoder) |
| 89 | + try: |
| 90 | + for encoder in ['h264_omx', 'h264_v4l2m2m']: |
| 91 | + 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) |
| 92 | + _logger.debug('Popen: {}'.format(ffmpeg_cmd)) |
| 93 | + ffmpeg_test_proc = subprocess.Popen(ffmpeg_cmd.split(' '), stdout=FNULL, stderr=FNULL) |
| 94 | + if ffmpeg_test_proc.wait() == 0: |
| 95 | + if encoder == 'h264_omx': |
| 96 | + return '-flags:v +global_header -c:v {} -bsf dump_extra'.format(encoder) # Apparently OMX encoder needs extra param to get the stream to work |
| 97 | + else: |
| 98 | + return '-c:v {}'.format(encoder) |
| 99 | + except Exception as e: |
| 100 | + _logger.exception('Failed to find ffmpeg h264 encoder. Exception: %s\n%s', e, traceback.format_exc()) |
97 | 101 |
|
98 | 102 | _logger.warn('No ffmpeg found, or ffmpeg does NOT support h264_omx/h264_v4l2m2m encoding.') |
99 | 103 | return None |
|
0 commit comments