/
video.lua
60 lines (42 loc) · 1.72 KB
/
video.lua
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
local vid_width = CreateConVar( "vid_width", "640", { FCVAR_ARCHIVE }, "Specifies the width of the recorded video. The height will be adjusted automatically based on your aspect ratio" )
local vid_fps = CreateConVar( "vid_fps", "30", { FCVAR_ARCHIVE }, "The FPS of the recorded video" )
local vid_sound = CreateConVar( "vid_sound", "1", { FCVAR_ARCHIVE }, "Enable sound recording" )
local activeVideo
local videoStart
concommand.Add( "gm_video", function()
if ( activeVideo ) then
activeVideo:Finish()
activeVideo = nil
local time = SysTime() - videoStart
MsgN( string.format( "Finished recording. Length: %.1fs", time ) )
return
end
local dynamic_name = game.GetMap() .. " " .. util.DateStamp()
local width = math.Round( vid_width:GetFloat() )
local height = math.Round( ScrH() * ( width / ScrW() ) )
local fps = math.Round( vid_fps:GetFloat() )
local err
activeVideo, err = video.Record( {
name = dynamic_name,
container = "webm",
video = "vp8",
audio = "vorbis",
quality = 0,
bitrate = 1024 * 64,
width = width,
height = height,
fps = fps,
lockfps = true
} )
if ( !activeVideo ) then
MsgN( "Couldn't record video: ", err )
return
end
activeVideo:SetRecordSound( vid_sound:GetBool() )
videoStart = SysTime()
MsgN( string.format( "Recording %ix%i@%iFPS video to \"videos/%s.webm\"...", width, height, fps, dynamic_name ) )
end, nil, "Starts and stops the recording of a .webm (VP8/Vorbis) video. See vid_* convars for settings.", { FCVAR_DONTRECORD } )
hook.Add( "DrawOverlay", "CaptureFrames", function()
if ( !activeVideo ) then return end
activeVideo:AddFrame( FrameTime(), true )
end )