How to convert the sample rate with ffmpeg-python

Question:

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)
Asked By: Nori

||

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.

Answered By: Nori
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.