I am using ffmpeg-python (source) to create the effect where you add a blurred background to fill in the sides of a tall vertical video as shown below:
The problem is that the output has no audio attached. Since the clips are the same, I want to keep the audio from one of the clips in the final output. How can I keep the audio? (I don't want to overlay the audio from both and get an echo effect, however!)
This is the function I'm using:
import ffmpeg
def add_blurred_bg():
HEIGHT = 720
WIDTH = 1280
in_file = ffmpeg.input('input.mp4')
probe = ffmpeg.probe('input.mp4')
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
iw=int(video_stream['width'])
ih=int(video_stream['height'])
nw = HEIGHT*iw/ih
(
ffmpeg
.overlay(
in_file.filter('scale', WIDTH, -2).crop(0,(WIDTH*HEIGHT/nw-HEIGHT)/2,WIDTH,HEIGHT).filter('gblur', sigma=40),
in_file.filter('scale', -2, HEIGHT),
x=(WIDTH-nw)/2
)
.output('output.mp4')
.run()
)