Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.54k stars 1.57k forks source link

keeping different FPS in a merged video #853

Open 0lm opened 6 years ago

0lm commented 6 years ago

Expected Behavior

merging videos with method=compose expection: fluently merged videos with back bars when they dont have same aspect ration/resolution (because highest hight and width are the leading ones when merging videos)

Actual Behavior

merging with black bars worked. but unfortunately there is a problem with the frame rate. all videos have different FPS. but the highest FPS is the leading one and that doesnt look good for many videos. are played too fast (skipped too many frame).

is there a possibility to keep the different FPS in combination with compose method (still having black bars) ? or is there an option to keep different FPS in one video at all?

Steps to Reproduce the Problem


clip01 = VideoFileClip("test.mp4")
clip02 = VideoFileClip("food.webm")
clip03 = VideoFileClip("sun.mp4")
final_clip = concatenate_videoclips([clip1,clip2,clip3], method="compose")
final_clip.write_videofile("result.mp4")```

### Specifications

  - Python Version: 2.7.15
  - Moviepy Version: not sure. i downloaded it via "clone or dowload" - "download zip" and it was updated 24 days ago.  but in releases the last release was 31st may. nontheless, im using the newest.
  - Platform Name: windows 
  - Platform Version: 7
ljluestc commented 7 months ago
from moviepy.editor import *

# Load the video clips
clip01 = VideoFileClip("test.mp4")
clip02 = VideoFileClip("food.webm")
clip03 = VideoFileClip("sun.mp4")

# Calculate the highest frame rate among the clips
max_fps = max(clip01.fps, clip02.fps, clip03.fps)

# Adjust the frame rate of each clip to match the highest frame rate
clip01 = clip01.speedx(factor=max_fps/clip01.fps)
clip02 = clip02.speedx(factor=max_fps/clip02.fps)
clip03 = clip03.speedx(factor=max_fps/clip03.fps)

# Concatenate the adjusted clips with black bars using the 'compose' method
final_clip = concatenate_videoclips([clip01, clip02, clip03], method="compose")

# Write the final video to a file
final_clip.write_videofile("result.mp4", fps=max_fps)