|
@@ -1,5 +1,33 @@
|
|
|
import openshot
|
|
|
|
|
|
+
|
|
|
+def cKey(r,g,b,fuzz):
|
|
|
+ col=openshot.Color()
|
|
|
+ col.red=openshot.Keyframe(r)
|
|
|
+ col.green=openshot.Keyframe(g)
|
|
|
+ col.blue=openshot.Keyframe(b)
|
|
|
+ return openshot.ChromaKey(col, openshot.Keyframe(fuzz))
|
|
|
+
|
|
|
+
|
|
|
+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(video)
|
|
|
+ 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
|
|
|
+
|
|
|
def video_writer_init(path):
|
|
|
w = openshot.FFmpegWriter(path)
|
|
|
w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
|
|
@@ -8,21 +36,39 @@ def video_writer_init(path):
|
|
|
return w
|
|
|
|
|
|
|
|
|
-t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
|
|
|
-t.Open()
|
|
|
-text_title = openshot.QtImageReader("/app/tt.jpg")
|
|
|
-clip = openshot.Clip(text_title)
|
|
|
-t.AddClip(clip)
|
|
|
-
|
|
|
-w = video_writer_init("/app/test.mp4")
|
|
|
-w.Open()
|
|
|
-
|
|
|
-frames = t.info.fps.ToInt ()*3
|
|
|
-for n in range(frames):
|
|
|
- f=t.GetFrame(n)
|
|
|
- w.WriteFrame(f)
|
|
|
+def create_video(bg, title_bg,time):
|
|
|
+ t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
|
|
|
+ t.Open()
|
|
|
+
|
|
|
+ ck = cKey(0, 254, 0, 270)
|
|
|
+ ck_anchor = cKey(0, 255, 0, 320)
|
|
|
+
|
|
|
+ anchor_video = openshot.FFmpegReader(bg) # 影片
|
|
|
+ anchor_video.Open()
|
|
|
+ anchor_clip_video = video_photo_clip(video=anchor_video, layer=2, scale_x=0.59, scale_y=0.59, location_x=-0.04, location_y=-0.04, position=0, end=70, ck=None, audio=True)
|
|
|
+ t.AddClip(anchor_clip_video)
|
|
|
+ anchor_video.Close()
|
|
|
+
|
|
|
+ anchor_template = openshot.FFmpegReader(title_bg) # 樣板
|
|
|
+ anchor_template.Open()
|
|
|
+ anchor_clip_template = video_photo_clip(video=anchor_template, layer=1, scale_x=1, scale_y=1,
|
|
|
+ location_x=0, location_y=0, position=0, end=70, ck=None, audio=True)
|
|
|
+ t.AddClip(anchor_clip_template)
|
|
|
+ anchor_template.Close()
|
|
|
+
|
|
|
+ w = video_writer_init("/app/output/A-2-1.mp4")
|
|
|
+ w.Open()
|
|
|
+ # frames = int(t.info.fps)*int(time)
|
|
|
+ frames = t.info.fps.ToInt()*int(time)
|
|
|
+ print('結果一',frames)
|
|
|
+ for n in range(frames):
|
|
|
+ # tmp = n%(int(t.info.fps)*3) +int(t.info.fps)*int(2)
|
|
|
+ f=t.GetFrame(n)
|
|
|
+ w.WriteFrame(f)
|
|
|
|
|
|
-t.Close()
|
|
|
-w.Close()
|
|
|
+ t.Close()
|
|
|
+ w.Close()
|
|
|
|
|
|
|
|
|
+if __name__ == '__main__':
|
|
|
+ create_video("/app/input/movie_main/C0048.mp4","/app/input/bg/串場樣板1.mp4",61)
|