MoviePy – Resizing Video File
Last Updated :
29 Dec, 2021
In this article, we will see how we can resize video file clips in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. Resizing video files means. Image/frame interpolation occurs when you resize or distort your frame of video from one-pixel grid to another. Video resizing is necessary when we need to increase or decrease the total number of pixels, whereas remapping can occur when you are correcting for lens distortion or rotating a video.
In order to do this we will use resize method with the VideoFileClip object
Syntax : clip.resize(n)
Argument : It takes float value i.e multiplier
Return : It returns VideoFileClip object
Below is the implementation
Python3
from moviepy.editor import *
clip1 = VideoFileClip( "dsa_geek.webm" ).subclip( 0 , 5 )
w1 = clip1.w
h1 = clip1.h
print ( "Width x Height of clip 1 : " , end = " " )
print ( str (w1) + " x " , str (h1))
print ( "---------------------------------------" )
clip2 = clip1.resize( 0.5 )
w2 = clip2.w
h2 = clip2.h
print ( "Width x Height of clip 2 : " , end = " " )
print ( str (w2) + " x " , str (h2))
print ( "---------------------------------------" )
clip2.ipython_display(width = 480 )
|
Output :
Width x Height of clip 1 : 854 x 480
---------------------------------------
Width x Height of clip 2 : 427 x 240
---------------------------------------
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4
Another example
Python3
from moviepy.editor import *
clip = VideoFileClip( "geeks.mp4" )
clip1 = clip.subclip( 0 , 7 )
w1 = clip1.w
h1 = clip1.h
print ( "Width x Height of clip 1 : " , end = " " )
print ( str (w1) + " x " , str (h1))
print ( "---------------------------------------" )
clip2 = clip1.resize( 0.5 )
w2 = clip2.w
h2 = clip2.h
print ( "Width x Height of clip 2 : " , end = " " )
print ( str (w2) + " x " , str (h2))
print ( "---------------------------------------" )
clip2.ipython_display()
|
Output :
Width x Height of clip 1 : 656 x 404
---------------------------------------
Width x Height of clip 2 : 328 x 202
---------------------------------------
Moviepy - Building video __temp__.mp4.
MoviePy - Writing audio in __temp__TEMP_MPY_wvf_snd.mp3
MoviePy - Done.
Moviepy - Writing video __temp__.mp4
Moviepy - Done !
Moviepy - video ready __temp__.mp4
Share your thoughts in the comments
Please Login to comment...