0

I am using opencv for analysing a video. However, after I use the cv2.VideoCapture() function(analysing using YOLO Darknet) I am unable to retrieve the audio files. How do I attach the audio files so that it plays like a normal audio file.

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()

As far as I know cv2 only extracts the frames and not the audio hence when I convert the frames back to video I obtain a no-audio video.

robotlover
  • 331
  • 1
  • 2
  • 12
  • Please provide a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve), so we have an easier time helping you. – Tim Schmidt Sep 25 '18 at 13:14
  • I have made the edits – robotlover Sep 25 '18 at 13:18
  • You will need to find and pick a library that's focused on reading/writing/editing of AV files. OpenCV is focused on computer vision, so what you ask for is out of scope -- all you get is some convenience tools to read/write image data. – Dan Mašek Sep 25 '18 at 13:33

0 Answers0