Skip to content

Coding Shiksha

Menu
  • Home
  • Youtube Channel
  • Online Store
  • Online Tools
  • Donate Us
  • Sitemap
  • Privacy Policy
Menu

Python 3 FFMPEG Script to Build Video & Audio Converter Using ffmpy Module in Command Line

Posted on October 28, 2022

Welcome folks today in this blog post we will be building a video & audio converter in python using ffmpeg library in command line. All the full source code of the example will be shown below.

 

 

Get Started

 

 

First of all guys you need to install the below dependencies using the pip command as shown below

 

 

pip install ffmpy

 

 

This is the actual ffmpeg client package available for python with the help of which you can execute any ffmpeg operation in python. For this library to work you need the ffmpeg software installed on your system and also set the ffmpeg library inside environment variables as shown below

 

You need to set the global path of ffmpeg binary inside the environment variables as shown below

 

 

 

 

 

After that you need to make an app.py file and copy paste the below code

 

 

app.py

 

 

1
2
3
4
5
import ffmpy
ff = ffmpy.FFmpeg(
    inputs = {"video.mp4": None},
    outputs = {"video.gif": None})
ff.run()

 

 

As you can see in the above code we are importing the ffmpy module at the top and then we are using the FFmpeg() method to convert the input video mp4 file to gif output video file. And lastly we are running the ffmpeg() command using the run() command. So if you execute this python script using the below command as shown below

 

 

python app.py

 

 

 

 

 

 

Here in the above code you can replace any extension such as mp3,mp4,gif,mov etc. to build a fully fledged audio and video converter in python using ffmpeg in command line

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

©2023 Coding Shiksha | Design: Newspaperly WordPress Theme