Reputation: 35
I want to create a python script what would show images for X seconds (the time until the audio goes), then go to the next image. I want the video to be X long. The lenght of the video will be always different cause of the audio. Anything that I can check the lenght of the unrendered video? My code:
from moviepy.editor import *
img = ['1.jpg']
clips = [ImageClip(m).set_duration(2)
for m in img]
clip = VideoFileClip("test.mp4")
print( clip.duration )
if clip.duration > 601:
print("clip is longer than 10 min")
else:
print("clip is shorter than 10 min")
vid_clips = concatenate_videoclips(clips, method="compose")
vid_clips.write_videofile("test.mp4", fps=60)
Upvotes: 1
Views: 713
Reputation: 471
Calling the command ffprobe would be faster than using moviepy:
import subprocess
def get_length(filename):
result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
"format=duration", "-of",
"default=noprint_wrappers=1:nokey=1", filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return float(result.stdout)
duration = get_length("test.mp4")
print(duration) # 30.024000
Upvotes: 0