python - CV2 不允许十进制 fps 并且视频显示大小已关闭
问题描述
cv2.waitKey 不允许使用小数,因此我的帧速率为 59.97fps 的视频只能以 59 运行。这会导致视频和音频无法正确同步。此外,某些视频的显示尺寸不会填满整个屏幕,而是会被截断。在此先感谢:)这是我的代码:
import cv2
import numpy as np
#ffpyplayer for playing audio
from ffpyplayer.player import MediaPlayer
userinput = input('What video u want? ')
variable = 'j'
video_path = ""
while(userinput != 'v'):
if(userinput.find("LTP") != -1):
video_path = "LTP.mp4"
break
if(userinput.find("Henry") != -1):
video_path= "Henry Smith.mp4"
break
if(userinput.find("Apple")!= -1):
video_path = "Apple Factory.mp4"
break
if(userinput.find("Grinch") != -1):
video_path = "Grinch Sample.mp4"
break
def PlayVideo(video_path):
video=cv2.VideoCapture(video_path)
player = MediaPlayer(video_path)
fps = video.get(cv2.CAP_PROP_FPS)
interval = int(1000/fps)
while True:
grabbed, frame=video.read()
audio_frame, val = player.get_frame()
if not grabbed:
print("End of video")
break
if cv2.waitKey(interval) & 0xFF == ord("q"):
break
cv2.imshow("Video", frame)
if val != 'eof' and audio_frame is not None:
#audio
img, t = audio_frame
video.release()
cv2.destroyAllWindows()
PlayVideo(video_path)
解决方案
推荐阅读
- docusignapi - 用于将通知/提醒发送到进程内信封的 docusign REST API
- c# - 设置父级时是否可以初始化嵌套属性?
- python-3.x - Pandas:使用 DataFrameGroupBy.filter() 方法选择 DataFrame 的行,其值大于相应组的平均值
- android - 如何销售与图书捆绑的付费应用程序?
- java - (Node.js, socket.io) JSONObject 无法转换为 int
- mysql - mysql 使用连接表和计数将动态日期从行转置到列
- sql-server - 将 Python 库导入 SQL Server
- azure-devops - 用于 Runbook 的 Azure ARM 模板,其中包含来自 Azure Git Repo 的 Powershell 文件
- javascript - JS如何更新列表项
- python-3.x - tika-python 的语言检测不起作用