garrysmod-requests icon indicating copy to clipboard operation
garrysmod-requests copied to clipboard

IVideoWriter: Function to pause/cut video

Open 0RadicalLarry0 opened this issue 1 year ago • 3 comments

Details

Currently you cannot pause the video recording for jump cuts. If you stop adding frames to the video, it will freeze and record audio only. A function to manage the video play state should be added.

Something like: IVideoWriter:SetRecordPause( bool )

0RadicalLarry0 avatar May 06 '24 03:05 0RadicalLarry0

You achieve this by not calling https://wiki.facepunch.com/gmod/IVideoWriter:AddFrame every frame?

robotboy655 avatar May 06 '24 08:05 robotboy655

EDIT: I may have misunderstood your reply, updated code to work as an example of the problem.

Not while sound is recorded. Without sound, it does cut the video. With sound, it freezes on the last frame until you start adding frames. I reckon this is intended behavior so if you're doing what I'm doing and adding frames to match 30 fps without locking the clients fps to 30 it doesn't cut the audio.

Code to reproduce:

local config = {
	container = "webm",
	video = "vp8",
	audio = "vorbis",
	quality = 50,
	bitrate = 500,
	fps = 30,
	lockfps = false,
	name = "Test",
	width = 480,
	height = 480
}

local vid
local toggle = false
local pause_recording = false

local function StopRecording()
	print("STOP RECORDING")
	toggle = false
	
	hook.Remove("PostRender", "Record")
	vid:Finish()
end

local last_time = 0
local start_time = 0
local function Record()
	local time = SysTime()

	if time >= start_time then
		StopRecording()
	return end

	if pause_recording then return end

	if time >= last_time then
		last_time = time + 0.0333333333333333 -- records at 30fps

		vid:AddFrame(FrameTime(), false)
	end
end

local function StartRecording()
	print("START RECORDING")
	toggle = true
	pause_recording = false

	vid = video.Record(config)
	vid:SetRecordSound(true)
	
	timer.Simple(0.1, function()
		start_time = SysTime() + 60
		hook.Add("PostRender", "Record", Record)
	end)
end

concommand.Add("record_toggle", function()
	if !toggle then
		StartRecording()
	else
		StopRecording()
	end
end)

concommand.Add("record_toggle_pause", function() -- Bind a key to this and press it in-game
	if !pause_recording then
		print("PAUSED")
		pause_recording = true
	else
		print("UNPAUSED")
		pause_recording = false
	end
end)

0RadicalLarry0 avatar May 06 '24 17:05 0RadicalLarry0

Here is an example, the cut happens between 5 seconds and 10 seconds Test.webm

0RadicalLarry0 avatar May 06 '24 17:05 0RadicalLarry0