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 ¶
- type Player
- func (v *Player) CreateRenderer() fyne.WidgetRenderer
- func (v *Player) DoubleTapped(ev *fyne.PointEvent)
- func (v *Player) EnableAutoHide(b bool)
- func (v *Player) MouseIn(pos *desktop.MouseEvent)
- func (v *Player) MouseMoved(pos *desktop.MouseEvent)
- func (v *Player) MouseOut()
- func (v *Player) SetAutoHideTimer(d time.Duration)
- func (v *Player) Tapped(ev *fyne.PointEvent)
- type VideoControls
- type Viewer
- func (v *Viewer) Clear() error
- func (v *Viewer) CreateRenderer() fyne.WidgetRenderer
- func (v *Viewer) CurrentPosition() (time.Duration, error)
- func (v *Viewer) Duration() (time.Duration, error)
- func (v *Viewer) ExtendBaseWidget(w fyne.Widget)
- func (v *Viewer) Frame() *canvas.Image
- func (v *Viewer) GetBrightness() float64
- func (v *Viewer) GetContrast() float64
- func (v *Viewer) GetHue() float64
- func (v *Viewer) GetSaturation() float64
- func (v *Viewer) GetVideoBalance() (float64, float64, float64, float64)
- func (v *Viewer) IsMuted() bool
- func (v *Viewer) IsPlaying() bool
- func (v *Viewer) Mute()
- func (v *Viewer) OnStartPlaying(f func())
- func (v *Viewer) Open(u fyne.URI) error
- func (v *Viewer) Pause() error
- func (v *Viewer) Pipeline() *gst.Pipeline
- func (v *Viewer) Play() error
- func (v *Viewer) Seek(pos time.Duration) error
- func (v *Viewer) SetBrightness(brightness float64)
- func (v *Viewer) SetContrast(contrast float64)
- func (v *Viewer) SetFillMode(mode canvas.ImageFill)
- func (v *Viewer) SetFullScreen(state bool)
- func (v *Viewer) SetHue(hue float64)
- func (v *Viewer) SetMaxRate(rate int) error
- func (v *Viewer) SetMinSize(size fyne.Size)
- func (v *Viewer) SetOnEOS(f func())
- func (v *Viewer) SetOnNewFrame(f func(time.Duration))
- func (v *Viewer) SetOnPaused(f func())
- func (v *Viewer) SetOnPreRoll(f func())
- func (v *Viewer) SetOnTitle(f func(string))
- func (v *Viewer) SetPipeline(p *gst.Pipeline) error
- func (v *Viewer) SetPipelineFromString(pipeline string) error
- func (v *Viewer) SetQuality(q int) error
- func (v *Viewer) SetSaturation(saturation float64)
- func (v *Viewer) SetScaleMode(mode canvas.ImageScale)
- func (v *Viewer) SetState(state gst.State) error
- func (v *Viewer) SetVolume(volume float64)
- func (v *Viewer) Stop() error
- func (v *Viewer) ToggleMute()
- func (v *Viewer) Unmute()
- func (v *Viewer) VideoSize() fyne.Size
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 ¶
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 ¶
SetAutoHideTimer sets the time to wait before hiding the controls.
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) 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 (*Viewer) CreateRenderer ¶
func (v *Viewer) CreateRenderer() fyne.WidgetRenderer
CreateRenderer creates a renderer for the video widget.
Implements: fyne.Widget
func (*Viewer) CurrentPosition ¶
CurrentPosition returns the current position of the stream in time.
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) GetBrightness ¶
GetBrightness returns the brightness of the video.
func (*Viewer) GetContrast ¶
GetContrast returns the contrast of the video.
func (*Viewer) GetSaturation ¶
GetSaturation returns the saturation of the video.
func (*Viewer) GetVideoBalance ¶
GetVideoBalance returns the contrast, brightness, hue and saturation of the video.
func (*Viewer) OnStartPlaying ¶
func (v *Viewer) OnStartPlaying(f func())
func (*Viewer) Seek ¶
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 ¶
SetBrightness sets the brightness of the video.
func (*Viewer) SetContrast ¶
SetContrast sets the contrast of the video.
func (*Viewer) SetFillMode ¶
SetFillMode sets the fill mode of the image.
func (*Viewer) SetFullScreen ¶
SetFullScreen sets the video widget to fullscreen mode or not.
func (*Viewer) SetMaxRate ¶
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 ¶
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 (*Viewer) SetPipeline ¶
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 ¶
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 ¶
SetQuality of the jpeg encoder. If que quality is not between 0 and 100, nothing is done.
func (*Viewer) SetSaturation ¶
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.