video

package
v0.0.0-...-6a2a004 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

README

Video File Support

Codecs and Containers

For maximum browser compatibility, PhotoPrism can transcode video codecs and containers supported by FFmpeg to MPEG-4 AVC.

Running the following command in a terminal displays a list of supported codecs:

ffmpeg -decoders

See our advanced setup guide to learn how to configure hardware video transcoding.

Please Note:

  1. Not all video and audio formats can be played with every browser. For example, AAC - the default audio codec for MPEG-4 AVC / H.264 - is supported natively in Chrome, Safari, and Edge, while it is only optionally supported by the OS in Firefox and Opera.
  2. HEVC/H.265 video files can have a .mp4 file extension too, which is often associated with AVC only. This is because MP4 is a container format, meaning that the actual video content may be compressed with H.264, H.265, or something else. The file extension doesn't really tell you anything other than that it's probably a video file.
  3. In case FFmpeg is disabled or not installed, videos cannot be indexed because still images cannot be created. You should also have Exiftool enabled to extract metadata such as duration, resolution, and codec.

Hybrid Photo/Video Formats

For more information on hybrid photo/video file formats, e.g. Apple Live Photos and Samsung/Google Motion Photos, see github.com/photoprism/photoprism/tree/develop/pkg/media and docs.photoprism.app/developer-guide/media/live.

Standard Resolutions

The PHOTOPRISM_FFMPEG_SIZE config option allows to limit the resolution of transcoded videos. It accepts the following standard sizes, while other values are automatically adjusted to the next supported size:

Size Usage
720 SD TV, Mobile
1280 HD TV, SXGA
1920 Full HD
2048 DCI 2K, Tablets
2560 Quad HD, Notebooks
3840 4K Ultra HD
4096 DCI 4K, Retina 4K
7680 8K Ultra HD 2

Technical References and Tutorials

Title URL
Web Video Codec Guide https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_codecs
Web Video Content-Type Headers https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter
Media Container Formats https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers
MP4 Signature Format https://www.file-recovery.com/mp4-signature-format.htm
List of file signatures (Wikipedia) https://en.wikipedia.org/wiki/List_of_file_signatures
How to use the io.Reader interface https://yourbasic.org/golang/io-reader-interface-explained/
AV1 Codec ISO Media File Format https://aomediacodec.github.io/av1-isobmff

PhotoPrism® is a registered trademark. By using the software and services we provide, you agree to our Terms of Service, Privacy Policy, and Code of Conduct. Docs are available under the CC BY-NC-SA 4.0 License; additional terms may apply.

Documentation

Overview

Package video provides video file related types and abstractions.

Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
<https://docs.photoprism.app/license/agpl>

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

The AGPL is supplemented by our Trademark and Brand Guidelines,
which describe how our Brand Assets may be used:
<https://www.photoprism.app/trademark>

Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.

Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>

Index

Constants

View Source
const (
	ContentTypeDefault = "application/octet-stream"
	ContentTypeAVC     = fs.MimeTypeMP4 + `; codecs="avc1"`
	ContentTypeMOV     = fs.MimeTypeMOV
)

Standard content types.

Variables

View Source
var (
	ChunkFTYP = Chunk{'f', 't', 'y', 'p'}
	ChunkQT   = Chunk{'q', 't', ' ', ' '}
	ChunkISOM = Chunk{'i', 's', 'o', 'm'}
	ChunkISO2 = Chunk{'i', 's', 'o', '2'}
	ChunkISO3 = Chunk{'i', 's', 'o', '3'}
	ChunkISO4 = Chunk{'i', 's', 'o', '4'}
	ChunkISO5 = Chunk{'i', 's', 'o', '5'}
	ChunkISO6 = Chunk{'i', 's', 'o', '6'}
	ChunkISO7 = Chunk{'i', 's', 'o', '7'}
	ChunkISO8 = Chunk{'i', 's', 'o', '8'}
	ChunkISO9 = Chunk{'i', 's', 'o', '9'}
	ChunkAVC1 = Chunk{'a', 'v', 'c', '1'}
	ChunkHEV1 = Chunk{'h', 'e', 'v', '1'}
	ChunkHVC1 = Chunk{'h', 'v', 'c', '1'}
	ChunkAV01 = Chunk{'a', 'v', '0', '1'}
	ChunkAV1C = Chunk{'a', 'v', '1', 'C'}
	ChunkMMP4 = Chunk{'m', 'm', 'p', '4'}
	ChunkMP4V = Chunk{'m', 'p', '4', 'v'}
	ChunkMP41 = Chunk{'m', 'p', '4', '1'}
	ChunkMP42 = Chunk{'m', 'p', '4', '2'}
	ChunkMP71 = Chunk{'m', 'p', '7', '1'}
	ChunkHEIC = Chunk{'h', 'e', 'i', 'c'}
)

ChunkFTYP specifies the start chunk of the ISO base media format, it must be followed by a valid subtype chunk. https://en.wikipedia.org/wiki/ISO_base_media_file_format

View Source
var AV1 = Type{
	Codec:       CodecAV1,
	FileType:    fs.VideoWebM,
	WidthLimit:  0,
	HeightLimit: 0,
	Public:      false,
}

AV1 + Google WebM.

View Source
var AVC = Type{
	Codec:       CodecAVC,
	FileType:    fs.VideoAVC,
	WidthLimit:  8192,
	HeightLimit: 4320,
	Public:      true,
}

AVC aka Advanced Video Coding (H.264).

View Source
var Codecs = StandardCodecs{
	"":         CodecUnknown,
	"a_opus":   CodecUnknown,
	"a_vorbis": CodecUnknown,
	"avc":      CodecAVC,
	"avc1":     CodecAVC,
	"v_avc":    CodecAVC,
	"v_avc1":   CodecAVC,
	"hevc":     CodecHVC,
	"hvc":      CodecHVC,
	"hvc1":     CodecHVC,
	"v_hvc":    CodecHVC,
	"v_hvc1":   CodecHVC,
	"vvc":      CodecVVC,
	"v_vvc":    CodecVVC,
	"av1":      CodecAV1,
	"av01":     CodecAV1,
	"v_av1":    CodecAV1,
	"v_av01":   CodecAV1,
	"vp8":      CodecVP8,
	"vp80":     CodecVP8,
	"v_vp8":    CodecVP8,
	"vp9":      CodecVP9,
	"vp09":     CodecVP9,
	"vp90":     CodecVP9,
	"v_vp9":    CodecVP9,
	"ogv":      CodecOGV,
	"webm":     CodecWebM,
}

Codecs maps identifiers to codecs.

CompatibleBrands contains compatible subtypes chunks.

View Source
var HEVC = Type{
	Codec:       CodecHVC,
	FileType:    fs.VideoHEVC,
	WidthLimit:  0,
	HeightLimit: 0,
	Public:      false,
}

HEVC aka High Efficiency Video Coding (H.265).

View Source
var LiveDuration = time.Millisecond * 3100

LiveDuration is the maximum duration for a video to play inline like a live photo.

View Source
var MOV = Type{
	Codec:       CodecAVC,
	FileType:    fs.VideoMOV,
	WidthLimit:  8192,
	HeightLimit: 4320,
	Public:      true,
}

MOV are QuickTime videos based on the MPEG-4 format,

View Source
var MP4 = Type{
	Codec:       CodecAVC,
	FileType:    fs.VideoMP4,
	WidthLimit:  8192,
	HeightLimit: 4320,
	Public:      true,
}

MP4 is a Multimedia Container (MPEG-4 Part 14).

View Source
var OGV = Type{
	Codec:       CodecOGV,
	FileType:    fs.VideoOGV,
	WidthLimit:  0,
	HeightLimit: 0,
	Public:      false,
}

OGV aka Ogg/Theora.

View Source
var Types = Standards{
	"":      AVC,
	"mp4":   MP4,
	"mpeg4": MP4,
	"avc":   AVC,
	"avc1":  AVC,
	"hvc":   HEVC,
	"hvc1":  HEVC,
	"hevc":  HEVC,
	"vvc":   VVC,
	"vvc1":  VVC,
	"vp8":   VP8,
	"vp80":  VP8,
	"vp9":   VP9,
	"vp90":  VP9,
	"av1":   AV1,
	"av01":  AV1,
	"ogg":   OGV,
	"ogv":   OGV,
	"webm":  WebM,
}

Types maps identifiers to standards.

View Source
var Unknown = Type{
	Codec:    CodecUnknown,
	FileType: fs.TypeUnknown,
}

Unknown represents an unknown video file type.

View Source
var VP8 = Type{
	Codec:       CodecVP8,
	FileType:    fs.VideoWebM,
	WidthLimit:  0,
	HeightLimit: 0,
	Public:      false,
}

VP8 + Google WebM.

View Source
var VP9 = Type{
	Codec:       CodecVP9,
	FileType:    fs.VideoWebM,
	WidthLimit:  0,
	HeightLimit: 0,
	Public:      false,
}

VP9 + Google WebM.

View Source
var VVC = Type{
	Codec:       CodecVVC,
	FileType:    fs.VideoVVC,
	WidthLimit:  0,
	HeightLimit: 0,
	Public:      false,
}

VVC aka Versatile Video Coding (H.266).

View Source
var WebM = Type{
	Codec:       CodecUnknown,
	FileType:    fs.VideoWebM,
	WidthLimit:  0,
	HeightLimit: 0,
	Public:      false,
}

WebM Container.

Functions

func ContentType

func ContentType(mimeType string, codec Codec) string

ContentType composes the video content type from the given mime type and codec.

func FileTypeOffset

func FileTypeOffset(fileName string, brands Chunks) (int, error)

FileTypeOffset returns the file type start offset, or -1 if it was not found.

Types

type Chunk

type Chunk [4]byte

Chunk represents a fixed length file chunk.

func (Chunk) Bytes

func (c Chunk) Bytes() []byte

Bytes returns the chunk as byte slice.

func (Chunk) DataOffset

func (c Chunk) DataOffset(file io.ReadSeeker) (int, error)

DataOffset returns the index of the chunk in file, or -1 if it was not found.

func (Chunk) Equal

func (c Chunk) Equal(b []byte) bool

Equal compares the chunk with a byte slice.

func (Chunk) FileOffset

func (c Chunk) FileOffset(fileName string) (int, error)

FileOffset returns the index of the chunk, or -1 if it was not found.

func (Chunk) Get

func (c Chunk) Get() [4]byte

Get returns the chunk as byte array.

func (Chunk) Hex

func (c Chunk) Hex() string

Hex returns the chunk as hex formatted string.

func (Chunk) String

func (c Chunk) String() string

String returns the chunk as string.

func (Chunk) Uint32

func (c Chunk) Uint32() uint32

Uint32 returns the chunk as unsigned integer.

type Chunks

type Chunks []Chunk

Chunks represents a list of file chunks.

func (Chunks) Contains

func (c Chunks) Contains(s [4]byte) bool

Contains tests if the chunk is contained in this list.

func (Chunks) ContainsAny

func (c Chunks) ContainsAny(b [][4]byte) bool

ContainsAny checks if at least one common chunk exists in this list.

func (Chunks) FileTypeOffset

func (c Chunks) FileTypeOffset(file io.ReadSeeker) (int, error)

FileTypeOffset returns the file type start offset in f, or -1 if it was not found.

type Codec

type Codec string
const (
	CodecUnknown Codec = ""
	CodecAVC     Codec = "avc1"
	CodecHVC     Codec = "hvc1"
	CodecVVC     Codec = "vvc"
	CodecAV1     Codec = "av01"
	CodecVP8     Codec = "vp8"
	CodecVP9     Codec = "vp9"
	CodecOGV     Codec = "ogv"
	CodecWebM    Codec = "webm"
)

func (Codec) String

func (c Codec) String() string

String returns the codec name as string.

type Info

type Info struct {
	FileName      string
	FileSize      int64
	FileType      fs.Type
	MediaType     media.Type
	ThumbOffset   int64
	ThumbMimeType string
	VideoOffset   int64
	VideoMimeType string
	VideoType     Type
	VideoCodec    Codec
	VideoWidth    int
	VideoHeight   int
	Duration      time.Duration
	Frames        int
	FPS           float64
	Tracks        int
	Encrypted     bool
	FastStart     bool
	Compatible    bool
}

Info represents video file information.

func NewInfo

func NewInfo() Info

NewInfo returns a new Info struct with default values.

func Probe

func Probe(file io.ReadSeeker) (info Info, err error)

Probe returns information on the provided video file. see https://pkg.go.dev/github.com/abema/go-mp4#ProbeInfo

func ProbeFile

func ProbeFile(fileName string) (info Info, err error)

ProbeFile returns information for the given filename.

func (Info) VideoBitrate

func (info Info) VideoBitrate() float64

VideoBitrate returns the bitrate of the embedded video in MBit/s.

func (Info) VideoContentType

func (info Info) VideoContentType() string

VideoContentType composes the video content type from its mime type and codec.

func (Info) VideoFileExt

func (info Info) VideoFileExt() string

VideoFileExt returns the appropriate video file extension based on the mime type and defaults to fs.ExtMP4 otherwise.

func (Info) VideoFileType

func (info Info) VideoFileType() fs.Type

VideoFileType returns the video type based on the mime type and defaults to fs.VideoMP4 otherwise.

func (Info) VideoSize

func (info Info) VideoSize() int64

VideoSize returns the size of the embedded video, if possible.

type ReadSeeker

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

ReadSeeker reads an existing file from an offset until the end.

func NewReadSeeker

func NewReadSeeker(file io.ReadSeeker, offset int64) *ReadSeeker

NewReadSeeker creates a new ReadSeeker.

func (*ReadSeeker) Read

func (r *ReadSeeker) Read(p []byte) (n int, err error)

Read reads up to len(p) bytes into p. It returns the number of bytes read and any error encountered.

func (*ReadSeeker) Seek

func (r *ReadSeeker) Seek(offset int64, whence int) (pos int64, err error)

Seek sets the offset for the next Read or Write to offset, interpreted according to whence: - SeekStart means relative to the start of the file - SeekCurrent means relative to the current offset - SeekEnd means relative to the end (for example, offset = -2 specifies the penultimate byte of the file)

Seek returns the new offset relative to the start of the file or an error, if any. Seeking to an offset before the start of the file is an error.

type Reader

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

Reader reads an existing file from an offset until the end.

func NewReader

func NewReader(fileName string, offset int64) (*Reader, error)

NewReader creates a new Reader.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the file after reading.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

Read reads up to len(p) bytes into p. It returns the number of bytes read and any error encountered.

type StandardCodecs

type StandardCodecs map[string]Codec

StandardCodecs maps names to known codecs.

type Standards

type Standards map[string]Type

Standards maps names to standardized formats.

type Type

type Type struct {
	Codec       Codec
	FileType    fs.Type
	WidthLimit  int
	HeightLimit int
	Public      bool
}

Type represents a video format type.

Jump to

Keyboard shortcuts

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