我目前正在尝试同步音频和视频(视频输出来自OpenCV)。我使用simpleaudio
函数直接从原始源播放音频。我想在音频中添加一个轻微的延迟,因为音频比OpenCV中的视频更早开始。
下面是我的代码
import cv2 as cv
from pydub.playback import _play_with_simpleaudio
cap = cv.VideoCapture(video_file)
first_loop = True
while cap.isOpened():
ret, frame = cap.read()
if not ret: #ret=False means frame is read correctly
print('\nVideo not being read correctly\n')
#cap.release()
break
key_pressed= cv.waitKey(1)
# first_loop to start the audio being played
if first_loop:
playback= _play_with_simpleaudio(audio)
#falsify the first loop so that audio doesn't keep playing
first_loop=False
#release the cap file
cap.release()
#stop the audio from playing
playback.stop()
1条答案
按热度按时间ergxz8rk1#
您可以尝试在音频文件的开头添加尽可能多的静音。
现在您可以使用第二个wav文件作为您的音频文件。