ffmpeg-python icon indicating copy to clipboard operation
ffmpeg-python copied to clipboard

adding an exemple for mono extraction

Open lutzray opened this issue 4 years ago • 4 comments

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)

lutzray avatar Aug 28 '21 01:08 lutzray

Can you please share a fully working program? Thanks!

tamararobin1982 avatar Mar 10 '22 10:03 tamararobin1982

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()

lutzray avatar Mar 10 '22 10:03 lutzray

Thanks!!! How do I stream the output using another ffmpeg stream so that I can listen to this?

tamararobin1982 avatar Mar 16 '22 08:03 tamararobin1982

I mean, instead of fn = '/tmp/stereo.wav' I want to use the microphone for streaming chunk by chunk.

tamararobin1982 avatar Mar 21 '22 06:03 tamararobin1982