-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
77 lines (57 loc) · 1.85 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import openshot
import os
setting = openshot.Settings.Instance()
setting.OMP_THREADS = 24
setting.FF_THREADS = 16
setting.VIDEO_CACHE_PERCENT_AHEAD = 0
setting.VIDEO_CACHE_MIN_PREROLL_FRAMES = 0
setting.VIDEO_CACHE_MAX_PREROLL_FRAMES = 0
setting.VIDEO_CACHE_MAX_FRAMES = 0
setting.ENABLE_PLAYBACK_CACHING = False
setting.HIGH_QUALITY_SCALING = True
# setting.DEBUG_TO_STDERR = False
width = 1920
height = 1080
fps = openshot.Fraction(30, 1)
audio_bitrate = 44100
audio_channels = 2
audio_channel_layout = openshot.LAYOUT_STEREO
pixel_ratio = openshot.Fraction(1, 1)
location = os.path.dirname(__file__)
timeline = openshot.Timeline(width, height, fps, audio_bitrate, audio_channels, audio_channel_layout)
r = openshot.FFmpegReader(os.path.join(location, "video.mp4"))
r.Open()
blur_effect = openshot.Blur()
blur_effect.iterations.AddPoint(1, 5)
# blur_effect.iterations.AddPoint(30, 0)
blur_effect.horizontal_radius.AddPoint(1, 5)
blur_effect.horizontal_radius.AddPoint(1, 5)
blur_effect.horizontal_radius.AddPoint(60, 0)
blur_effect.horizontal_radius.AddPoint(60, 0)
blur_effect.sigma.AddPoint(1, 10)
blur_effect.Position(0)
blur_effect.Layer(2)
c = openshot.Clip(r)
c.AddEffect(blur_effect)
c.Position(0)
c.gravity = openshot.GRAVITY_CENTER
c.Layer(1)
c.Open()
timeline.AddClip(c)
timeline.Open()
w = openshot.FFmpegWriter(os.path.join(location, "output.mp4"))
# w.info.pixel_format = 0
w.SetAudioOptions(False, "libvorbis", 44100, 2, openshot.LAYOUT_STEREO, 128000)
w.SetVideoOptions(True, "libx265", fps, width, height, pixel_ratio, False, False, 3000000)
w.PrepareStreams()
w.SetOption(openshot.VIDEO_STREAM, "crf", "28")
w.SetOption(openshot.VIDEO_STREAM, "preset", "veryslow")
# w.SetOption(openshot.VIDEO_STREAM, "args", "-pix_fmt yuv420p")
w.WriteHeader()
w.Open()
w.WriteFrame(c, 1, r.info.video_length)
w.WriteTrailer()
w.Close()
timeline.Close()
c.Close()
r.Close()