• win有界面录制桌面画面及麦克风声音


    from PIL import ImageGrab
    import numpy as np
    import cv2
    import datetime
    from pynput import keyboard
    import threading
    flag=False  #停止标志位
    
    # cap = cv2.VideoCapture(0)
    BOX=(0,0,1920,1080)
    
    
    def video_record():
        """
        屏幕录制!
        :return:
        """
        name = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S') #当前的时间
        p = ImageGrab.grab()  # 获得当前屏幕
        a, b = p.size  # 获得当前屏幕的大小
        fourcc = cv2.VideoWriter_fourcc(*'XVID')  # 编码格式
        video = cv2.VideoWriter('%s.avi'%name, fourcc, 25, (a, b))  # 输出文件命名为test.mp4,帧率为16,可以自己设置
        while True:
            im = ImageGrab.grab(bbox=BOX)
            imm=cv2.cvtColor(np.array(im), cv2.COLOR_RGB2BGR)#转为opencv的BGR格式
            cv2.namedWindow('Recording', cv2.WINDOW_KEEPRATIO) 
            cv2.imshow("Recording",imm)
            if cv2.waitKey(25) & 0xFF ==ord("q"):
                cv2.destroyAllWindows()
                break
    
            video.write(imm)
            if flag:
                print("录制结束!")
                break
        video.release()
    def on_press(key):
        """
        键盘监听事件!!!
        :param key:
        :return:
        """
        #print(key)
        global flag
        if key == keyboard.Key.esc:
            flag=True
            print("stop monitor!")
            return False  #返回False,键盘监听结束!
    
    if __name__=='__main__':
        th=threading.Thread(target=video_record)
        th.start()
        with keyboard.Listener(on_press=on_press) as listener:
            listener.join()
    
  • 相关阅读:
    js021-Ajax与Comet
    Android之应用程序基础
    Android之项目的目录结构
    Android之ContentProvider组件
    Android之BroadcastReceiver组件
    Android之Activity组件
    Android之Service组件
    2.绘制简单的几何图形
    1.一个简单的OpenGL程序
    2.由深拷贝和浅拷贝引发的写时拷贝技术
  • 原文地址:https://www.cnblogs.com/bear-king/p/15132529.html
Copyright © 2020-2023  润新知