video

package
v0.0.0-...-8800be3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2023 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package video proposes widgets to play video files using GStreamer. There are

two widgets: Player and Viewer. The Player widget is a complete widget that can be used as is. The Viewer widget is a lower level widget that can be used to create a custom video player or a simple video viewer with no graphical controls.

If you need a simple video viwer, use the Viewer widget.

video := video.NewViewer()
video.Open(uri)

If you need a video player with controls, use the Player widget.

video := video.NewPlayer()
video.Open(uri)
video.Play()

Both widgets can be fullscreened and have Play(), Pause() and Seek(duration) methods. The difference is that the Player has controls (auto hidden) and react on tap and double tap.

You can create your own Gstreamer pipeline and use the Viewer widget to display the video frames. The mandatory element to create is an "appsink" that is name with "AppSinkElementName" (constant). Others names can be provided to let the player adapt the framerate, the quality of the image compression, etc. The encoders can be "jpegenc" or "pngenc" and it's mandatory to have one of them in the pipeline before the appsink element.

To ease the creation of the pipeline, the CustomFromString method accepts a template string with comments. The ElementMap variable is used as data for the template. So you can use the ElementName constants in the template.

For example:

pipeline := `
# the video source is sent to decoder
videotestsrc name={{ .InputElementName }} !
videoconvert !
videorate name={{ .VideoRateElementName }} !

# add an image encoder here
jpegenc name={{ .ImageEncoderElementName }} !

# the appsink element is mandatory
appsink name={{ .AppSinkElementName }} sync=true
`
video := video.NewViewer()
video.CustomFromString(pipeline)
video.Play()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Player

type Player struct {
	*Viewer
	// contains filtered or unexported fields
}

Player is a Viewer widget with controls and interaction. This widget proposes auto-hidden controls, cursor to navigate in the video and, and many others features.

func NewPlayer

func NewPlayer() *Player

NewPlayer returns a new video widget with controls and interaction.

func (*Player) CreateRenderer

func (v *Player) CreateRenderer() fyne.WidgetRenderer

CreateRenderer creates a renderer for the video widget.

Implements: fyne.Widget

func (*Player) DoubleTapped

func (v *Player) DoubleTapped(ev *fyne.PointEvent)

DoubleTapped toggles the video widget between playing and paused.

Implements: fyne.DoubleTappable

func (*Player) EnableAutoHide

func (v *Player) EnableAutoHide(b bool)

EnableAutoHide sets the autoHide feature of the video widget.

func (*Player) MouseIn

func (v *Player) MouseIn(pos *desktop.MouseEvent)

MouseIn shows the controls of the video widget.

Implements: desktop.Hoverable

func (*Player) MouseMoved

func (v *Player) MouseMoved(pos *desktop.MouseEvent)

MouseMoved shows the controls of the video widget.

Implements: desktop.Hoverable

func (*Player) MouseOut

func (v *Player) MouseOut()

MouseOut hides the controls of the video widget.

Implements: desktop.Hoverable

func (*Player) SetAutoHideTimer

func (v *Player) SetAutoHideTimer(d time.Duration)

SetAutoHideTimer sets the time to wait before hiding the controls.

func (*Player) Tapped

func (v *Player) Tapped(ev *fyne.PointEvent)

Tapped hides the controls of the video widget.

Implements: fyne.Tappable

type VideoControls

type VideoControls struct {
	widget.BaseWidget
	// contains filtered or unexported fields
}

VideoControls is the widget that displays the video controls (play, pause, fullscreen, etc.).

func NewVideoControls

func NewVideoControls(viewer *Viewer) *VideoControls

NewVideoControls creates a new video controls widget. It is used to control the video viewer. It is use in the Player widget.

func (*VideoControls) CreateRenderer

func (vc *VideoControls) CreateRenderer() fyne.WidgetRenderer

CreateRenderer returns a new videoControlsRenderer.

Implements fyne.Widget.

func (*VideoControls) Refresh

func (vc *VideoControls) Refresh()

Refresh the video controls.

func (*VideoControls) SetCursorAt

func (vc *VideoControls) SetCursorAt(pos time.Duration)

SetCursorAt sets the cursor at the given position.

func (*VideoControls) SetDuration

func (vc *VideoControls) SetDuration(d time.Duration)

SetDuration sets the slider max value to the given duration.

type Viewer

type Viewer struct {
	widget.BaseWidget
	// contains filtered or unexported fields
}

Viewer widget is a simple video player with no controls to display. This is a base widget to only read a video or that can be extended to create a video player with controls.

func CreateBaseVideoViewer

func CreateBaseVideoViewer() *Viewer

CreateBaseVideoViewer returns a new video widget without the base widget. It is useful to create various video widgets with the same base. It's MANDATORY to use it to create viewers.

func NewViewer

func NewViewer() *Viewer

NewViewer creates a new video viewer widget.

func (*Viewer) Clear

func (v *Viewer) Clear() error

Clear the pipeline. Use it with caution, it may cause some issues.

func (*Viewer) CreateRenderer

func (v *Viewer) CreateRenderer() fyne.WidgetRenderer

CreateRenderer creates a renderer for the video widget.

Implements: fyne.Widget

func (*Viewer) CurrentPosition

func (v *Viewer) CurrentPosition() (time.Duration, error)

CurrentPosition returns the current position of the stream in time.

func (*Viewer) Duration

func (v *Viewer) Duration() (time.Duration, error)

Duration returns the duration of the stream if possible.

func (*Viewer) ExtendBaseWidget

func (v *Viewer) ExtendBaseWidget(w fyne.Widget)

ExtendBaseWidget overrides the ExtendBaseWidget method of the BaseWidget. It is used to set the currentWindowFinder function and the object that is really displayed in the window (to ensure that fullscreen will use the right object).

func (*Viewer) Frame

func (v *Viewer) Frame() *canvas.Image

Frame returns the canvas.Image that is used to display the video.

func (*Viewer) GetBrightness

func (v *Viewer) GetBrightness() float64

GetBrightness returns the brightness of the video.

func (*Viewer) GetContrast

func (v *Viewer) GetContrast() float64

GetContrast returns the contrast of the video.

func (*Viewer) GetHue

func (v *Viewer) GetHue() float64

GetHue returns the hue of the video.

func (*Viewer) GetSaturation

func (v *Viewer) GetSaturation() float64

GetSaturation returns the saturation of the video.

func (*Viewer) GetVideoBalance

func (v *Viewer) GetVideoBalance() (float64, float64, float64, float64)

GetVideoBalance returns the contrast, brightness, hue and saturation of the video.

func (*Viewer) IsMuted

func (v *Viewer) IsMuted() bool

IsMuted returns true if the audio is muted.

func (*Viewer) IsPlaying

func (v *Viewer) IsPlaying() bool

IsPlaying returns true if the pipeline is in the playing state.

func (*Viewer) Mute

func (v *Viewer) Mute()

Mute the audio.

func (*Viewer) OnStartPlaying

func (v *Viewer) OnStartPlaying(f func())

func (*Viewer) Open

func (v *Viewer) Open(u fyne.URI) error

Open opens the given location. It can be a file URI, an http or https URL.

func (*Viewer) Pause

func (v *Viewer) Pause() error

Pause the stream if the pipeline is not nil.

func (*Viewer) Pipeline

func (v *Viewer) Pipeline() *gst.Pipeline

Pipeline returns the gstreamer pipeline.

func (*Viewer) Play

func (v *Viewer) Play() error

Play the stream if the pipeline is not nil.

func (*Viewer) Seek

func (v *Viewer) Seek(pos time.Duration) error

Seek the position to "pos" Nanoseconds. Set the playing stream to this time position. If the element or the pipeline cannot be seekable, the operation is cancelled.

func (*Viewer) SetBrightness

func (v *Viewer) SetBrightness(brightness float64)

SetBrightness sets the brightness of the video.

func (*Viewer) SetContrast

func (v *Viewer) SetContrast(contrast float64)

SetContrast sets the contrast of the video.

func (*Viewer) SetFillMode

func (v *Viewer) SetFillMode(mode canvas.ImageFill)

SetFillMode sets the fill mode of the image.

func (*Viewer) SetFullScreen

func (v *Viewer) SetFullScreen(state bool)

SetFullScreen sets the video widget to fullscreen mode or not.

func (*Viewer) SetHue

func (v *Viewer) SetHue(hue float64)

SetHue sets the hue of the video.

func (*Viewer) SetMaxRate

func (v *Viewer) SetMaxRate(rate int) error

SetMaxRate sets the max-rate property of the videorate element. It is used to limit the framerate of the video. Note that if the rate value is too high, the Video element will fix it automatically.

func (*Viewer) SetMinSize

func (v *Viewer) SetMinSize(size fyne.Size)

SetMinSize sets the minimum size of the video widget.

func (*Viewer) SetOnEOS

func (v *Viewer) SetOnEOS(f func())

SetOnEOS set the function to call when EOS is reached in the pipeline. E.g. when the// video ends.

func (*Viewer) SetOnNewFrame

func (v *Viewer) SetOnNewFrame(f func(time.Duration))

SetOnNewFrame set the function that is called when a new frame is available and presented to the view. The position is set as time.Duration to the function.

func (*Viewer) SetOnPaused

func (v *Viewer) SetOnPaused(f func())

SetOnPaused set the function that is called when the pipeline is paused.

func (*Viewer) SetOnPreRoll

func (v *Viewer) SetOnPreRoll(f func())

SetOnPreRoll set the function that is called when the pipeline is prerolling. At this time, you must be able to get the video size and duration.

func (*Viewer) SetOnTitle

func (v *Viewer) SetOnTitle(f func(string))

func (*Viewer) SetPipeline

func (v *Viewer) SetPipeline(p *gst.Pipeline) error

SetPipeline creates a pipeline from a gst.Pipeline object. As for CustomFromString, it is mandatory to provide at least an "appsink" element named with AppSinkElementName.

You can also provide other elements that the viewer will manage. Use provided const names for the elements: InputElementName, DecodeElementName, VideoRateElementName, ImageEncoderElementName, AppSinkElementName.

func (*Viewer) SetPipelineFromString

func (v *Viewer) SetPipelineFromString(pipeline string) error

SetPipelineFromString creates a pipeline from a string. The string is a GStreamer pipeline description that is a template (text/template) with the ElementMap as data. So you can use the ElementName constants in the template.

It also upports comments starting with #.

It is mandatory to provide at least an "appsink" element named with AppSinkElementName.

You can also provide other elements that the viewer will manage. Use provided const names for the elements: InputElementName, DecodeElementName, VideoRateElementName, ImageEncoderElementName, AppSinkElementName.

For example, getting the webcam stream can be done with:

pipeline := `
    autovideosrc name={{ .InputElementName }} ! # the input, a video test
    videoconvert n-threads=4 ! # convert to something usable
    videorate name={{ .VideoRateElementName }} max-rate=30 ! # fix the framerate
    # encode to jpeg (or png), mandatory for appsink
    jpegenc name={{ .ImageEncoderElementName }} quality=80 !
    # the appsink (mandatory)
    appsink name={{ .AppSinkElementName }} drop=true max-lateness=33333 sync=true
    `
v.Custom(pipeline)

Note that the appsink element max-lateness property is set to 33333 nanoseconds, which is the equivalent of 30 fps. This argument is modified by the Video element if needed.

func (*Viewer) SetQuality

func (v *Viewer) SetQuality(q int) error

SetQuality of the jpeg encoder. If que quality is not between 0 and 100, nothing is done.

func (*Viewer) SetSaturation

func (v *Viewer) SetSaturation(saturation float64)

SetSaturation sets the saturation of the video.

func (*Viewer) SetScaleMode

func (v *Viewer) SetScaleMode(mode canvas.ImageScale)

SetScaleMode sets the scale mode of the image. It's not recommended to use other mode than canvas.ImageScaleFastest because it can be very slow.

func (*Viewer) SetState

func (v *Viewer) SetState(state gst.State) error

SetState sets the state of the pipeline to the given state.

func (*Viewer) SetVolume

func (v *Viewer) SetVolume(volume float64)

SetVolume sets the volume of the audio.

func (*Viewer) Stop

func (v *Viewer) Stop() error

Stop the stream if the pipeline is not nil.

func (*Viewer) ToggleMute

func (v *Viewer) ToggleMute()

ToggleMute mutes or unmutes the audio.

func (*Viewer) Unmute

func (v *Viewer) Unmute()

Unmute the audio.

func (*Viewer) VideoSize

func (v *Viewer) VideoSize() fyne.Size

VideoSize returns the size of the video (resolution in pixels).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL