mp4 to yuv
ffmpeg -i video1.mp4 video1.yuv
使用python直接播放yuv
import cv2
import numpy as np
def play_yuv(file_path, width, height):
yuv_file = open(file_path, 'rb')
frame_size = int(width * height * 3 / 2)
while True:
frame_data = yuv_file.read(frame_size)
if not frame_data:
break
yuv_image = np.frombuffer(frame_data, dtype=np.uint8)
yuv_image = yuv_image.reshape((height * 3 // 2, width))
y = yuv_image[:height, :]
u = yuv_image[height:height + height // 4, :]
v = yuv_image[height + height // 4:, :]
bgr_image = cv2.cvtColor(yuv_image, cv2.COLOR_YUV2BGR_I420)
cv2.imshow('YUV Player', bgr_image)
cv2.waitKey(30)
yuv_file.close()
cv2.destroyAllWindows()
if __name__ == '__main__':
play_yuv('/Users/jimogangdan/Downloads/video1.yuv', 1920, 1080)
标签:python,image,cv2,height,file,播放,frame,yuv
From: https://www.cnblogs.com/guanchaoguo/p/18025160