How to convert the sample rate with ffmpeg-python

Viewed 884

I'm using ffmpeg-python. I would like to change the sample rate of the audio file.

In ffmpeg-, it seems that you can change the sample rate as follows.

ffmpeg -i" movie.mp3 "-y" movie.flac "-ar 44100

-ar is sample rate.

How do I change the sample rate by ffmpeg-python?

This is my source code that is currently being written.

stream = ffmpeg.input(input_file_path)
audio = stream.audio
stream = ffmpeg.output(audio, output_file_path)
ffmpeg.run(stream, capture_stdout=True, capture_stderr=True)
1 Answers

I soleved.

I can set keyword arguments like this.

stream = ffmpeg.output(audio, output_file_path, **{'ar': '16000','acodec':'flac'})

It is important to keep the ** in place. If you remove it, you will get an error.

Related