Moviepy为什么在剪切和重新组合视频后拉伸我的输出?

huangapple go评论79阅读模式
英文:

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)

See also.

huangapple
  • 本文由 发表于 2023年3月7日 07:48:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656843.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定