PySimpleGUIでボタンを作成し、カメラ映像の録画を行うとファイルが破損し再生できません。
GUIに映像を映し、録画ボタンで録画を行いたいと思っていたのですが上記のエラーが起きました。
何か悪いのかと思い、映像はOpenCVのimshowで映したのですがやはりエラー。
while文直後のGUIの処理をコメントアウトすると(録画時に映像は映りませんが)再生ができるようになるのでこの辺りが悪いのかなと思います。
アドバイス宜しくお願いします。
Python
1import cv2 2import PySimpleGUI as sg 3 4 5# PySimpleGUIの設定 6layout = [ 7 [sg.Text('Realtime movie', font='Helvetica 20')], 8 [sg.Image(filename='', key='image'), 9 sg.Button('Exit', size=(10, 1), font='Helvetica 14', key='-exit-')] 10 ] 11window = sg.Window('Realtime movie',layout, location=(100, 100)) 12 13cap = cv2.VideoCapture(0) 14 15# 動画ファイル保存用の設定 16fps = int(cap.get(cv2.CAP_PROP_FPS)) 17w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) 18h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) 19fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') 20video = cv2.VideoWriter('video4.mp4', fourcc, fps, (w, h)) 21 22# 映像処理 23while True: 24 event, values = window.read(timeout=0) 25 if event in (sg.WIN_CLOSED, '-exit-'): 26 break 27 ret, frame = cap.read() 28 cv2.imshow("camra", frame) 29 video.write(frame) 30 31 32cap.release() 33cv2.destroyAllWindows() 34window.close()
あなたの回答
tips
プレビュー