python 播放 yuv
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)
ffplay 播放 yuv
ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 video1.yuv
vlc 可以直接播放 h264 文件
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/18025160