diff --git a/CHANGELOG.md b/CHANGELOG.md index a868aa4a..bfc57297 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased (on "next" branch) ### Added +* FfmpegOutput support custom audio filter ### Changed diff --git a/examples/ffmpeg_audio_filter.py b/examples/ffmpeg_audio_filter.py new file mode 100644 index 00000000..e1106915 --- /dev/null +++ b/examples/ffmpeg_audio_filter.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 +import time + +from picamera2 import Picamera2 +from picamera2.encoders import H264Encoder +from picamera2.outputs import FfmpegOutput + +picam2 = Picamera2() +video_config = picam2.create_video_configuration() +picam2.configure(video_config) +encoder = H264Encoder(10000000) + +# audio filter takes the left channel and copies it to the right channel +# below example copies c0 (left channel) to c1 (right channel) - convert mono to stereo + +# or add audio delay on left channel like this: audio_filter="pan=stereo|adelay=1500|0" +# source for more examples: https://ffmpeg.org/ffmpeg-filters.html#Examples-2 +output = FfmpegOutput( + 'ffmpeg_audio_filter_test.mp4', + audio=True, + audio_filter="pan=stereo|c0=c0|c1=c0" +) + +picam2.start_recording(encoder, output) +time.sleep(10) +picam2.stop_recording() diff --git a/picamera2/outputs/ffmpegoutput.py b/picamera2/outputs/ffmpegoutput.py index e6938d58..d9aef9d4 100644 --- a/picamera2/outputs/ffmpegoutput.py +++ b/picamera2/outputs/ffmpegoutput.py @@ -32,13 +32,14 @@ class FfmpegOutput(Output): audio_samplerate, audio_codec, audio_bitrate - the usual audio parameters. """ - def __init__(self, output_filename, audio=False, audio_device="default", audio_sync=-0.3, + def __init__(self, output_filename, audio_filter, audio=False, audio_device="default", audio_sync=-0.3, audio_samplerate=48000, audio_codec="aac", audio_bitrate=128000, pts=None): super().__init__(pts=pts) self.ffmpeg = None self.output_filename = output_filename self.audio = audio self.audio_device = audio_device + self.audio_filter = audio_filter self.audio_sync = audio_sync self.audio_samplerate = audio_samplerate self.audio_codec = audio_codec @@ -71,6 +72,8 @@ def start(self): '-i', self.audio_device] audio_codec = ['-b:a', str(self.audio_bitrate), '-c:a', self.audio_codec] + if self.audio_filter: # Check if audio_filter is not empty or None + audio_codec.extend(['-af', self.audio_filter]) command = ['ffmpeg'] + general_options + audio_input + video_input + \ audio_codec + video_codec + self.output_filename.split()