首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Python播放视频OpenCV中的声音

如何用Python播放视频OpenCV中的声音
EN

Stack Overflow用户
提问于 2018-03-29 01:54:30
回答 1查看 13.3K关注 0票数 0

我在python中播放一个mp4文件,但是视频的声音没有出来,我搜索了一段时间,如果它要播放声音,但我找不到任何东西。有人知道怎么放声音吗?

我发布了显示de视频的代码:

代码语言:javascript
复制
import cv2
import numpy as np
 
# Create a VideoCapture object and read from input file
# If the input is the camera, pass 0 instead of the video file name
cap = cv2.VideoCapture('video.mp4')
 
# Check if camera opened successfully
#if (cap.isOpened()== False): 
 # print("Error opening video stream or file")
 
# Read until video is completed
while(cap.isOpened()):
  # Capture frame-by-frame
  ret, frame = cap.read()
  if ret == True:
 
    # Display the resulting frame
    cv2.imshow('Frame',frame)
 
    # Press Q on keyboard to  exit
    if cv2.waitKey(25) & 0xFF == ord('q'):
      break
 
  # Break the loop
  else: 
    break
 
# When everything done, release the video capture object
cap.release()
 
# Closes all the frames
cv2.destroyAllWindows()

OpenCV不允许播放声音似乎毫无用处。顺便说一下,我正在使用Python 3。谢谢。

回答: OpenCV是一个计算机视觉库.它不支持音频。如果你想播放声音,你可以试试夫比播放器。-多亏了>>> yushulx

EN

Stack Overflow用户

发布于 2020-05-10 17:49:57

你可以使用Pyglet播放视频和它的音频..。希望这能帮上忙。

代码语言:javascript
复制
import pyglet
vid_path='vid1.mp4' # Name of the video
window=pyglet.window.Window()
player = pyglet.media.Player()
source = pyglet.media.StreamingSource()
MediaLoad = pyglet.media.load(vid_path)

player.queue(MediaLoad)
player.play()

@window.event
def on_draw():
    if player.source and player.source.video_format:
        player.get_texture().blit(50,50)


pyglet.app.run()
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49546837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档