使用pygame覆盖显示YUV420p会导致imag顶部的绿色条

2024-04-25 21:57:05 发布

您现在位置:Python中文网/ 问答频道 /正文

代码如下。图像由PyAV库解码。在图片的顶部有一个水平的绿色条。大概1像素高。你知道怎么避免吗?我已经看到很多建议VLC播放器禁用硬件加速。它已在pygame中禁用。我在Windows1064bit上工作。你知道吗

import av
import pygame
import time

container = av.open('video.mp4') # libx264 en-/decoded, pixel format yuv420p
container.streams.video[0].thread_type = 'AUTO'
frameSequence = container.decode(video=0)
for _ in range(100):
    image = next(frameSequence) #skip some frames
pygame.init()
trueResolution = pygame.display.list_modes()[0]  # corresponds to video, as it FULL HD
                                                 #also tested with HD
pygame.display.set_mode(trueResolution)
ovl = pygame.Overlay(pygame.YV12_OVERLAY,trueResolution)
ovl.display((image.planes[0], image.planes[1], image.planes[2]))
time.sleep(10)

我还尝试用其他行替换每个平面中的第一行,以检查图像是否损坏。结果是一样的,所以图像似乎是正确的。你知道吗

升级1。视频链接https://drive.google.com/file/d/1t6d5weBVeW4EWzGI1gytmUBwXF91dNC9/view?usp=sharing

图片上方有绿线的截图 The screenshot with a green line on top of the image


Tags: 图像imageimporttimecontainervideodisplay图片
1条回答
网友
1楼 · 发布于 2024-04-25 21:57:05

您可以缩小到屏幕大小并更改覆盖的位置以隐藏绿色条。我知道这不是一个解决办法,但你可能会发现它足够好的进展。你知道吗

覆盖的文档确实警告:

The Overlay objects represent lower level access to the display hardware. To use the object you must understand the technical details of video overlays.

因此,拥有更多领域专业知识的人可能能够提供更好的解决方案。你知道吗

pygame.display.set_mode((1280,  718), pygame.RESIZABLE)
ovl = pygame.Overlay(pygame.YV12_OVERLAY,trueResolution)
ovl.set_location(pygame.Rect(0,-2,1280, 720))

注意trueResolution应该从源流而不是图形卡支持的full screen modes确定。你知道吗

另外,本例中的image是一个VideoFrame,您可以使用它的.to_image()方法来转换为PIL类型的图像或.to_rgb(),如果您不想/不需要使用覆盖,它可能更容易显示。你知道吗

相关问题 更多 >

    热门问题