泰山派调试常用命令

ubuntu下使用命令行连接wifi

1
2
3
4
5
6
sudo iwlist scan
nmcli device wifi list
nmcli device wifi connect {ESSID} password {PASSWORD}
nmcli device wifi connect 404_2.4g password "@404@404"
nmcli device wifi connect "404_5g" password "@404@404@404" ifname wlan0
make modules_install INSTALL_MOD_PATH=<rootfs_path>

image-20250305184418243

image-20250305184435807
image-20250305184435807
image-20250305184444185
image-20250305184444185

备忘录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 v4l2-ctl --list-devices
v4l2-ctl --list-formats-ext --device=/dev/video0
v4l2-ctl -d /dev/video0 -L
v4l2-ctl --set-ctrl analogue_gain=80


v4l2-ctl --verbose -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='UYVY' --stream-mmap=20 --set-selection=target=crop,flags=0,top=0,left=0,width=1920,height=1080 --set-ctrl analogue_gain=80 --stream-to=/tmp/out.yuv

v4l2-ctl --verbose -d /dev/video1 --set-fmt-video=width=1920,height=1080,pixelformat='UYVY' --stream-mmap=20 --stream-to=/tmp/out.yuv

ffmpeg -f v4l2 -input_format nv12 -video_size 1920x1080 -i /dev/video0 -c:v libx264 -preset ultrafast output.mp4

ffmpeg -f v4l2 -i /dev/video0 -pixel_format yuv422p -framerate 15 -video_size 800x600 -c:v copy -f mpegts udp://@:1234

ffmpeg -f v4l2 -input_format nv12 -video_size 1920x1080 -i /dev/video8 -t 10 output.yuv

ffmpeg -f rawvideo -pixel_format yuv422p -video_size 3840x2160 -framerate 24 -i out.yuv -c:v libx264 output.mp4


scp lsc@192.168.115.129:/home/lsc/project/Release/kernel/boot.img ./

硬件编码测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
import cv2
import socket
import numpy as np
import time

# --- 配置 ---
TARGET_IP = "192.168.3.71" # 接收端电脑的 IP 地址 (运行 OBS 的电脑)
TARGET_PORT = 1234 # 目标 UDP 端口 (与 OBS 设置一致)
CAMERA_INDEX = 0 # 摄像头的索引 (通常是 0 或 1)
JPEG_QUALITY = 70 # JPEG 编码质量 (0-100, 越高画质越好但数据量越大)
SEND_RESOLUTION = (640, 480) # 发送的分辨率 (宽, 高)

# --- 初始化 ---
# 创建 UDP socket
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 打开摄像头
cap = cv2.VideoCapture(CAMERA_INDEX)

if not cap.isOpened():
print(f"错误:无法打开摄像头索引 {CAMERA_INDEX}")
exit()

# 设置摄像头分辨率 (可选, 尝试设置)
# cap.set(cv2.CAP_PROP_FRAME_WIDTH, SEND_RESOLUTION[0])
# cap.set(cv2.CAP_PROP_FRAME_HEIGHT, SEND_RESOLUTION[1])

print(f"摄像头已打开。将推流到 UDP {TARGET_IP}:{TARGET_PORT}")
print(f"发送分辨率: {SEND_RESOLUTION}, JPEG 质量: {JPEG_QUALITY}")
print("按 Ctrl+C 停止推流。")

try:
while True:
# 读取一帧
ret, frame = cap.read()
if not ret:
print("错误:无法读取摄像头帧。")
time.sleep(0.5) # 等待一下再试
continue

# 调整帧大小
frame_resized = cv2.resize(frame, SEND_RESOLUTION)

# 将帧编码为 JPEG
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), JPEG_QUALITY]
result, encoded_frame = cv2.imencode('.jpg', frame_resized, encode_param)

if not result:
print("错误:JPEG 编码失败。")
continue

# 将编码后的数据转换为字节
data = encoded_frame.tobytes()

# 发送数据
# UDP 对于数据包大小有限制 (通常 < 65507 字节)
# 如果编码后的帧太大,可能会发送失败或被截断
if len(data) > 65000:
print(f"警告:帧数据过大 ({len(data)} 字节),可能无法完整发送。尝试降低分辨率或 JPEG 质量。")
# 可以选择跳过此帧或尝试发送
# continue # 选择跳过

try:
udp_socket.sendto(data, (TARGET_IP, TARGET_PORT))
# print(f"Sent frame: {len(data)} bytes") # 取消注释以查看发送日志
except socket.error as e:
print(f"发送错误: {e}")
time.sleep(1) # 发送失败时稍作等待

# (可选) 稍微降低帧率,减轻 CPU 负担和网络拥堵
# time.sleep(0.01) # 约等于 100 FPS 的延迟,根据需要调整

except KeyboardInterrupt:
print("\n停止推流...")

finally:
# 清理资源
print("正在释放资源...")
cap.release()
udp_socket.close()
cv2.destroyAllWindows() # 如果在开发板上有显示窗口的话
print("资源已释放。")
1
2
3
4
5

-> Device Drivers │
│ -> Multimedia support (MEDIA_SUPPORT [=y]) │
│ -> Media drivers │
│ (1) -> V4L platform devices (V4L_PLATFORM_DRIVERS [=y])

pip install opencv-python numpy

sudo apt install -y libgl1