Comments (5)
Hello, so you can calculate the aspect ratio like this
ratio = int(video_width) / int(video_height)
then you can use this value to calculate the width when keeping the height
video_width = video_width * ratio
and pass these values to your functions
from moviepy.
i made the adjust to my code, but this is the output now.
output.mp4
def build_image_clips(images, audio_file):
audio = AudioFileClip(audio_file)
audio_duration = audio.duration
image_duration = audio_duration / len(images)
video_clips = []
ratio = int(480) / int(854)
video_width = 480 * ratio
for image_url in images:
image_clip = ImageClip(image_url).set_fps(30).set_duration(image_duration)
image_clip = image_clip.set_position("center").resize(width=video_width)
image_clip = Zoom(
image_clip, mode="in", position="center", speed=5.0
)
video_clips.append(image_clip)
final_video = concatenate_videoclips(video_clips)
final_video = CompositeVideoClip([final_video], size=(480, 854))
final_video.write_videofile(
"output.mp4", fps=30, codec="libx264", audio_codec="aac"
)
from moviepy.
can you add the values to ComposeiteVideoClip
too, and try with that
from moviepy.
using this way, return a error.
cannot unpack non-iterable float object
def build_image_clips(images, audio_file):
audio = AudioFileClip(audio_file)
audio_duration = audio.duration
image_duration = audio_duration / len(images)
video_clips = []
ratio = int(480) / int(854)
video_width = 480 * ratio
for image_url in images:
image_clip = ImageClip(image_url).set_fps(30).set_duration(image_duration)
image_clip = image_clip.set_position("center").resize(width=video_width)
image_clip = Zoom(
image_clip, mode="in", position="center", speed=5.0
)
video_clips.append(image_clip)
final_video = concatenate_videoclips(video_clips)
final_video = CompositeVideoClip([final_video], size=video_width)
final_video.write_videofile(
"output.mp4", fps=30, codec="libx264", audio_codec="aac"
)
from moviepy.
seems your ratio
or video_width
is float instead of integer, can you check?
on resize
you can use resize(newsize=(video_width, video_height))
from moviepy.
Related Issues (20)
- commas in filterchain are always escaped by a backslash
- Operation on closed image
- AudioClip.iter_chunks(160) is chunking into [159, 160, 160, ..., 160]
- The position of subclip cutting is different from the parameters HOT 1
- Output resolution wrong. HOT 1
- Workflows need updating
- No longer encoding subtitles HOT 2
- AttributeError: 'NoneType' object has no attribute 'get_frame', reported by AudioFileClip.to_soundarray() HOT 1
- Test suite fails for most Windows, Linux tests HOT 2
- Test suite fails for macOS due to missing Conda install
- support latest decorator
- Unable to run moviepy on debian 10 HOT 8
- No sound HOT 1
- I cut 1800 seconds of audio, but the result is 1846 seconds. Why is this happening? How can I solve this problem?
- Resizable rounded rectangle
- Getting `AttributeError: 'NoneType' object has no attribute 'get_frame'` when trying to save a `CompositeVideoClip`
- Error When Generating a Long video and not getting the error when generating a shorter video
- AttributeError: 'NoneType' object has no attribute 'get_frame' when calling write_videofile HOT 1
- Vertical MOV video to MP4 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moviepy.