Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 FFMPEG Script to Cut,Trim, Change FPS & Scale Videos at Different Resolutions

Posted on February 12, 2023

 

Welcome folks today in this blog post we will be showing how to cut,trim and change the fps value and scale mp4 video using the ffmpeg library in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the ffmpeg module using the pip command as shown below

 

 

pip install ffmpeg

 

 

After installing this library you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Python
1
2
3
4
import ffmpeg
import sys
sys.path.append(r'C:\ffmpeg\bin') # your ffmpeg file path

 

 

First of all we are importing the ffmpeg and sys module and then we are setting the path of the ffmpeg library where it is stored inside the local file system.

 

 

Python
1
stream = ffmpeg.input('video.mp4') # video location

 

 

And in the above line we are using the input method to provide the output.mp4 video file as the input to ffmpeg library.

 

 

Python
1
2
3
stream = stream.trim(start = 0, duration=5).filter('setpts', 'PTS-STARTPTS')
 
stream = stream.filter('fps', fps=15, round='up').filter('scale', w=128, h=128)

 

 

And now we are using some methods of the ffmpeg module which includes the trim() method which basically cuts the video from the start to end. And then we use the filter() method to scale and change the fps value of the video

 

 

Python
1
2
3
stream = ffmpeg.output(stream, 'output.mp4')
ffmpeg.run(stream)

 

 

And lastly we are executing the ffmpeg command using the output() method and then we are running the command using the run() method of ffmpeg module.

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme