123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import openshot
- def video_writer_init(path):
- w = openshot.FFmpegWriter(path)
- w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
- w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
- openshot.Fraction(1, 1), False, False, 3000000)
- return w
- def video_photo_clip(video=None,layer=None, position=None, end=None
- ,scale_x=1,scale_y=1,location_x=0,location_y=0,ck=None,audio=True):
- clip = openshot.Clip(vid)
- clip.Layer(layer)
- clip.Position(position)
- clip.End(end)
- clip.scale_x=openshot.Keyframe(scale_x)
- clip.scale_y=openshot.Keyframe(scale_y)
- clip.location_x=openshot.Keyframe(location_x)
- clip.location_y=openshot.Keyframe(location_y)
-
- if ck!=None:
- clip.AddEffect(ck)
- if audio==True:
- clip.has_audio=openshot.Keyframe(1)
- else:
- clip.has_audio=openshot.Keyframe(0)
- return clip
- t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
- t.Open()
- anchor = openshot.FFmpegReader("pexels-ekaterina-bolovtsova-6689233.mp4")
- anchor.Open()
- anchor_clip = video_photo_clip(vid=anchor,layer=5,scale_x=0.65,scale_y=0.65,
- location_x=0.35,location_y=0.25,position=1, end=5,audio=True)
- t.AddClip(anchor_clip)
- anchor.Close()
- w = video_writer_init("test.mp4")
- w.Open()
- frames = int(t.info.fps)*int(7)
- for n in range(frames):
- f=t.GetFrame(n)
- w.WriteFrame(f)
- t.Close()
- w.Close()
|