install asitop

install asitop 但是找不到

pip3 install asitop

安装成功了,但是显示

1
2
3
Installing collected packages: asitop

WARNING: The script asitop is installed in '/Users/PeppaZhu/Library/Python/3.9/bin' which is not on PATH.

然后无法运行asitop which whereis都找不到

需要添加环境变量

1
echo -e 'export PATH="$PATH:/Users/PeppaZhu/Library/Python/3.9/bin"' >> $HOME/.bash_profile

然后就可以了

然后下次打开咋又不行了呢

需要source ~/.bash_profile 使得环境变量生效

YUV storage

令人迷惑的YUV存储模式

奇怪的知识增加了

除YUV之外,经常提到的还有 YPbPr 和 YCbCr。YPbPr 指模拟分量信号(或接口),P(Parallel)表示并行,b 下标表示蓝,r 下标表示红。YCbCr 指的是数字分量信号(或接口),C(Chroma)表示色度。YCbCr 还可指色彩空间,YCbCr 色彩空间是 YUV 色彩空间的缩放和偏移版本。

YUV采样方式

主流的采样方式有三种,YUV4:4:4,YUV4:2:2,YUV4:2:0。这些采样方式,不压缩 Y 分量,对 UV 分量的压缩程度不同。

YUV存储方式

存储模式分成三大类:

packed:将 Y、U、V 分量交织存放在一起,和 RGB 的存放方式类似。内存中排列形式类似:YVYUYVYUYVYUYVYU…。在具体的存储模式命名中,packed 格式不带后缀 P。

planar:将 Y、U、V 的三个分量分别存放在不同的矩阵(平面)中。内存中排列形式类似:YYYYYY…,UUUUUU…,VVVVVV…。在具体的存储模式命名中,planar 格式带后缀 P。

semi-planar:将 Y、U、V 三个分量放在两个矩阵(平面)中。Y 占用一个平面,UV 共用一个平面。内存中排列形式类似:YYYYYY…,UVUVUV…。在具体的存储模式命名中,semi-planar 格式带后缀 SP。

存储方式加上采样方式

https://developer.aliyun.com/article/782082

其中有些常用的

semi-planar 存储模式 YUV420SP

NV12:

1
2
3
4
5
6
7
Y Y Y Y
Y Y Y Y
Y Y Y Y
Y Y Y Y
-------
U V U V
U V U V

NV21:

1
2
3
4
5
6
7
Y Y Y Y
Y Y Y Y
Y Y Y Y
Y Y Y Y
-------
V U V U
V U V U

planar 存储模式 YUV420P

YU12/IYUV/I420:

1
2
3
4
5
6
7
8
9
10
Y Y Y Y
Y Y Y Y
Y Y Y Y
Y Y Y Y
-------
U U
U U
---
V V
V V

YV12:

1
2
3
4
5
6
7
8
9
10
Y Y Y Y
Y Y Y Y
Y Y Y Y
Y Y Y Y
-------
V V
V V
---
U U
U U

一段读取YUV420数据的代码

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
class VideoCaptureYUV:
def __init__(self, filename, size):

​ self.width, self.height = size

​ self.Y_len = self.width * self.height

​ self.UV_len = self.width * self.height // 4

​ self.f = open(filename, 'rb')

​ self.Y_shape = (self.height, self.width)

​ self.UV_shape = (self.height//2, self.width//2)



​ def read_raw(self):

​ raw = self.f.read(self.Y_len)

​ Y = np.frombuffer(raw, dtype=np.uint8)

​ Y = Y.reshape(self.Y_shape)



​ raw = self.f.read(self.UV_len)

​ u = np.frombuffer(raw, dtype=np.uint8)

​ u = u.reshape(self.UV_shape)





​ raw = self.f.read(self.UV_len)

​ v = np.frombuffer(raw, dtype=np.uint8)

​ v = v.reshape(self.UV_shape)

​ return Y,u,v



​ def read(self):

​ Y,u,v = self.read_raw()

​ img = np.concatenate((Y.reshape(-1), u.reshape(-1), v.reshape(-1)))

​ img = img.reshape((self.height * 3 // 2, self.width)).astype('uint8') # YUV 的存储格式为:I420(YYYY UUVV)

​ \#print(yuv.shape)

​ bgr = cv2.cvtColor(img, cv2.COLOR_YUV2BGR_I420)

​ return bgr

ffmpeg record

深海巨坑ffmpeg的使用记录

服务器上安装

apt install ffmpeg

将多帧图像合成视频

ffmpeg -r 30 -i output_video/%05d.jpg -vcodec libx264 -vf zscale=matrix=709:r=full output_video_fullr.mp4

-vf zscale=matrix=709:r=limited负责转换色域,否则默认转出来是BT.601之类的SD标准。显式指定limited 色域很多种,limited显得饱和度高一些,full色域大,同样数据显得饱和度低一些

这个链接 https://fireattack.github.io/blog/2018/07/03/ffmpeg-commands.html

编码质量控制: -c:v libx264 -preset veryslow -crf 0

将yuv视频分png

ffmpeg -s 1080x720 -pix_fmt yuv420p -i dst_1080x720_30Hz_P420.yuv -vf scale=in_range=full:out_range=full output_ori/%05d.png
-vf scale=in_range=full:out_range=full 来控制色彩
这个链接 https://www.bilibili.com/read/cv6601959/

截取视频片段

按照时间截取

ffmpeg -i input.mp4 -vcodec copy -acodec copy -ss 00:00:00 -to 00:00:05 cutout.mp4 -y

按照帧截取

ffmpeg -i input.mp4 -vf”select=between(n,20,200)” -y -acodec copy cutout.mp4

将YUV转成MP4

ffmpeg -s 640x480 -pix_fmt yuv420p -i output.yuv out3.mp4

将MP4转YUV

ffmpeg -i input.mp4 -s 640x480 -pix_fmt yuv420p output.yuv

视频分帧

ffmpeg -i backlit.mp4 -r 30 backlit/%05d.png

如果改成jpg会有严重压缩

如果转化成png还有压缩的话,可以先将mp4转成yuv, yuv单帧的质量也就是图片单帧能达到的最高质量。然后将yuv视频转化成图像。

将视频拼接

ffmpeg -i peppa_v3_fullr.mp4 -i peppa_v5_fullr_.mp4 -filter_complex "[0:v]pad=iw*2:ih*1[a];[a][1:v]overlay=w" compair_peppa_v3v5.mp4

这个链接 https://blog.csdn.net/Gary__123456/article/details/88742705

转封装

ffmpeg -i xx.mov c:v copy xx.mp4

视频resize

ffmpeg -i testbanding.mp4 -s 1280:720 -aspect “16:9” testbanding_1280x720.mp4

一张图片转视频

ffmpeg -r 10 -f image2 -loop 1 -i 1.jpg -s 1080x1920 -pix_fmt yuvj420p -t 4 -vcodec libx264 1.mp4