streamer

package module
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: 1 Imported by: 0

README

Go Reference Go Report

Gstreamer with Fyne - Audio/Video Widget

Fyne-Streamer offers you a number of widgets that will enable you to display videos or manipulate sound with your applications developed with Fyne.

Fyne-Streamer uses Gstreamer, a cross-platform, high-performance and easy-to-use framework. It offers a large variety of filters, effects, decoders and encoders.

For the moment, Fyne-Streamer doesn't provide an Audio widget (but it will soon), although the video widget plays video sound correctly.

Installation

To install these widgets, you must first have the Gstreamer development files on your workstation. You need to install:

  • gstreamer-devel
  • gstreamer-app-devel

On Windows, you need to download Gstreamer and follow the configuration suggested by the Go-GST package in the Windows section.

Important On Windows, it seems that the only MingW version that successfuly builds go-gst is <= 11. Also, you must add the "bin" directory of "Gstreamer" (mingw version) in the "Path" environment to avoid copying the DLLs to your working directory.

See our Wike page: https://github.com/metal3d/fyne-streamer/wiki/Installation-on-Windows

For Mac users, you should be fine with "HomeBrew".

Android, iOs...

At this time, although Gstreamer is compatible with Android and iOS, we can't provide documentation on how to compile your applications with Fyne-Streamer - but as soon as we have the solution, it will be presented here.

If you're confortable with Android or iOS development, you're welcome to provide us a solution!

And finaly...

Installing and compiling Go-Gst could take a while. The first time you'll compile your application, it may take several minutes to finalize the process. This only happens once, to make Go caching the compilation results.

The next compilations will be very fast. See This issue

Demo

There is a "complete" demo in ./examples/blender-peertube directory. Get this repository and type:

go run -v ./examples/blender-peertube

There are others examples like a green screen remover, camera viewer with effects, and a simple "videotest". You are pleased to read the sources of these example to understand how the viewer and player work.

This application takes video list from Peertube channel of Blender, and proposes to stream the videos in a Player. You can also open a local file, or paste a video URL (and press Enter).

Move the mouse over the video to see the controls. Click to hide them, or wait 3 seconds.

Blender Peertube

Usage

For the moment, two widgets are available:

  • video.Viewer which is a "simple" video viewer (with sound). No control buttons are shown. You can control playback, position, pause, volume, etc. with the corresponding methods.
  • video.Player is a player with ready-to-use controls. This widget inherits from video.Viewer and can therefore be controlled using the same methods + those proposed for the control widget.

Import github.com/metal3d/fyne-streamer/video in your project, and use it!

The Open() method takes a fyne.URI. You can, at this time, provide file uri, or http(s) uri. Other locations are planned to be managed, but you can create your own pipeline as explained later.

For example, a simple video viewer:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"github.com/metal3d/fyne-streamer/video"
)

func main(){
	a := app.New()
	win := a.NewWindow("A viewer")

	viewer := video.NewViewer()
	viewer.Open(storage.NewFileURI("/path/to/a/video"))
	viewer.Play()

	win.SetContent(viewer)
	win.Resize(fyne.NewSize(800,600))
	win.ShowAndRun()
}

Or use a player:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"github.com/metal3d/fyne-streamer/video"
)

func main(){
	a := app.New()
	win := a.NewWindow("A viewer")

	player := video.NewPlayer()
	player.Open(storage.NewFileURI("/path/to/a/video"))
	player.Play()

	win.SetContent(player)
	win.Resize(fyne.NewSize(800,600))
	win.ShowAndRun()
}

You can provide your own pipeline. The pipeline string allows comments and names from the ElementMap constant. The mandatory element is the appsink named with .AppSinkElementName that must recieve png or jpeg encoded images.

For example:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"github.com/metal3d/fyne-streamer/video"
)

func main() {
	pipeline := `
	videotestsrc 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
	`

	a := app.New()
	w := a.NewWindow("Simple video test")

	videoWidget := video.NewViewer()
	videoWidget.SetPipelineFromString(pipeline)
	videoWidget.Play()

	w.Resize(fyne.NewSize(640, 480))
	w.SetContent(videoWidget)
	w.ShowAndRun()
}

Video Test

Caution

This widget is in early stage and can have several bugs. You are pleased to provide fixes as Pull Requests, or to fill issues.

Documentation

Index

Constants

View Source
const TimeFormat = "15:04:05"

TimeFormat is the format used to display the time in the video widget.

Variables

View Source
var (
	ErrNoPipeline            = fmt.Errorf("no pipeline")
	ErrPositionUnseekable    = fmt.Errorf("could not get position")
	ErrSeekUnsupported       = fmt.Errorf("seeking is not supported")
	ErrSeekFailed            = fmt.Errorf("seek failed")
	ErrFailedToGetFirstFrame = fmt.Errorf("failed to get the first frame")
	ErrNoDuration            = fmt.Errorf("couldn't get duration")
)
View Source
var ElementMap = map[string]ElementName{
	"InputElementName":        InputElementName,
	"DecodeElementName":       DecodeElementName,
	"VideoRateElementName":    VideoRateElementName,
	"ImageEncoderElementName": ImageEncoderElementName,
	"AppSinkElementName":      AppSinkElementName,
	"VolumeElementName":       VolumeElementName,
	"VideoBalanceElementName": VideoBalanceElementName,
}

ElementMap is a map of the element names used in the pipeline. This is used in templates to create the pipeline.

Functions

This section is empty.

Types

type ElementName

type ElementName = string

ElementName is the name of a GStreamer element. It's a string (alias).

const (
	// InputElementName is the name of the input element. Filesrc, souphttpsrc...
	InputElementName ElementName = "fyne-input"

	// DecodeElementName is the name of the decode element. Actually, a decodebin.
	DecodeElementName ElementName = "fyne-decode"

	// AppSinkElementName is the name of the appsink element. It's the mandatory element
	// in the pipeline.
	AppSinkElementName ElementName = "fyne-app"

	// VideoRateElementName is the name of the videorate element. It's used to limit
	// the framerate of the video. Place it just after the videoconvert element in the same
	// branch of the appsink element
	VideoRateElementName ElementName = "fyne-videorate"

	// ImageEncoderElementName is the name of the image encoder element. It's used to
	// encode the video frames to jpeg or png. It must be the last element in the pipeline before
	// the appsink element.
	// Generally, it's a "jpenenc". But it can be a "pngenc" if you want to encode the frames
	// with alpha channel.
	ImageEncoderElementName ElementName = "fyne-imageencoder"

	// VolumeElementName is the name of the volume element.
	// It's used to control the volume of the audio.
	VolumeElementName ElementName = "fyne-volume"

	// VideoBalanceElementName is the name of the videobalance element. It can be used to
	// controle the brightness, contrast, hue and saturation of the video.
	VideoBalanceElementName ElementName = "fyne-videobalance"
)

Directories

Path Synopsis
examples
internal
Package video proposes widgets to play video files using GStreamer.
Package video proposes widgets to play video files using GStreamer.

Jump to

Keyboard shortcuts

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