playing audio generate noise... #857
Unanswered
MenGuangwen0411
asked this question in
1. Help
Replies: 1 comment
-
Most likely a bug in #1022 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I use pyav on win10 as:
from future import print_function
from PyQt5.QtMultimedia import *
import time
import av
container = av.open(r'd:\king.mp4')
stream = next(s for s in container.streams if s.type == 'audio')
fifo = av.AudioFifo()
resampler = av.AudioResampler(
format=av.AudioFormat('s16').packed,
layout='stereo',
rate=48000,
)
qformat = QAudioFormat()
qformat.setByteOrder(QAudioFormat.LittleEndian)
qformat.setChannelCount(2)
qformat.setCodec('audio/pcm')
qformat.setSampleRate(48000)
qformat.setSampleSize(16)
qformat.setSampleType(QAudioFormat.SignedInt)
output = QAudioOutput(qformat)
output.setBufferSize(16 * 48000)
device = output.start()
print(qformat, output, device)
def decode_iter():
try:
for pi, packet in enumerate(container.demux(stream)):
for fi, frame in enumerate(packet.decode()):
yield pi, fi, frame
except:
return
for pi, fi, frame in decode_iter():
while output.state() == QAudio.ActiveState:
time.sleep(0.1)
It works but the sound is very noisy, although hearable, how to deal with the noise?
Beta Was this translation helpful? Give feedback.
All reactions