首页 > 解决方案 > Opencv 视频分析音频文件

问题描述

我正在使用 opencv 来分析视频。但是,在我使用 cv2.VideoCapture() 函数(使用 YOLO Darknet 分析)后,我无法检索音频文件。如何附加音频文件,使其像普通音频文件一样播放。

import cvlib as cv
from cvlib.object_detection import draw_bbox
import cv2

# open webcam
webcam = cv2.VideoCapture("143055.crf")

if not webcam.isOpened():
    print("Could not open webcam")
    exit()

image_counter=0
# loop through frames
while webcam.isOpened():

    # read frame from webcam 
    status, frame = webcam.read()

    if not status:
        print("Could not read frame")
        exit()

    # apply object detection
    bbox, label, conf = cv.detect_common_objects(frame)

    print(bbox, label, conf)

    # draw bounding box over detected objects
    out = draw_bbox(frame, bbox, label, conf)

    # display output
    cv2.imshow("Real-time object detection", frame)
    cv2.imwrite('/Users/dukeglacia/Downloads/test_images2/%d.jpg'%image_counter,frame)
    image_counter+=1

    # press "Q" to stop
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# release resources
webcam.release()
cv2.destroyAllWindows()

据我所知,cv2 只提取帧而不是音频,因此当我将帧转换回视频时,我得到一个无音频视频。

标签: pythonopencvaudiovideocvlib

解决方案


推荐阅读