国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

python將YUV420P文件轉PNG圖片格式的兩種方法

瀏覽:8日期:2022-06-29 11:38:37
方法一:

import osimport cv2 as cvimport numpy as np# 讀取yuv420p的一幀文件,并轉化為png圖片if __name__ == ’__main__’: filepath = ’one_frame_of_highway.yuv’ binfile = open(filepath, ’rb’) size = os.path.getsize(filepath) image_width = 352 image_hight = 288 image_y = [[0] * image_width for i in range(image_hight)] image_u = [[0] * image_width for i in range(image_hight)] image_v = [[0] * image_width for i in range(image_hight)] for r in range(image_hight): for c in range(image_width): image_y[r][c] = binfile.read(1)[0] Image_Y = np.array(image_y) for r in range(int(image_hight / 2)): for c in range(int(image_width / 2)): pixel = binfile.read(1)[0] image_u[2 * r + 0][2 * c + 0] = pixel image_u[2 * r + 1][2 * c + 0] = pixel image_u[2 * r + 0][2 * c + 1] = pixel image_u[2 * r + 1][2 * c + 1] = pixel Image_U = np.array(image_u) for r in range(int(image_hight / 2)): for c in range(int(image_width / 2)): pixel = binfile.read(1)[0] image_v[2 * r + 0][2 * c + 0] = pixel image_v[2 * r + 0][2 * c + 1] = pixel image_v[2 * r + 1][2 * c + 0] = pixel image_v[2 * r + 1][2 * c + 1] = pixel Image_V = np.array(image_v) binfile.close() compose = np.array([Image_Y, Image_V, Image_U]).transpose([1, 2, 0]).astype(np.uint8) Image = cv.cvtColor(compose, cv.COLOR_YUV2RGB) cv.imwrite('one_frame_of_highway.yuv.png', Image)方法二:

ffmpeg -s 352x288 -i one_frame_of_highway.yuv one_frame_of_highway.png

highway視頻網址:http://trace.eas.asu.edu/yuv/index.html

附錄:

將yuv文件轉化為一幀幀yuv文件

#include <stdio.h>#include <fcntl.h>#include <zconf.h>#include <stdint.h>#include <strings.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>int File_Size(int fd) { struct stat st; fstat(fd, &st); return st.st_size;}int Frame_Size_Of_Cif() { int width = 352; int heigh = 288; int Y_SIZE = width * heigh; int U_SIZE = Y_SIZE / 4; int V_SIZE = Y_SIZE / 4; int Frame_SIZE = Y_SIZE + U_SIZE + V_SIZE; return Frame_SIZE;}int Frames_Of_Cif_File(int fd) { if (fd < 0) { printf('Invalid FD!'); return -1; } int Frame_SIZE = Frame_Size_Of_Cif(); int fd_size = File_Size(fd); return fd_size / Frame_SIZE;}void Abstract_Frame_From_CIF_File(int fd,char *Path_And_Prefix_Img,int Len) { int Frame_SIZE = Frame_Size_Of_Cif(); char file[128]; memset(file,0,128); memcpy(file,Path_And_Prefix_Img,Len); uint8_t buf[Frame_SIZE]; int ret = -1; int frames = 0; while ((ret = read(fd, buf, Frame_SIZE))) { frames += 1; uint64_t len = strlen(file); sprintf(file + len, '%d', frames); len = strlen(file); sprintf(file + len, '%s', '.yuv'); int fdw = open(file, O_RDWR | O_CREAT, 0777); write(fdw, buf, ret); memset(file,0,128); memcpy(file,Path_And_Prefix_Img,Len); close(fdw); } printf('Abstract %d frames!n', frames);}int main() { int fd = open('./yuv420p_352x288.yuv', O_RDONLY); Abstract_Frame_From_CIF_File(fd,'/home/liu/Frames/Frames_',strlen('/home/liu/Frames/Frames_')); close(fd); return 0;}

以上就是python將YUV420P文件轉PNG圖片格式的兩種方法的詳細內容,更多關于python將YUV420P文件轉PNG的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 三级黄色毛片视频 | 久久精品香蕉视频 | 久久成人精品 | 毛片免费看看 | 久久草在线观看 | 色偷偷在线刺激免费视频 | 日本一区二区三区免费视频 | 草久在线观看 | 国产系列在线观看 | 看一级毛片国产一级毛片 | 欧美成人一级 | 日本成人免费在线观看 | 国产一级特黄一级毛片 | 国产欧美一区二区精品性色 | 免费看黄网址 | 免费看成人频视在线视频 | 午夜香蕉成视频人网站高清版 | 国产一区亚洲二区 | 亚洲大片 | 90岁老太婆一级毛片 | 久久国产毛片 | 久久久综合结合狠狠狠97色 | 日本免费毛片在线高清看 | 亚洲精品国产经典一区二区 | 韩国三级日本三级香港三级黄 | 在线播放免费播放av片 | 91视频综合网 | 国产成人永久免费视频 | 亚洲男人的天堂在线 | 亚洲另类在线视频 | 国产3区 | 一级毛片免费观看不卡视频 | 国产成人精品三级91在线影院 | 综合自拍亚洲综合图区美腿丝袜 | 色老头久久久久 | 亚洲综合精品一二三区在线 | 日本视频免费在线播放 | 日韩久久综合 | 欧美一级毛片一级毛片 | 久草最新在线 | 悟空影视大全免费高清 |