Reputation: 33
I'm trying to write an app which resizes video files, and the easiest way to do that is moviepy. However, I can't use resize function of moviepy. It seems unsolved reference. Part of my code is here:
I tried to solve my problem using ffmpeg with subprocess, but it did not work.
from moviepy.editor import *
video_path = self.file_name2process.text()
video2process = VideoFileClip(video_path)
video2process_resized = video2process.resize(height=360)
video2process_resized.write_videofile("new.mp4")
It does not show up any error message, because it does not recognize resize part. Since it does not recognize resize part, it also does not allow me to use 'write_videofile' function. Somehow, when I look into 'VideoFileClip' module, I can see resize function there, but I cannot reach that.
Here is the screenshot: https://i.hizliresim.com/5NqQAL.png
Upvotes: 3
Views: 1571
Reputation: 350
For anyone stumbling about it with blind eyes like I did: The resize function returns a copy of the resized clip. You need to reassign the variable! I know Shivam's answer contains the solution, but I did not notice it until if found the answer explicitly on reddit. The moviePy documentation is confusing because the example does not show the reassignment.
resizedClip = oldClip.resize(width=400)
Upvotes: 1
Reputation: 376
Yes, it shows resize as an unresolved reference, but does the job anyway.
from moviepy.editor import VideoFileClip
disk_video_path = get_tmp_video_file_path(video)
clip = VideoFileClip(disk_video_path)
video_max_height = int(get_config_value(STORY_VIDEO_HEIGHT))
if clip.h > video_max_height:
clip_resized = clip.resize(height=video_max_height)
clip_resized.write_videofile(RESIZED_STORY_VIDEO_NAME, temp_audiofile="temp-audio.m4a",
remove_temp=True,
codec="libx264",
audio_codec="aac", fps=30,
logger=None, threads=4)
clip.close()
Upvotes: 1