{"id":3967,"date":"2023-12-22T08:11:01","date_gmt":"2023-12-22T00:11:01","guid":{"rendered":"http:\/\/cnliutz.ipyingshe.net\/?p=3967"},"modified":"2023-12-22T08:11:03","modified_gmt":"2023-12-22T00:11:03","slug":"python%e5%bd%95%e5%b1%8f-2","status":"publish","type":"post","link":"http:\/\/cnliutz.wicp.vip\/?p=3967","title":{"rendered":"python\u5f55\u5c4f"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\r#\u5f55\u5236\u5c4f\u5e5530\u79d2\nimport pyautogui\r\nimport cv2\r\nimport numpy as np\r\n\r\n# Set the recording resolution and framerate\r\nresolution = (1920,1080)\r\nfps = 30\r\n\r\n# Start recording the screen\r\n#screen_capture = pyautogui.screenshot()\r\n# Convert the screenshot to a numpy array\r\n#screen_capture = np.array(screen_capture)\r\n# Create a VideoWriter object to save the video\r\nfourcc = cv2.VideoWriter_fourcc(*'mp4v')\r\nout = cv2.VideoWriter('output.mp4', fourcc, fps, resolution)\r\n\r\n# Record the screen for 10 seconds\r\nfor i in range(10 * fps):\r\n   # Capture a screenshot\r\n   screen_capture = pyautogui.screenshot()\r\n   # Convert the screenshot to a numpy array\r\n   screen_capture = np.array(screen_capture)\r\n   # Write the numpy array to the video file\r\n   out.write(screen_capture)\r\n\r\n# Release the VideoWriter object and close the video file\r\nout.release()\r\ncv2.destroyAllWindows()\r\nprint(\"saved to output.mp4....\")<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,10],"tags":[],"class_list":["post-3967","post","type-post","status-publish","format-standard","hentry","category-2","category-python"],"_links":{"self":[{"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=\/wp\/v2\/posts\/3967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3967"}],"version-history":[{"count":1,"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=\/wp\/v2\/posts\/3967\/revisions"}],"predecessor-version":[{"id":3968,"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=\/wp\/v2\/posts\/3967\/revisions\/3968"}],"wp:attachment":[{"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3967"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cnliutz.wicp.vip\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}