【问题标题】:How to play video with the audio in open cv python from the particular frame?如何在特定帧的 open cv python 中播放带有音频的视频?
【发布时间】:2019-12-06 16:28:35
【问题描述】:

我必须播放来自特定帧的视频,我可以使用 opencv 来完成,但是如何播放该特定视频的音频 我有我必须开始播放视频的帧,我也想要相应的音频。

cap = cv2.VideoCapture('tcs.mp4')
fps = cap.get(cv2.CAP_PROP_FPS)
count = 0
success = True
while success:
    success,frame = cap.read()
    count+=1
    ts = count/fps
    if t == ts:
      print("time stamp of current frame:",count/fps)
      print("Press Q to quit")
      f_count = count
cap.set(cv2.CAP_PROP_POS_FRAMES, f_count)
# Check if camera opened successfully 
if (cap.isOpened()== False):  
  print("Error opening video  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() 

【问题讨论】:

标签: python opencv


【解决方案1】:

OpenCV 是一个计算机视觉库。要播放音频,您必须使用另一个库(即在 C++ 中,使用 FFMPEG)。

Python 中的替代方案是 ffpyplayer (https://pypi.org/project/ffpyplayer/),它基于 FFMPEG。

可以使用OpenCV处理帧,显示帧的同时播放ffpyplayer抓取的音频帧。

更好的选择是在 OpenCV 中处理视频文件并将其写入磁盘,然后使用 python-VLC 播放。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 2013-03-02
    相关资源
    最近更新 更多