Need example code of in-memory processing #22
-
|
Thanks for the good job.
in this process, it takes resample, rechannel, volume normalize and codec [from PCM24 to PCM16]. but now I want this process to be in memory, which means the input, or the output [or maybe both] is a numpy-array or some other in memory array data, instead of a file in disk, How to make such a process? thanks |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 8 replies
-
|
@JohnHerry - (Moved your post from Issue to Discussions section.) You'd want to use import ffmpegio as ff
fsout , dataout= ff.audio.filter('loudnorm=I=-23', fsin, datain, ar=16000, ac=1)Assuming you're using |
Beta Was this translation helpful? Give feedback.
-
|
Thank you very much |
Beta Was this translation helpful? Give feedback.
-
|
You're welcome. (I'm reopening this discussion as I want others to be able to see it easily) |
Beta Was this translation helpful? Give feedback.
-
|
An exception. The result audio file seems downsampled by the processing and left a mess. that means when the input sample just fit part of the filter (in my example, samplling_rate and channels ), the result will be wrong? Python==3.9.9 |
Beta Was this translation helpful? Give feedback.
-
|
What do you mean by "the input sample just fit part of the filter "? As far as I can tell on my end, Please try to run it with debug logger on and check the executed ffmpeg command line. My guess is that there is something funny going on with Here is my test script: import ffmpegio as ff
import logging
import numpy as np
logging.basicConfig(level=logging.DEBUG)
x = np.random.randint(-2**15,2**15,(16000,2),np.int16)
fs = 16000
fs_out, y = ff.audio.filter(ff.filtergraph.loudnorm(I=-24), fs, x, ar=fs, ac=1)
print(fs_out)
print(y.shape)This should print a line (among others): If still not resolved, post your command line as well as dtype of the input array. P.S., BTW, you don't need to rely on sr, audio_in = ff.audio.read(input_file) |
Beta Was this translation helpful? Give feedback.
-
|
the result y.shape is (result_sample_length, 1), not two-channel. |
Beta Was this translation helpful? Give feedback.



@JohnHerry - (Moved your post from Issue to Discussions section.) You'd want to use
audio.filter()function.Assuming you're using
ffmpegiopackage and not justffmpegio-core, here you preparedatainas a 2D Numpy array with column-wise channels and specify its sampling rate infsin. The function returns the processed output data with its sampling rate firstfsoutfollowed bydataoutnumpy array.