Hello, i have written the code below for a pyqt5 app which can be used to view from 4 cameras connected to an arducam multicam adapter. (just to note, i have made changes to the program when trying to fix this so thats why there are some lines which may look unnecessary).
When i click the record button, the video file is created but when i open it, i just get the error: VLC is unable to open the MRL. I was wondering why im getting this error and where i might be going wrong.
When i click the record button, the video file is created but when i open it, i just get the error: VLC is unable to open the MRL. I was wondering why im getting this error and where i might be going wrong.
Code:
import traceback, requests, time, os, sys, RPi.GPIO as gpfrom PyQt5 import QtWidgetsfrom PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout, QGridLayout, QRadioButton, QLabel, QLineEditfrom picamera2 import Picamera2from picamera2.previews.qt import QGlPicamera2from picamera2.encoders import H264Encoderfrom picamera2.outputs import FileOutputfrom libcamera import controlsfrom googleapiclient.http import MediaFileUploadfrom googleapiclient.discovery import buildfrom google.oauth2 import service_accountfrom google.auth import exceptions as auth_exceptions# Initialise camera_A as first camera in previewgp.setwarnings(False)gp.setmode(gp.BOARD)gp.setup(7, gp.OUT)gp.setup(11, gp.OUT)gp.setup(12, gp.OUT)i2c = "i2cset -y 1 0x70 0x00 0x04"os.system(i2c)gp.output(7, False)gp.output(11, False)gp.output(12, True)Exposure_value = 1.0Analogue_gain = 0.0Brightness = 0.1Contrast = 1.0Saturation = 1.0Sharpness = 15.0# Picamera2 configurationspicam2 = Picamera2()picam2.configure(picam2.create_video_configuration(main={"size": (1920, 1088)},encode="main"))picam2.set_controls({"AfMode": 2, "AfTrigger": 0, "AeEnable": False, "ExposureValue": Exposure_value, "AnalogueGain": Analogue_gain, "Brightness": Brightness, "Contrast": Contrast, "Saturation": Saturation, "Sharpness": Sharpness, "FrameDurationLimits": (40000,40000)})############################################################################################################################################################## Functions# Camera selectiondef camera_a(): picam2.stop() os.system("i2cset -y 1 0x70 0x00 0x04") gp.output(7, False) gp.output(11, False) gp.output(12, True) picam2.set_controls({"AfMode": 2, "AfTrigger": 0, "AeEnable": False, "ExposureValue": Exposure_value, "AnalogueGain": Analogue_gain, "Brightness": Brightness, "Contrast": Contrast, "Saturation": Saturation, "Sharpness": Sharpness, "FrameDurationLimits": (40000,40000)}) picam2.start()def camera_b(): picam2.stop() os.system("i2cset -y 1 0x70 0x00 0x05") gp.output(7, True) gp.output(11, False) gp.output(12, True) picam2.set_controls({"AfMode": 2, "AfTrigger": 0, "AeEnable": False, "ExposureValue": Exposure_value, "AnalogueGain": Analogue_gain, "Brightness": Brightness, "Contrast": Contrast, "Saturation": Saturation, "Sharpness": Sharpness, "FrameDurationLimits": (40000,40000)}) picam2.start()def camera_c(): picam2.stop() os.system("i2cset -y 1 0x70 0x00 0x06") gp.output(7, False) gp.output(11, True) gp.output(12, False) picam2.set_controls({"AfMode": 2, "AfTrigger": 0, "AeEnable": False, "ExposureValue": Exposure_value, "AnalogueGain": Analogue_gain, "Brightness": Brightness, "Contrast": Contrast, "Saturation": Saturation, "Sharpness": Sharpness, "FrameDurationLimits": (40000,40000)}) picam2.start()def camera_d(): picam2.stop() os.system("i2cset -y 1 0x70 0x00 0x07") gp.output(7, True) gp.output(11, True) gp.output(12, False) picam2.set_controls({"AfMode": 2, "AfTrigger": 0, "AeEnable": False, "ExposureValue": Exposure_value, "AnalogueGain": Analogue_gain, "Brightness": Brightness, "Contrast": Contrast, "Saturation": Saturation, "Sharpness": Sharpness, "FrameDurationLimits": (40000,40000)}) picam2.start()# Preview functionsdef preview_select(): if camera_A_select.isChecked(): try: camera_a() except Exception as e: print(f"Error in selecting camera A for preview: {str(e)}") traceback.print_exc() elif camera_B_select.isChecked(): try: camera_b() except Exception as e: print(f"Error in selecting camera B for preview: {str(e)}") traceback.print_exc() elif camera_C_select.isChecked(): try: camera_b() except Exception as e: print(f"Error in selecting camera C for preview: {str(e)}") traceback.print_exc() elif camera_D_select.isChecked(): try: camera_d() except Exception as e: print(f"Error in selecting camera D for preview: {str(e)}") traceback.print_exc() # Record functionsdef on_button_clicked(): try: camera_a() encoder = H264Encoder(bitrate=10000000) output = FileOutput("test.h264") picam2.start_encoder(encoder,output) time.sleep(2) picam2.stop_encoder() except Exception as e: print(f"Error in recording: {str(e)}") traceback.print_exc() # Zoom functiondef zoom(): try: full_res = list(picam2.camera_properties['PixelArraySize']) # Convert tuple to list size = full_res.copy() if zoom_in.isChecked(): picam2.stop() offset = [(r - int(s * 0.25)) // 2 for r, s in zip(full_res, size)] size = [int(s * 0.25) for s in size] picam2.set_controls({"ScalerCrop": offset + size}) picam2.start() else: picam2.stop() offset = [0, 0] picam2.set_controls({"ScalerCrop": offset + size}) picam2.start() except Exception as e: print(f"Error in zoom: {str(e)}") traceback.print_exc()###########################################################################################################################################################parent_folder_id = '19AepzzBM937dfSWkT2pFZMj83kDti105'# App set-upapp = QApplication([])window = QWidget()window.setWindowTitle("Larvae Capture app")overall_layout = QGridLayout()# Previewqpicamera2 = QGlPicamera2(picam2, width=1920, height=1088, keep_ar=False)qpicamera2.setFixedSize(640,360)overall_layout.addWidget(qpicamera2, 0, 0)# Preview buttonspreview_button_layout = QHBoxLayout()camera_A_select = QRadioButton("Camera A")camera_A_select.toggled.connect(preview_select)preview_button_layout.addWidget(camera_A_select)camera_B_select = QRadioButton("Camera B")camera_B_select.toggled.connect(preview_select)preview_button_layout.addWidget(camera_B_select)camera_C_select = QRadioButton("Camera C")camera_C_select.toggled.connect(preview_select)preview_button_layout.addWidget(camera_C_select)camera_D_select = QRadioButton("Camera D")camera_D_select.toggled.connect(preview_select)preview_button_layout.addWidget(camera_D_select)overall_layout.addLayout(preview_button_layout, 1, 0)#Record button/srecord_button = QPushButton("Record Button")record_button.clicked.connect(on_button_clicked)overall_layout.addWidget(record_button, 0, 1)push_button = 32gp.setup(push_button, gp.IN, pull_up_down=gp.PUD_UP)gp.add_event_detect(push_button, gp.RISING, callback=on_button_clicked, bouncetime=1000)video_length = 2 # Video length# Initialise LEDsnot_recording_led = 36recording_led = 38gp.setup(not_recording_led, gp.OUT)gp.setup(recording_led, gp.OUT)gp.output(not_recording_led, True)gp.output(recording_led, False)# Batch namingpot = 1rep_a = 1rep_b = 2rep_c = 3rep_d = 4batch_label = QLabel('Batch Number:')pot_label = QLabel(f'Pot Number: {pot}')rep_label = QLabel(f'Rep Number: {rep_a}, {rep_b}, {rep_c}, {rep_d}')batch_line_edit = QLineEdit()naming_layout = QVBoxLayout()naming_layout.addWidget(batch_label)naming_layout.addWidget(batch_line_edit)naming_layout.addWidget(pot_label)naming_layout.addWidget(rep_label)overall_layout.addLayout(naming_layout, 1, 1)# Zoom buttonszoom_in = QRadioButton('Zoom in')zoom_in.toggled.connect(zoom)overall_layout.addWidget(zoom_in, 4, 1)window.setLayout(overall_layout)picam2.start()window.show()app.exec()picam2.close()gp.output(not_recording_led, False)gp.output(recording_led, False)
Statistics: Posted by RobertHawes — Fri Mar 15, 2024 10:59 am