使用shell在linux录屏
时间: 2024-05-27 21:12:47 浏览: 16
您好!关于使用shell在linux录屏的问题,我可以给您提供以下命令:
1. 使用avconv录屏命令:avconv -f x11grab -s 1366x768 -r 25 -i :0.0 -vcodec libx264 out.mp4
2. 使用ffmpeg录屏命令:ffmpeg -f x11grab -s 1366x768 -r 25 -i :0.0 -vcodec libx264 out.mp4
希望对您有所帮助!
相关问题
linux录屏快捷键
在Linux系统中,常用的录屏快捷键是使用FFmpeg命令行工具进行录制。你可以按下Ctrl + Alt + T组合键打开终端,然后输入以下命令开始录制屏幕:
```
ffmpeg -f x11grab -s <屏幕分辨率> -i :0.0 -r <帧率> <输出文件名>
```
其中,`<屏幕分辨率>`是你希望录制的屏幕大小,例如1920x1080;`<帧率>`是录制的帧率,例如30;`<输出文件名>`是保存录制视频的文件名和路径。
在录制期间,你可以按下Ctrl + C组合键来停止录制。
请注意,FFmpeg命令行工具需要事先安装在你的Linux系统中。
在 linux上使用opencv 和python 录屏
可以使用Python中的OpenCV库来录制屏幕。以下是在Linux上使用OpenCV和Python录制屏幕的步骤:
1. 安装OpenCV库
可以使用以下命令在Linux上安装OpenCV库:
```
sudo apt-get install python-opencv
```
2. 导入库
在Python脚本中导入OpenCV库:
```python
import cv2
```
3. 获取屏幕分辨率
使用以下代码获取屏幕的宽度和高度:
```python
screen_width = int(cv2.CAP_PROP_FRAME_WIDTH)
screen_height = int(cv2.CAP_PROP_FRAME_HEIGHT)
```
4. 创建VideoWriter对象
使用以下代码创建VideoWriter对象:
```python
fourcc = cv2.VideoWriter_fourcc(*"XVID")
video_writer = cv2.VideoWriter("output.avi", fourcc, 20.0, (screen_width, screen_height))
```
这里的"output.avi"是输出文件的名称,fourcc是视频编解码器,20.0是帧速率,(screen_width, screen_height)是视频分辨率。
5. 开始录制
使用以下代码开始录制:
```python
while True:
img = pyautogui.screenshot()
frame = np.array(img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
video_writer.write(frame)
```
这里使用PyAutoGUI库获取屏幕截图,并将其转换为OpenCV格式。然后将帧写入VideoWriter对象中。
6. 停止录制
最后,使用以下代码停止录制:
```python
video_writer.release()
```
这将释放VideoWriter对象并保存录制的视频。
完整的代码示例:
```python
import cv2
import numpy as np
import pyautogui
screen_width = int(cv2.CAP_PROP_FRAME_WIDTH)
screen_height = int(cv2.CAP_PROP_FRAME_HEIGHT)
fourcc = cv2.VideoWriter_fourcc(*"XVID")
video_writer = cv2.VideoWriter("output.avi", fourcc, 20.0, (screen_width, screen_height))
while True:
img = pyautogui.screenshot()
frame = np.array(img)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
video_writer.write(frame)
if cv2.waitKey(1) == ord("q"):
break
video_writer.release()
cv2.destroyAllWindows()
```
运行此脚本,按下键盘上的“q”键以停止录制。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)