23

I want to resize a video clip in python 2.7.

For example we give "movie.mp4" with 1080p quality The result should be "movie.mp4" with 360p quality

I Think that there should be solutions with Moviepy. If you know a solution with it.

I would be grateful if you answer me.

Seyed Ali Akhavani
  • 633
  • 1
  • 6
  • 18
  • 1
    have you read the doc http://zulko.github.io/moviepy/ref/videofx/moviepy.video.fx.all.resize.html?highlight=resize#moviepy.video.fx.all.resize yet? – dragon2fly Feb 06 '15 at 08:01

3 Answers3

48

Here is how you resize a movie with moviepy: see the mpviepy doc here

import moviepy.editor as mp
clip = mp.VideoFileClip("movie.mp4")
clip_resized = clip.resize(height=360) # make the height 360px ( According to moviePy documenation The width is then computed so that the width/height ratio is conserved.)
clip_resized.write_videofile("movie_resized.mp4")

You can also tune the quality by adding the parameter bitrate="500k" or bitrate="5000k" in the last line.

As said above, you could also use ffmpeg directly, it will be simpler if you just need a quick script.

Community
  • 1
  • 1
Zulko
  • 3,540
  • 1
  • 22
  • 18
  • 2
    if you wish to freely set width and height without having to stick to relative scaling of w:h, you can use the `newsize` parameter, ex. `clip_resized = clip.resize(newsize=(my_width,my_height))` – Zahra May 06 '20 at 19:10
10

Why not ffmpeg?

ffmpeg -i movie.mp4 -vf scale=640:360 movie_360p.mp4

If you use 640:-2 then, in this example, the scale filter will preserve the aspect ratio and automatically calculate the correct height.

Look at the H.264 encoding guide for additional options.

slhck
  • 36,575
  • 28
  • 148
  • 201
John Hua
  • 1,400
  • 9
  • 15
3

Moviepy Resize function

>>> myClip.resize( (460,720) ) # New resolution: (460,720)
>>> myClip.resize(0.6) # width and heigth multiplied by 0.6
>>> myClip.resize(width=800) # height computed automatically.
>>> myClip.resize(lambda t : 1+0.02*t) # slow swelling of the clip