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.