Skip to content
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

feat(FfmpegOutput): add audio filter support #1039

Merged

Conversation

StephenGrable1
Copy link

@StephenGrable1 StephenGrable1 commented May 25, 2024

tldr; this pr enables support for ffmpeg audio filters so it is easy to configure and customize audio recordings.

I do this by adding a new audio_filter parameter to the FfmpegOutput interface which passes it to the -af flag for audio configuration.

ive also added a simple example where i convert a mono audio input into stereo while recording a 10 second video.
but you can also do cool things like add delay or add echo

Ps. thanks for the awesome library, i love the pdf documentation and in-depth examples, it has helped me a ton.

@StephenGrable1 StephenGrable1 changed the base branch from main to next May 25, 2024 19:23
@StephenGrable1 StephenGrable1 changed the title add ffmpeg audio filter support feat(FfmpegOutput): add audio filter support May 25, 2024
@davidplowman
Copy link
Collaborator

Hi Stephen, thanks very much for this PR. It all looks good to me, I just notice a couple of complaints from flake8 (which I often find to complain over nothing much, but we seem to be using it...). Would you be able to patch those little things up and then I'd be OK to merge. Thanks again!

@StephenGrable1
Copy link
Author

StephenGrable1 commented Nov 19, 2024

Hi Stephen, thanks very much for this PR. It all looks good to me, I just notice a couple of complaints from flake8 (which I often find to complain over nothing much, but we seem to be using it...). Would you be able to patch those little things up and then I'd be OK to merge. Thanks again!

hey @davidplowman sorry for the late follow up here but i finally got around to linting these files - i also added some more context and helpful links to the added example as well

does this still look good to merge in?

@StephenGrable1 StephenGrable1 force-pushed the ffmpeg-custom-audio-filter branch 2 times, most recently from 407c295 to 12ac8a5 Compare November 19, 2024 02:05
@@ -70,7 +71,8 @@ def start(self):
'-thread_queue_size', '1024', # necessary to prevent warnings
'-i', self.audio_device]
audio_codec = ['-b:a', str(self.audio_bitrate),
'-c:a', self.audio_codec]
'-c:a', self.audio_codec,
-'af', self.audio_filter]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I merge this, just one thing I wanted to understand. We're now setting the audio filter to pan=stereo by default. Is this a change in behaviour, or was it doing the same thing before? (If it is a change, do you know what you would put to get the previous behaviour?) Thanks!

Copy link
Author

@StephenGrable1 StephenGrable1 Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I intended this to be a sane default, but looking into it a bit more, if the input or soundcard is configured for mono, this would indeed change it to stereo (the -af default will reflect the input signal/channel setup if nothing is provided to that argument). Its quite rare that a device nowadays would be mono, but im sure there are use-cases for that.

So I went ahead and removed the default parameter to pan=stereo so it will have the same behavior as before, while allowing it to be customized if an arg is passed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we've still got the problem where audio_filter is a required parameter, and causing a test failure. Could we put it back where it was (i.e. just before pts, just in case anyone out there has hard-coded the order of all those audio parameters) and default it to None. Then I think the code you've got after that looks good.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 💯

@StephenGrable1 StephenGrable1 force-pushed the ffmpeg-custom-audio-filter branch 3 times, most recently from 550f614 to 3f09d35 Compare November 19, 2024 14:39
Signed-off-by: Stephen Grable  <stephengrable@gmail.com>
@davidplowman davidplowman merged commit d77e751 into raspberrypi:next Nov 19, 2024
4 checks passed
@davidplowman
Copy link
Collaborator

Thank you very much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants