Video System Frame Glitching

Hi devs,

Im currently just trying out a new system for a project of mine that involves videos that I can show to the player now the way im currently doing this is by preloading 30 of the first frames then waiting a bit (i found this worked when i was doing it with less frames) before then showing them in order. Now the issue im currently facing is that between loading each frame they dont transition smoothly between eachother and instead theres a gap where the frame is invisible,

local S_Content = game:GetService("ContentProvider")
local FPS = 4
local TBF = 1/FPS -- Time Between Frames (TBF)

local callback = function(assetId, assetFetchStatus)
    print("PreloadAsync() resolved asset ID:", assetId)
    print("PreloadAsync() final AssetFetchStatus:", assetFetchStatus)
end

local function LoadFirstFrames()
    local FirstFrames = {}
    for i = 1, 15 do
        print(Frames[i])
        table.insert(FirstFrames, Frames[i])
    end
    S_Content:PreloadAsync(FirstFrames,callback)
end
LoadFirstFrames()
wait(5)

local function LoadRestofFrames()
    local RestofFrames = {}
    for i = 30, #Frames do
        print(Frames[i])
        table.insert(RestofFrames, Frames[i])
    end
    S_Content:PreloadAsync(RestofFrames,callback)
end

local loadImagesWhilst = coroutine.create(LoadRestofFrames)

for i,v in Frames do
    script.Parent.Frame1.Image = v
    wait(1)
end

You don’t seem to be running this coroutine? Make sure to add coroutine.resume(loadImagesWhilst) below this line too.

Have you tried printing out the FirstFrames and the RestofFrames table when attempting to debug? In my own experience, table.insert sometimes skips over a few items if it was being called repeatedly over a short time period.

Yeah i just realised that just now lol it but hasnt made much of a differance other than the first 15 frames now load smoothly but when i get to the rest of them which a being loaded through the coroutine i am still getting the same issue, and it does seem like all of the values in the table are being loaded correctly.

I feel like image flickering might aswell be a bug. When i look at old videos of innovation inc having a spinning logo using decals it works perfectly fine. But when i go in game and check it out myself it’s flickering!

Look at denis’ video at 4:15 for example.

Yeah but the thing is when i do it with with loading like the first 10 frames it works quite nicely however when i try then load the rest it goes glitchy…

Something I have now just found to work is by creating all the frames in the video and then setting the ZIndex to the amount of frames - i in the first loop as shown below:

local function LoadFrames()
    local FirstFrames = {}
    for i, v in Frames do
        table.insert(FirstFrames, Frames[i])
        wait()
        if i % 10 == 0 then
            print(i)
            S_Content:PreloadAsync(FirstFrames,callback)
            print(FirstFrames)
            table.clear(FirstFrames)
            print("Table Cleared")
            wait()
        end
    end
    print(FirstFrames)
    S_Content:PreloadAsync(FirstFrames,callback)
    
    for i,v in pairs(Frames) do
        local c = script.Frame:Clone()
        c.Parent = script.Parent
        c.Image = v
        c.Name = i
        c.ZIndex = #Frames + 1 - i
    end
    
end
LoadFrames()

Now then when i want to display the video all i need to do is simply destroy the first image then the second one will show in its place. And i could then optimize this by it loading the first say 15 frames before it playes then it loads the rest in a coroutine like i had before.

However this is not the most practical or ideal so if anyone else has any suggestions that’d be appriciated.