src

package
v0.0.0-...-aa47be3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const DummyKeyframeDuration = float64(4)
View Source
const ExtractVersion = 1
View Source
const InfoVersion = 1
View Source
const KeyframeVersion = 1
View Source
const ThumbsVersion = 1

Variables

View Source
var DeletedHead = Head{
	// contains filtered or unexported fields
}
View Source
var Qualities = []Quality{P240, P360, P480, P720, P1080, P1440, P4k, P8k}

Purposfully removing Original from this list (since it require special treatments anyways)

View Source
var Settings = SettingsT{
	Outpath:     GetEnvOr("GOCODER_CACHE_ROOT", "/cache"),
	Metadata:    GetEnvOr("GOCODER_METADATA_ROOT", "/metadata"),
	RoutePrefix: GetEnvOr("GOCODER_PREFIX", ""),
	SafePath:    GetEnvOr("GOCODER_SAFE_PATH", "/video"),
	HwAccel:     DetectHardwareAccel(),
}
View Source
var SubtitleExtensions = map[string]string{
	"subrip": "srt",
	"ass":    "ass",
	"vtt":    "vtt",
}

Functions

func Abs

func Abs(x int32) int32

func Filter

func Filter[E any](s []E, f func(E) bool) []E

func GetEnvOr

func GetEnvOr(env string, def string) string

func GetMimeCodec

func GetMimeCodec(stream *ffprobe.Stream) *string

convert mediainfo to RFC 6381, waiting for either of those tickets to be resolved:

https://sourceforge.net/p/mediainfo/feature-requests/499
https://trac.ffmpeg.org/ticket/6617

this code is addapted from https://github.com/jellyfin/jellyfin/blob/master/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs and https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD%3a/libavformat/hlsenc.c#l344

func Map

func Map[T, U any](ts []T, f func(T, int) U) []U

func MapStream

func MapStream[T any](streams []*ffprobe.Stream, kind ffprobe.StreamType, mapper func(*ffprobe.Stream, uint32) T) []T

func NewStream

func NewStream(file *FileStream, keyframes *Keyframe, handle StreamHandle, ret *Stream)

func NullIfUnd

func NullIfUnd(str string) *string

func OrNull

func OrNull(str string) *string

func ParseFloat

func ParseFloat(str string) float32

func ParseInt64

func ParseInt64(str string) int64

func ParseUint

func ParseUint(str string) uint32

Types

type Audio

type Audio struct {
	/// The index of this track on the media.
	Index uint32 `json:"index"`
	/// The title of the stream.
	Title *string `json:"title"`
	/// The language of this stream (as a IETF-BCP-47 language code)
	Language *string `json:"language"`
	/// The human readable codec name.
	Codec string `json:"codec"`
	/// The codec of this stream (defined as the RFC 6381).
	MimeCodec *string `json:"mimeCodec"`
	/// The average bitrate of the audio in bytes/s
	Bitrate uint32 `json:"bitrate"`
	/// Is this stream the default one of it's type?
	IsDefault bool `json:"isDefault"`

	/// Keyframes of this video
	Keyframes *Keyframe `json:"-"`

	//TODO: remove this in next major
	IsForced bool `json:"isForced"`
}

type AudioStream

type AudioStream struct {
	Stream
	// contains filtered or unexported fields
}

type CMap

type CMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewCMap

func NewCMap[K comparable, V any]() CMap[K, V]

func (*CMap[K, V]) Get

func (m *CMap[K, V]) Get(key K) (V, bool)

func (*CMap[K, V]) GetAndRemove

func (m *CMap[K, V]) GetAndRemove(key K) (V, bool)

func (*CMap[K, V]) GetOrCreate

func (m *CMap[K, V]) GetOrCreate(key K, create func() V) (V, bool)

func (*CMap[K, V]) GetOrSet

func (m *CMap[K, V]) GetOrSet(key K, val V) (V, bool)

func (*CMap[K, V]) Remove

func (m *CMap[K, V]) Remove(key K)

func (*CMap[K, V]) Set

func (m *CMap[K, V]) Set(key K, val V)

type Chapter

type Chapter struct {
	/// The start time of the chapter (in second from the start of the episode).
	StartTime float32 `json:"startTime"`
	/// The end time of the chapter (in second from the start of the episode).
	EndTime float32 `json:"endTime"`
	/// The name of this chapter. This should be a human-readable name that could be presented to the user.
	Name string `json:"name"`
	/// The type value is used to mark special chapters (openning/credits...)
	Type ChapterType
}

type ChapterType

type ChapterType string
const (
	Content ChapterType = "content"
	Recap   ChapterType = "recap"
	Intro   ChapterType = "intro"
	Credits ChapterType = "credits"
	Preview ChapterType = "preview"
)

type ClientInfo

type ClientInfo struct {
	// contains filtered or unexported fields
}

type FileStream

type FileStream struct {
	Out  string
	Info *MediaInfo
	// contains filtered or unexported fields
}

func (*FileStream) Destroy

func (fs *FileStream) Destroy()

func (*FileStream) GetAudioIndex

func (fs *FileStream) GetAudioIndex(audio uint32) (string, error)

func (*FileStream) GetAudioSegment

func (fs *FileStream) GetAudioSegment(audio uint32, segment int32) (string, error)

func (*FileStream) GetMaster

func (fs *FileStream) GetMaster() string

func (*FileStream) GetVideoIndex

func (fs *FileStream) GetVideoIndex(idx uint32, quality Quality) (string, error)

func (*FileStream) GetVideoSegment

func (fs *FileStream) GetVideoSegment(idx uint32, quality Quality, segment int32) (string, error)

func (*FileStream) Kill

func (fs *FileStream) Kill()

type Flags

type Flags int32
const (
	AudioF   Flags = 1 << 0
	VideoF   Flags = 1 << 1
	Transmux Flags = 1 << 3
)
type Head struct {
	// contains filtered or unexported fields
}

type HwAccelT

type HwAccelT struct {
	Name        string
	DecodeFlags []string
	EncodeFlags []string
	ScaleFilter string
}

func DetectHardwareAccel

func DetectHardwareAccel() HwAccelT

type Keyframe

type Keyframe struct {
	Keyframes []float64
	IsDone    bool
	// contains filtered or unexported fields
}

func (*Keyframe) AddListener

func (kf *Keyframe) AddListener(callback func(keyframes []float64))

func (*Keyframe) Get

func (kf *Keyframe) Get(idx int32) float64

func (*Keyframe) Length

func (kf *Keyframe) Length() (int32, bool)

func (*Keyframe) Scan

func (kf *Keyframe) Scan(src interface{}) error

func (*Keyframe) Slice

func (kf *Keyframe) Slice(start int32, end int32) []float64

type KeyframeInfo

type KeyframeInfo struct {
	// contains filtered or unexported fields
}

type KeyframeKey

type KeyframeKey struct {
	Sha     string
	IsVideo bool
	Index   uint32
}

type MediaInfo

type MediaInfo struct {
	// The sha1 of the video file.
	Sha string `json:"sha"`
	/// The internal path of the video file.
	Path string `json:"path"`
	/// The extension currently used to store this video file
	Extension string `json:"extension"`
	/// The whole mimetype (defined as the RFC 6381). ex: `video/mp4; codecs="avc1.640028, mp4a.40.2"`
	MimeCodec *string `json:"mimeCodec"`
	/// The file size of the video file.
	Size int64 `json:"size"`
	/// The length of the media in seconds.
	Duration float64 `json:"duration"`
	/// The container of the video file of this episode.
	Container *string `json:"container"`
	/// Version of the metadata. This can be used to invalidate older metadata from db if the extraction code has changed.
	Versions Versions `json:"versions"`

	// TODO: remove on next major
	Video Video `json:"video"`

	/// The list of videos if there are multiples.
	Videos []Video `json:"videos"`
	/// The list of audio tracks.
	Audios []Audio `json:"audios"`
	/// The list of subtitles tracks.
	Subtitles []Subtitle `json:"subtitles"`
	/// The list of fonts that can be used to display subtitles.
	Fonts []string `json:"fonts"`
	/// The list of chapters. See Chapter for more information.
	Chapters []Chapter `json:"chapters"`
	// contains filtered or unexported fields
}

func RetriveMediaInfo

func RetriveMediaInfo(path string, sha string) (*MediaInfo, error)

func (*MediaInfo) SearchExternalSubtitles

func (mi *MediaInfo) SearchExternalSubtitles() error

type MetadataService

type MetadataService struct {
	// contains filtered or unexported fields
}

func NewMetadataService

func NewMetadataService() (*MetadataService, error)

func (*MetadataService) ExtractSubs

func (s *MetadataService) ExtractSubs(info *MediaInfo) (interface{}, error)

func (*MetadataService) ExtractThumbs

func (s *MetadataService) ExtractThumbs(path string, sha string) (interface{}, error)

func (*MetadataService) GetAttachmentPath

func (s *MetadataService) GetAttachmentPath(sha string, is_sub bool, name string) (string, error)

func (*MetadataService) GetKeyframes

func (s *MetadataService) GetKeyframes(info *MediaInfo, isVideo bool, idx uint32) (*Keyframe, error)

func (*MetadataService) GetMetadata

func (s *MetadataService) GetMetadata(path string, sha string) (*MediaInfo, error)

func (*MetadataService) GetThumb

func (s *MetadataService) GetThumb(path string, sha string) (string, string, error)

type Quality

type Quality string
const (
	P240     Quality = "240p"
	P360     Quality = "360p"
	P480     Quality = "480p"
	P720     Quality = "720p"
	P1080    Quality = "1080p"
	P1440    Quality = "1440p"
	P4k      Quality = "4k"
	P8k      Quality = "8k"
	Original Quality = "original"
)

func QualityFromString

func QualityFromString(str string) (Quality, error)

func (Quality) AverageBitrate

func (v Quality) AverageBitrate() uint32

I'm not entierly sure about the values for bitrates. Double checking would be nice.

func (Quality) Height

func (q Quality) Height() uint32

func (Quality) MaxBitrate

func (v Quality) MaxBitrate() uint32

type Result

type Result[V any] struct {
	// contains filtered or unexported fields
}

type RunLock

type RunLock[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRunLock

func NewRunLock[K comparable, V any]() RunLock[K, V]

func (*RunLock[K, V]) Start

func (r *RunLock[K, V]) Start(key K) (func() (V, error), func(val V, err error) (V, error))

func (*RunLock[K, V]) WaitFor

func (r *RunLock[K, V]) WaitFor(key K) (V, error)

type Segment

type Segment struct {
	// contains filtered or unexported fields
}

type SettingsT

type SettingsT struct {
	Outpath     string
	Metadata    string
	RoutePrefix string
	SafePath    string
	HwAccel     HwAccelT
}

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func (*Stream) GetIndex

func (ts *Stream) GetIndex() (string, error)

func (*Stream) GetSegment

func (ts *Stream) GetSegment(segment int32) (string, error)

func (*Stream) Kill

func (ts *Stream) Kill()

func (*Stream) KillHead

func (ts *Stream) KillHead(encoder_id int)

Stream assume to be locked

type StreamHandle

type StreamHandle interface {
	// contains filtered or unexported methods
}

type Subtitle

type Subtitle struct {
	/// The index of this track on the media.
	Index *uint32 `json:"index"`
	/// The title of the stream.
	Title *string `json:"title"`
	/// The language of this stream (as a IETF-BCP-47 language code)
	Language *string `json:"language"`
	/// The codec of this stream.
	Codec string `json:"codec"`
	/// The extension for the codec.
	Extension *string `json:"extension"`
	/// Is this stream the default one of it's type?
	IsDefault bool `json:"isDefault"`
	/// Is this stream tagged as forced?
	IsForced bool `json:"isForced"`
	/// Is this an external subtitle (as in stored in a different file)
	IsExternal bool `json:"isExternal"`
	/// Where the subtitle is stored (null if stored inside the video)
	Path *string `json:"path"`
	/// The link to access this subtitle.
	Link *string `json:"link"`
}

type Task

type Task[V any] struct {
	// contains filtered or unexported fields
}

type Thumbnail

type Thumbnail struct {
	// contains filtered or unexported fields
}

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

func NewTracker

func NewTracker(t *Transcoder) *Tracker

func (*Tracker) DestroyStreamIfOld

func (t *Tracker) DestroyStreamIfOld(sha string)

func (*Tracker) KillAudioIfDead

func (t *Tracker) KillAudioIfDead(sha string, path string, audio uint32) bool

func (*Tracker) KillOrphanedHeads

func (t *Tracker) KillOrphanedHeads(sha string, video *VideoKey, audio *uint32)

func (*Tracker) KillStreamIfDead

func (t *Tracker) KillStreamIfDead(sha string, path string) bool

func (*Tracker) KillVideoIfDead

func (t *Tracker) KillVideoIfDead(sha string, path string, video VideoKey) bool

type Transcoder

type Transcoder struct {
	// contains filtered or unexported fields
}

func NewTranscoder

func NewTranscoder(metadata *MetadataService) (*Transcoder, error)

func (*Transcoder) GetAudioIndex

func (t *Transcoder) GetAudioIndex(
	path string,
	audio uint32,
	client string,
	sha string,
) (string, error)

func (*Transcoder) GetAudioSegment

func (t *Transcoder) GetAudioSegment(
	path string,
	audio uint32,
	segment int32,
	client string,
	sha string,
) (string, error)

func (*Transcoder) GetMaster

func (t *Transcoder) GetMaster(path string, client string, sha string) (string, error)

func (*Transcoder) GetVideoIndex

func (t *Transcoder) GetVideoIndex(
	path string,
	video uint32,
	quality Quality,
	client string,
	sha string,
) (string, error)

func (*Transcoder) GetVideoSegment

func (t *Transcoder) GetVideoSegment(
	path string,
	video uint32,
	quality Quality,
	segment int32,
	client string,
	sha string,
) (string, error)

func (*Transcoder) NewAudioStream

func (t *Transcoder) NewAudioStream(file *FileStream, idx uint32) (*AudioStream, error)

func (*Transcoder) NewVideoStream

func (t *Transcoder) NewVideoStream(file *FileStream, idx uint32, quality Quality) (*VideoStream, error)

type Versions

type Versions struct {
	Info      int32 `json:"info"`
	Extract   int32 `json:"extract"`
	Thumbs    int32 `json:"thumbs"`
	Keyframes int32 `json:"keyframes"`
}

type Video

type Video struct {
	/// The index of this track on the media.
	Index uint32 `json:"index"`
	/// The title of the stream.
	Title *string `json:"title"`
	/// The language of this stream (as a ISO-639-2 language code)
	Language *string `json:"language"`
	/// The human readable codec name.
	Codec string `json:"codec"`
	/// The codec of this stream (defined as the RFC 6381).
	MimeCodec *string `json:"mimeCodec"`
	/// The width of the video stream
	Width uint32 `json:"width"`
	/// The height of the video stream
	Height uint32 `json:"height"`
	/// The average bitrate of the video in bytes/s
	Bitrate uint32 `json:"bitrate"`
	/// Is this stream the default one of it's type?
	IsDefault bool `json:"isDefault"`

	/// Keyframes of this video
	Keyframes *Keyframe `json:"-"`
}

func (*Video) Quality

func (video *Video) Quality() Quality

type VideoKey

type VideoKey struct {
	// contains filtered or unexported fields
}

type VideoStream

type VideoStream struct {
	Stream
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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