简体   繁体   中英

Python play audio in sync with cv2 video

我对cv2库非常cv2 ,并且由于我最近发现它无法播放音频,所以我想知道是否还有另一个库可以让我与视频本身同步播放音频(最好不需要音频文件) ,仅使用视频的音频)

Turns out there is a very simple method that I will found after researching later, unfortunately, it requires a separate audio file that matches the video: First, import simpleaudio as sa (install it with pip if necessary) and then add this piece of code to your cv2 video player. Add it before the while loop but after the line of code that defines the video file:

wave_obj = sa.WaveObject.from_wave_file("AudioFile.wav")
wave_obj.play()

Then you must manually adjust the waitKey until the audio matches the video, otherwise it might be too fast or too slow. Generally a value close to 25 must be used, and if the audio abruptly ends, try adding one to the value until it matches

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM