~eliasnaur/gio

2 2

Video

David Brophy
Details
Message ID
<CAE2o+9Gys1aHkRF0rQBURzPPqLD3TYhydtX-gVtr3XMOOK0xPQ@mail.gmail.com>
DKIM signature
missing
Download raw message
I'd like to display a video stream from an IP camera on the screen
(MJPEG or H.264). Can gio do this?


-- 
David Brophy
+44 7971 597702
Details
Message ID
<CAFcc3FSCM=RUtqjH45RVGTvesSNGkPTzJyxBWPiLLuL8+v9nSg@mail.gmail.com>
In-Reply-To
<CAE2o+9Gys1aHkRF0rQBURzPPqLD3TYhydtX-gVtr3XMOOK0xPQ@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
Hi David,

> I'd like to display a video stream from an IP camera on the screen
> (MJPEG or H.264). Can gio do this?

Yes, Gio is able to render frames of video from MJPEG. Essentially,
you just decode each frame on the CPU as an image.Image, then create
an op.ImageOp of it and render those with widget.Image.

I actually used to do this in my trideo project, though I switched to
rendering triangles instead of image.Image.
https://git.sr.ht/~whereswaldon/trideo

I've stripped down trideo to just play video from a webcam as an
example here: https://play.golang.org/p/zv3VUJEp4uQ

It gets about 15 FPS for me, which is good enough for many purposes. I
haven't tried to optimize it, so I don't know where the bottleneck is.

NOTE: this only works on Linux because I couldn't find a
cross-platform webcam API. However, it should be pretty simple to
insert a webcam library that supports your OS of choice into that
example code.

This approach works on a laptop processor for reasonably high-quality
video, but is definitely inefficient. In the future, Gio may grow the
ability to decode the media stream in hardware, which would greatly
improve the speed and efficiency of doing things like this.

Cheers,
Chris
Details
Message ID
<CBRJQEFWMXJD.14KX881MJPHFH@themachine>
In-Reply-To
<CAFcc3FSCM=RUtqjH45RVGTvesSNGkPTzJyxBWPiLLuL8+v9nSg@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Mon May 31, 2021 at 11:12, Chris Waldon wrote:
> Hi David,
>
> > I'd like to display a video stream from an IP camera on the screen
> > (MJPEG or H.264). Can gio do this?
>
> Yes, Gio is able to render frames of video from MJPEG. Essentially,
> you just decode each frame on the CPU as an image.Image, then create
> an op.ImageOp of it and render those with widget.Image.
>
> I actually used to do this in my trideo project, though I switched to
> rendering triangles instead of image.Image.
> https://git.sr.ht/~whereswaldon/trideo
>
> I've stripped down trideo to just play video from a webcam as an
> example here: https://play.golang.org/p/zv3VUJEp4uQ
>
> It gets about 15 FPS for me, which is good enough for many purposes. I
> haven't tried to optimize it, so I don't know where the bottleneck is.
>
> NOTE: this only works on Linux because I couldn't find a
> cross-platform webcam API. However, it should be pretty simple to
> insert a webcam library that supports your OS of choice into that
> example code.
>
> This approach works on a laptop processor for reasonably high-quality
> video, but is definitely inefficient. In the future, Gio may grow the
> ability to decode the media stream in hardware, which would greatly
> improve the speed and efficiency of doing things like this.
>

A potentially faster (but also more tedious) alternative is to use
OpenGL directly to (decode and) render the video textures. See the
gioui.org/example/opengl sample.

Elias
Reply to thread Export thread (mbox)