-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathffmpeg_video_to_quad.py
More file actions
53 lines (33 loc) · 1.42 KB
/
ffmpeg_video_to_quad.py
File metadata and controls
53 lines (33 loc) · 1.42 KB
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
import harfang as hg
hg.InputInit()
hg.WindowSystemInit()
res_x, res_y = 1280, 720
win = hg.RenderInit('Harfang - FFMpeg video stream plugin test', res_x, res_y, hg.RF_VSync)
hg.AddAssetsFolder('resources_compiled_dx')
pipeline = hg.CreateForwardPipeline()
res = hg.PipelineResources()
prg = hg.LoadProgramFromAssets('shaders/video_stream.vsb', 'shaders/video_stream.fsb')
vtx_layout = hg.VertexLayoutPosFloatNormUInt8TexCoord0UInt8()
cube_mdl = hg.CreateCubeModel(vtx_layout, 1, 1, 1)
cube_ref = res.AddModel('cube', cube_mdl)
texture = hg.CreateTexture(res_x, res_y, "Video texture", 0)
size = hg.iVec2(res_x, res_y)
fmt = hg.TF_RGB8
streamer = hg.MakeVideoStreamer('hg_ffmpeg.dll')
streamer.Startup()
##handle = streamer:Open(arg[1]);
handle = streamer.Open("resources_compiled_dx/videos/noise-512x512.mp4")
streamer.Play(handle)
angle = 0
while not hg.ReadKeyboard('default').Key(hg.K_Escape):
dt = hg.TickClock()
angle = angle + hg.time_to_sec_f(dt)
_, texture, size, fmt = hg.UpdateTexture(streamer, handle, texture, size, fmt)
tex_uniforms = [hg.MakeUniformSetTexture('u_source', texture, 0)]
view_id = 0
hg.SetViewPerspective(view_id, 0, 0, res_x, res_y, hg.TranslationMat4(hg.Vec3(0, 0, -1.8)))
hg.DrawModel(view_id, cube_mdl, prg, [], tex_uniforms, hg.TransformationMat4(hg.Vec3(0, 0, 0), hg.Vec3(angle * 0.1, angle * 0.05, angle * 0.2)))
hg.Frame()
hg.UpdateWindow(win)
hg.RenderShutdown()
hg.DestroyWindow(win)