Video stutters with ui.loop()

We have a simple test project with started from the touch experiments package, that is needed to use touch events.

The problem is that videos lag/stutters at around 30/45 fps and is quite noticeable.

We have simplified the project with error with a barebone node.lua file.
This is it

local ui = require("ui")

gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)

local function render()

    local video = resource.load_video {
        file = 'ast-home.mp4',
        loop = true
        }

    while ui.loop() do

        video:draw(0, 0, WIDTH, HEIGHT)

    end
end

function node.render()
    gl.clear(0, 0, 0, 1)
    ui.run(render)
end

and this is ui.lua

-- coroutine based continuous UI

local _run
function ui.run(entry)
    if not _run then
        _run = coroutine.wrap(entry)
    end
    _run()
end

function ui.loop()
    coroutine.yield()
    return true
end
 

As you can see it’s pretty linear but it it somehow slow, and I don’t know what to touch to improve it. We have started from this lua file since we need touch in put and this was the template.

Thanks

We manage to have a full 60fps with this lua file

local ui = require("ui")

gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)

local raw = sys.get_ext "raw_video"
local video = raw.load_video {
    file = 'ast-home.mp4',
    looped = true,
} 

function node.render()
    gl.clear(0, 0, 0, 1)
    video:layer(1):target(0, 0, WIDTH, HEIGHT):start()
 
end

even without using ui.loop() the normal video play stuttered (i.e. the non raw).
Reading this post reminded me why.

That’s the correct way, although the easier way today is:

local video = resource.load_video {
    file = 'ast-home.mp4',
    looped = true,
    raw = true -- no sys.get_ext needed
} 

The difference between raw and non-raw is that the former directly renders to the screen, while the latter uses OpenGL between decoding and output. Unlike with OpenGL, raw videos are a bit awkward to use as they work outside OpenGL and you can’t (for example) have other content both behind and in-front of a video. And you can only rotate in 90 degree increments.

Hi, thanks.

So if we have contents only IN FRONT of the video, it’s ok? We are doing some experiments right now and it works, but do you foresee any problems?

Yep. That works perfect. Have a look at this older blog post: https://info-beamer.com/blog/raspberry-pi-hardware-video-scaler

The normal info-beamer content is rendered into a single layer. If you use resource.load_video without raw, you too render into that same layer. raw videos on the other hand are rendered into their own layer. They can then only be rendered either above or below all other info-beamer content. Also their coordinates are always given in display pixels.

1 Like