ffmpeg-python
ffmpeg-python copied to clipboard
adding an exemple for mono extraction
I struggled to find out where the 'pan' audio filter fits in ffmpeg-python incantation... Here is a working example (maybe you could add it to the rep)
import ffmpeg, numpy as np
# this quietly dumps the right channel into a numpy array
out, _ = (ffmpeg
.input(fn)
.output('pipe:', format='s16le', acodec='pcm_s16le', af='pan=mono|FC=FR')
.global_args("-loglevel", "quiet")
.global_args("-nostats")
.global_args("-hide_banner")
.run(capture_stdout=True))
data = np.frombuffer(out, np.int16)
Can you please share a fully working program? Thanks!
Bein sûr! Voici:
import ffmpeg, numpy as np
import matplotlib.pyplot as plt
# this quietly dumps the right channel into a numpy array
fn = '/tmp/stereo.wav'
out, _ = (ffmpeg
.input(fn)
.output('pipe:', format='s16le', acodec='pcm_s16le', af='pan=mono|FC=FR')
.global_args("-loglevel", "quiet")
.global_args("-nostats")
.global_args("-hide_banner")
.run(capture_stdout=True))
data = np.frombuffer(out, np.int16)
plt.plot(data)
plt.show()
Thanks!!! How do I stream the output using another ffmpeg stream so that I can listen to this?
I mean, instead of fn = '/tmp/stereo.wav' I want to use the microphone for streaming chunk by chunk.