-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to mix 2 pcm mono audio files using FFmpegFrameFilter class and "amix" filter option #1315
Comments
You're not calling |
Sorry, I forgot to copy the close()/stop()/release() statements for the frame recorder, filter & grabbers. Below is the code snippet from my editor.
|
Ok, next thing, if you'd like the output to have the same sample rate as the inputs, you'll need to set it with |
Thank you for the tips. |
Your inputs are not of the same length. If you need to have everything, you'll need to lengthen the shortest one of them. |
How can I do that without changing the original audio file. |
The number of samples for each is different, you'll need to give it more samples. The |
I have verified with the ffmpeg filter |
JavaCV doesn't do anything. That's how the amix filter works by default.
|
Ah, no, amix should pick the longest stream by default:
https://ffmpeg.org/ffmpeg-filters.html#amix So your code isn't sending all existing samples to amix... |
I will check the code again. FYI, ffmpeg in debug mode shows 57 packets being read from each input which is exactly same no of frames/samples that my program grabs from each input using FFmpegFrameGrabber. All these frames are fed to the filter.
Also I noticed that ffmpeg auto-inserts an extra filter (named
Java console output (using JavaCV in DEBUG mode)
Do you think this could be the issues? |
The number of samples is not the same, that's not necessarily related to the number of frames. Each audio frame may contain a different number of samples. |
Could pleases suggest how can I get the raw data from each frame ( |
That's in the |
Based on your previous input I found that during the last iteration, the grabbed input sample sizes are different for the xmit (1664 bytes) and recv (b4 bytes) audio (the recv.wav file is 200milliseconds shorter). For these samples when the |
EAGAIN means that we must provide more input to the filter, or we won't be getting more output: |
Actually, I think I know what we can do about this. I've just noticed there's a missing call to |
Sorry for late response. I have tested the changes with the following logic for reading the audio samples, but the output file was shorter as before (without padding). Using the debugger I made sure that
|
Ah, I see, there is another issue there, so you're doing it right I think. There must be some other way the ffmpeg program tells the filter about the end of the stream... |
Looking briefly at |
Today, I have tested the previous audio
Also from the API documentation of
|
We need to set a fixed frame size for the output when the encoder doesn't support variable frame size. That's something we should add I suppose, but it's not something anyone has had any problems with yet, and it's not related to the issue you're having. |
Hello,
I am not able to mix two mono pcm ulaw files using FFmpegFrameFilter class with the "amix" option. The output file size is much smaller (78 bytes) as comapred to input (225 KB & 225 KB) and the does not play at all.
Intially I created a mix audio running ffmpeg commandline so that I can compare the results with the output from the java program
ffmpeg -i xmit.wav -i recv.wav -filter_complex [0:a][1:a]amix=inputs=2 ffmpeg-amix-audio.wav
Commad
ffmpeg -i ffmpeg-amix-audio.wav
Console output
My sample java program to mix two audio files using javacv-1.5.1.jar
Eclipse console output does not give any error, however the program failed to read the last sample from each input and the output frame/sample timestamps are different than input. Also the output stream info does not match with ffmpeg output
Here is the ffmpeg output from directly quering the javacv generated file
Command
ffmpeg -i javacv-amix-audio.wav
Console Output
Please suggets how to fix the java program.
The text was updated successfully, but these errors were encountered: