我想要裁剪的视频是16x9分辨率到9x16。这可以通过剪切16x9视频中的607 on宽矩形来实现。这能办到吗?编辑:我不想呆在电影里。我想用速度快的东西。目前,用电影编写一个5分钟的视频文件需要花费10+分钟。
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
import moviepy.editor as mpy
origVideo = 'video.mp4'
video = mpy.VideoFileClip(origVideo)
#Crop 'video' here and output 'cropped-video.mp4'
video.write_videofile('video-cropped.mp4')
目前只得到一个没有音频的黑色屏幕。这段视频不会播放,但它有一个时间代码。
编辑:这里的解决方案: https://github.com/JerlinJR/Crop-a-Video/blob/main/crop.py
发布于 2022-11-27 00:45:20
您可以使用moviepy.video.fx.all.crop
。文档是这里。例如,
import moviepy.editor as mpy
from moviepy.video.fx.all import crop
clip = mpy.VideoFileClip("path/to/video.mp4")
(w, h) = clip.size
crop_width = h * 9/16
# x1,y1 is the top left corner, and x2, y2 is the lower right corner of the cropped area.
x1, x2 = (w - crop_width)//2, (w+crop_width)//2
y1, y2 = 0, h
cropped_clip = crop(clip, x1=x1, y1=y1, x2=x2, y2=y2)
# or you can specify center point and cropped width/height
# cropped_clip = crop(clip, width=crop_width, height=h, x_center=w/2, y_center=h/2)
cropped_clip.write_videofile('path/to/cropped/video.mp4')
代码没有经过测试。如果还有其他问题,请告诉我。
https://stackoverflow.com/questions/74586467
复制相似问题