英文:
Why does Moviepy stretch my output after cutting and putting back together a video?
问题
以下是翻译好的部分:
I am using moviepy to cut up a video, put all the clips back together, and then export it. When I export it, the aspect ratio is changed, vertically stretching the image. I was using the '.mkv' container, which I thought might have been the issue, but it's happening with '.mp4' files too. Is there an issue with my export options, or is it the file itself?
My code:
我正在使用moviepy来剪辑视频,然后将所有剪辑片段合并并导出。在导出时,纵向拉伸了图像的宽高比。一开始我使用的是'.mkv'容器,我以为这可能是问题的原因,但对'.mp4'文件也发生了这种情况。是导出选项有问题,还是文件本身有问题?
My files:
我的文件:
The two files called "input.###" are, well, the input files, and the two files labeled "test-output.###" are the outputs my program creates.
两个名为"input.###"的文件是输入文件,而两个标记为"test-output.###"的文件是我的程序创建的输出文件。
英文:
I am using moviepy to cut up a video, put all the clips back together, and then export it. When I export it, the aspect ratio is changed, vertically stretching the image. I was using the '.mkv' container, which I thought might have been the issue, but it's happening with '.mp4' files too. Is there an issue with my export options, or is it the file itself?
My code:
from moviepy.editor import *
input = "input.mp4"
timestamps = [[60,70],[80,100]]
output_destination = "test-output"
video_end = 120
video = VideoFileClip(input)
# MAKE CUTS
# all this does is create a list of pieces to cut out of the video, and then puts them in a list
initial_time = 0
clips = []
for a in timestamps:
temp = video.subclip(initial_time, a[0])
initial_time = a[1]
clips.append(temp)
clips.append(video.subclip(initial_time, video_end))
# PUT TOGETHER
result = concatenate_videoclips(clips)
# EXPORT TO DESTINATION
result.write_videofile((output_destination+".mp4"),fps=29.97,codec='libx264',audio_bitrate='448k',preset='superfast',ffmpeg_params=['-crf','18'],write_logfile=True)
I wanted to briefly mention that I have tried resizing the video to 720x480 in the code, and I have also tried resizing it during import (as a parameter of VideoFileClip). I still get the streteched output. I have also tried just a pure re-encode to see if it's the subclips that cause the problem, but I still get the stretched output.
My files:
https://drive.google.com/drive/folders/1dvFP6xPSqFMeC1VexIUIIkVJ-RApTbV6?usp=sharing
The two files called "input.###" are, well, the input files, and the two files labeled "test-output.###" are the outputs my program creates.
答案1
得分: 2
我发现可以通过在 ffmpeg_params
中传递宽高比参数来强制使用 16:9 的宽高比:
ffmpeg_params=[..., '-aspect', '16:9']
然后,完整的 write_videofile()
调用如下所示:
result.write_videofile((output_destination+".mp4"), fps=29.97, codec='libx264', audio_bitrate='448k', preset='superfast', ffmpeg_params=['-crf','18', '-aspect', '16:9'], write_logfile=True)
另请参阅。
英文:
I found that it's possible to force a 16:9 aspect ratio by passing the aspect ratio inside ffmpeg_params
:
ffmpeg_params=[..., '-aspect', '16:9']
The full call to write_videofile()
then becomes this:
result.write_videofile((output_destination+".mp4"),fps=29.97,codec='libx264',audio_bitrate='448k',preset='superfast',ffmpeg_params=['-crf','18', '-aspect', '16:9'],write_logfile=True)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论