program1.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import openshot
  2. def video_writer_init(path):
  3. w = openshot.FFmpegWriter(path)
  4. w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
  5. w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  6. openshot.Fraction(1, 1), False, False, 3000000)
  7. return w
  8. def video_photo_clip(video=None,layer=None, position=None, end=None
  9. ,scale_x=1,scale_y=1,location_x=0,location_y=0,ck=None,audio=True):
  10. clip = openshot.Clip(vid)
  11. clip.Layer(layer)
  12. clip.Position(position)
  13. clip.End(end)
  14. clip.scale_x=openshot.Keyframe(scale_x)
  15. clip.scale_y=openshot.Keyframe(scale_y)
  16. clip.location_x=openshot.Keyframe(location_x)
  17. clip.location_y=openshot.Keyframe(location_y)
  18. if ck!=None:
  19. clip.AddEffect(ck)
  20. if audio==True:
  21. clip.has_audio=openshot.Keyframe(1)
  22. else:
  23. clip.has_audio=openshot.Keyframe(0)
  24. return clip
  25. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  26. t.Open()
  27. anchor = openshot.FFmpegReader("pexels-ekaterina-bolovtsova-6689233.mp4")
  28. anchor.Open()
  29. anchor_clip = video_photo_clip(vid=anchor,layer=5,scale_x=0.65,scale_y=0.65,
  30. location_x=0.35,location_y=0.25,position=1, end=5,audio=True)
  31. t.AddClip(anchor_clip)
  32. anchor.Close()
  33. w = video_writer_init("test.mp4")
  34. w.Open()
  35. frames = int(t.info.fps)*int(7)
  36. for n in range(frames):
  37. f=t.GetFrame(n)
  38. w.WriteFrame(f)
  39. t.Close()
  40. w.Close()