Documentation ¶
Index ¶
- Constants
- Variables
- func Download(ctx context.Context, configDirectory string) error
- func DownloadSingle(ctx context.Context, configDirectory, url string) error
- func GetFrameFromRegex(str string) int
- func GetPaths(paths []string) (string, string)
- func GetTimeFromRegex(str string) float64
- func IsStreamable(videoCodec string, audioCodec AudioCodec, container Container) bool
- func IsValidAudio(audio AudioCodec, validCodecs []AudioCodec) bool
- func IsValidAudioForContainer(audio AudioCodec, format Container) bool
- func IsValidCodec(codecName string, supportedCodecs []string) bool
- func IsValidCombo(codecName string, format Container, supportedVideoCodecs []string) bool
- func IsValidForContainer(format Container, validContainers []Container) bool
- func KillRunningEncoders(path string)
- func WriteHLSPlaylist(probeResult VideoFile, baseUrl string, w io.Writer)
- type AudioCodec
- type Codec
- type Container
- type Encoder
- func (e *Encoder) CopyVideo(probeResult VideoFile, options TranscodeOptions)
- func (e *Encoder) GetTranscodeStream(options TranscodeStreamOptions) (*Stream, error)
- func (e *Encoder) ImageThumbnail(image *bytes.Buffer, format *string, maxDimensions int, path string) ([]byte, error)
- func (e *Encoder) SceneMarkerImage(probeResult VideoFile, options SceneMarkerOptions) error
- func (e *Encoder) SceneMarkerVideo(probeResult VideoFile, options SceneMarkerOptions) error
- func (e *Encoder) ScenePreviewVideoChunk(probeResult VideoFile, options ScenePreviewChunkOptions, preset string, ...) error
- func (e *Encoder) ScenePreviewVideoChunkCombine(probeResult VideoFile, concatFilePath string, outputPath string) error
- func (e *Encoder) ScenePreviewVideoToImage(probeResult VideoFile, width int, videoPreviewPath string, outputPath string) error
- func (e *Encoder) Screenshot(probeResult VideoFile, options ScreenshotOptions) error
- func (e *Encoder) SpriteScreenshot(probeResult VideoFile, options SpriteScreenshotOptions) (image.Image, error)
- func (e *Encoder) SpriteScreenshotSlow(probeResult VideoFile, options SpriteScreenshotOptions) (image.Image, error)
- func (e *Encoder) Transcode(probeResult VideoFile, options TranscodeOptions)
- func (e *Encoder) TranscodeAudio(probeResult VideoFile, options TranscodeOptions)
- func (e *Encoder) TranscodeVideo(probeResult VideoFile, options TranscodeOptions)
- type FFProbe
- type FFProbeJSON
- type FFProbeStream
- type SceneMarkerOptions
- type ScenePreviewChunkOptions
- type ScreenshotOptions
- type SpriteScreenshotOptions
- type Stream
- type TranscodeOptions
- type TranscodeStreamOptions
- type VideoFile
Constants ¶
const ( Mp4 Container = "mp4" M4v Container = "m4v" Mov Container = "mov" Wmv Container = "wmv" Webm Container = "webm" Matroska Container = "matroska" Avi Container = "avi" Flv Container = "flv" Mpegts Container = "mpegts" Aac AudioCodec = "aac" Mp3 AudioCodec = "mp3" Opus AudioCodec = "opus" Vorbis AudioCodec = "vorbis" MissingUnsupported AudioCodec = "" Mp4Ffmpeg string = "mov,mp4,m4a,3gp,3g2,mj2" // browsers support all of them M4vFfmpeg string = "mov,mp4,m4a,3gp,3g2,mj2" // so we don't care that ffmpeg MovFfmpeg string = "mov,mp4,m4a,3gp,3g2,mj2" // can't differentiate between them WmvFfmpeg string = "asf" WebmFfmpeg string = "matroska,webm" MatroskaFfmpeg string = "matroska,webm" AviFfmpeg string = "avi" FlvFfmpeg string = "flv" MpegtsFfmpeg string = "mpegts" H264 string = "h264" H265 string = "h265" // found in rare cases from a faulty encoder Hevc string = "hevc" Vp8 string = "vp8" Vp9 string = "vp9" Mkv string = "mkv" // only used from the browser to indicate mkv support Hls string = "hls" // only used from the browser to indicate hls support MimeWebm string = "video/webm" MimeMkv string = "video/x-matroska" MimeMp4 string = "video/mp4" MimeHLS string = "application/vnd.apple.mpegurl" MimeMpegts string = "video/MP2T" )
const CopyStreamCodec = "copy"
Variables ¶
var CodecH264 = Codec{ Codec: "libx264", MimeType: MimeMp4, // contains filtered or unexported fields }
var CodecHEVC = Codec{ Codec: "libx265", MimeType: MimeMp4, // contains filtered or unexported fields }
var CodecHLS = Codec{ Codec: "libx264", MimeType: MimeMpegts, // contains filtered or unexported fields }
var CodecMKVAudio = Codec{ Codec: CopyStreamCodec, MimeType: MimeMkv, // contains filtered or unexported fields }
it is very common in MKVs to have just the audio codec unsupported copy the video stream, transcode the audio and serve as Matroska
var CodecVP8 = Codec{ Codec: "libvpx", MimeType: MimeWebm, // contains filtered or unexported fields }
var CodecVP9 = Codec{ Codec: "libvpx-vp9", MimeType: MimeWebm, // contains filtered or unexported fields }
var ContainerToFfprobe = map[Container]string{ Mp4: Mp4Ffmpeg, M4v: M4vFfmpeg, Mov: MovFfmpeg, Wmv: WmvFfmpeg, Webm: WebmFfmpeg, Matroska: MatroskaFfmpeg, Avi: AviFfmpeg, Flv: FlvFfmpeg, Mpegts: MpegtsFfmpeg, }
ContainerToFfprobe maps user readable container strings to ffprobe's format_name. On some formats ffprobe can't differentiate
var DefaultSupportedCodecs = []string{H264, H265}
only support H264 by default, since Safari does not support VP8/VP9
var ErrUnsupportedFormat = errors.New("unsupported image format")
var FfprobeToContainer = map[string]Container{ Mp4Ffmpeg: Mp4, WmvFfmpeg: Wmv, AviFfmpeg: Avi, FlvFfmpeg: Flv, MpegtsFfmpeg: Mpegts, MatroskaFfmpeg: Matroska, }
var FrameRegex = regexp.MustCompile(`frame=\s*([0-9]+)`)
var TimeRegex = regexp.MustCompile(`time=\s*(\d+):(\d+):(\d+.\d+)`)
Functions ¶
func DownloadSingle ¶ added in v0.4.0
func GetFrameFromRegex ¶
func GetTimeFromRegex ¶
func IsStreamable ¶ added in v0.3.0
func IsStreamable(videoCodec string, audioCodec AudioCodec, container Container) bool
func IsValidAudio ¶ added in v0.2.0
func IsValidAudio(audio AudioCodec, validCodecs []AudioCodec) bool
func IsValidAudioForContainer ¶ added in v0.2.0
func IsValidAudioForContainer(audio AudioCodec, format Container) bool
func IsValidCodec ¶
func IsValidCombo ¶ added in v0.2.0
IsValidCombo checks if a codec/container combination is valid. Returns true on validity, false otherwise
func IsValidForContainer ¶ added in v0.2.0
func KillRunningEncoders ¶
func KillRunningEncoders(path string)
Types ¶
type AudioCodec ¶ added in v0.2.0
type AudioCodec string
type Container ¶ added in v0.2.0
type Container string
func MagicContainer ¶ added in v0.2.0
MagicContainer returns the container type of a file path. Returns the zero-value on errors or no-match. Implements mkv or webm only, as ffprobe can't distinguish between them and not all browsers support mkv
func MatchContainer ¶ added in v0.2.0
type Encoder ¶
type Encoder string
func (*Encoder) CopyVideo ¶ added in v0.2.0
func (e *Encoder) CopyVideo(probeResult VideoFile, options TranscodeOptions)
CopyVideo will copy the video stream as is, and drop the audio stream.
func (*Encoder) GetTranscodeStream ¶ added in v0.3.0
func (e *Encoder) GetTranscodeStream(options TranscodeStreamOptions) (*Stream, error)
func (*Encoder) ImageThumbnail ¶ added in v0.11.0
func (*Encoder) SceneMarkerImage ¶
func (e *Encoder) SceneMarkerImage(probeResult VideoFile, options SceneMarkerOptions) error
func (*Encoder) SceneMarkerVideo ¶
func (e *Encoder) SceneMarkerVideo(probeResult VideoFile, options SceneMarkerOptions) error
func (*Encoder) ScenePreviewVideoChunk ¶
func (*Encoder) ScenePreviewVideoChunkCombine ¶
func (*Encoder) ScenePreviewVideoToImage ¶
func (*Encoder) Screenshot ¶
func (e *Encoder) Screenshot(probeResult VideoFile, options ScreenshotOptions) error
func (*Encoder) SpriteScreenshot ¶ added in v0.7.0
func (*Encoder) SpriteScreenshotSlow ¶ added in v0.13.0
func (e *Encoder) SpriteScreenshotSlow(probeResult VideoFile, options SpriteScreenshotOptions) (image.Image, error)
SpriteScreenshotSlow uses the select filter to get a single frame from a videofile instead of seeking It is very slow and should only be used for files with very small duration in secs / frame count
func (*Encoder) Transcode ¶
func (e *Encoder) Transcode(probeResult VideoFile, options TranscodeOptions)
func (*Encoder) TranscodeAudio ¶ added in v0.2.0
func (e *Encoder) TranscodeAudio(probeResult VideoFile, options TranscodeOptions)
TranscodeAudio will copy the video stream as is, and transcode audio.
func (*Encoder) TranscodeVideo ¶ added in v0.2.0
func (e *Encoder) TranscodeVideo(probeResult VideoFile, options TranscodeOptions)
TranscodeVideo transcodes the video, and removes the audio. In some videos where the audio codec is not supported by ffmpeg, ffmpeg fails if you try to transcode the audio
type FFProbe ¶ added in v0.11.0
type FFProbe string
FFProbe
func (*FFProbe) GetReadFrameCount ¶ added in v0.13.0
GetReadFrameCount counts the actual frames of the video file
type FFProbeJSON ¶
type FFProbeJSON struct { Format struct { BitRate string `json:"bit_rate"` Duration string `json:"duration"` Filename string `json:"filename"` FormatLongName string `json:"format_long_name"` FormatName string `json:"format_name"` NbPrograms int `json:"nb_programs"` NbStreams int `json:"nb_streams"` ProbeScore int `json:"probe_score"` Size string `json:"size"` StartTime string `json:"start_time"` Tags struct { CompatibleBrands string `json:"compatible_brands"` CreationTime models.JSONTime `json:"creation_time"` Encoder string `json:"encoder"` MajorBrand string `json:"major_brand"` MinorVersion string `json:"minor_version"` Title string `json:"title"` Comment string `json:"comment"` } `json:"tags"` } `json:"format"` Streams []FFProbeStream `json:"streams"` Error struct { Code int `json:"code"` String string `json:"string"` } `json:"error"` }
type FFProbeStream ¶
type FFProbeStream struct { AvgFrameRate string `json:"avg_frame_rate"` BitRate string `json:"bit_rate"` BitsPerRawSample string `json:"bits_per_raw_sample,omitempty"` ChromaLocation string `json:"chroma_location,omitempty"` CodecLongName string `json:"codec_long_name"` CodecName string `json:"codec_name"` CodecTag string `json:"codec_tag"` CodecTagString string `json:"codec_tag_string"` CodecTimeBase string `json:"codec_time_base"` CodecType string `json:"codec_type"` CodedHeight int `json:"coded_height,omitempty"` CodedWidth int `json:"coded_width,omitempty"` DisplayAspectRatio string `json:"display_aspect_ratio,omitempty"` Disposition struct { AttachedPic int `json:"attached_pic"` CleanEffects int `json:"clean_effects"` Comment int `json:"comment"` Default int `json:"default"` Dub int `json:"dub"` Forced int `json:"forced"` HearingImpaired int `json:"hearing_impaired"` Karaoke int `json:"karaoke"` Lyrics int `json:"lyrics"` Original int `json:"original"` TimedThumbnails int `json:"timed_thumbnails"` VisualImpaired int `json:"visual_impaired"` } `json:"disposition"` Duration string `json:"duration"` DurationTs int `json:"duration_ts"` HasBFrames int `json:"has_b_frames,omitempty"` Height int `json:"height,omitempty"` Index int `json:"index"` IsAvc string `json:"is_avc,omitempty"` Level int `json:"level,omitempty"` NalLengthSize string `json:"nal_length_size,omitempty"` NbFrames string `json:"nb_frames"` NbReadFrames string `json:"nb_read_frames"` PixFmt string `json:"pix_fmt,omitempty"` Profile string `json:"profile"` RFrameRate string `json:"r_frame_rate"` Refs int `json:"refs,omitempty"` SampleAspectRatio string `json:"sample_aspect_ratio,omitempty"` StartPts int `json:"start_pts"` StartTime string `json:"start_time"` Tags struct { CreationTime models.JSONTime `json:"creation_time"` HandlerName string `json:"handler_name"` Language string `json:"language"` Rotate string `json:"rotate"` } `json:"tags"` TimeBase string `json:"time_base"` Width int `json:"width,omitempty"` BitsPerSample int `json:"bits_per_sample,omitempty"` ChannelLayout string `json:"channel_layout,omitempty"` Channels int `json:"channels,omitempty"` MaxBitRate string `json:"max_bit_rate,omitempty"` SampleFmt string `json:"sample_fmt,omitempty"` SampleRate string `json:"sample_rate,omitempty"` }
type SceneMarkerOptions ¶
type ScreenshotOptions ¶
type SpriteScreenshotOptions ¶ added in v0.7.0
type Stream ¶ added in v0.3.0
type Stream struct { Stdout io.ReadCloser Process *os.Process // contains filtered or unexported fields }
type TranscodeOptions ¶
type TranscodeOptions struct { OutputPath string MaxTranscodeSize models.StreamingResolutionEnum }
type TranscodeStreamOptions ¶ added in v0.3.0
type TranscodeStreamOptions struct { ProbeResult VideoFile Codec Codec StartTime string MaxTranscodeSize models.StreamingResolutionEnum // transcode the video, remove the audio // in some videos where the audio codec is not supported by ffmpeg // ffmpeg fails if you try to transcode the audio VideoOnly bool }
func GetTranscodeStreamOptions ¶ added in v0.3.0
func GetTranscodeStreamOptions(probeResult VideoFile, videoCodec Codec, audioCodec AudioCodec) TranscodeStreamOptions
type VideoFile ¶
type VideoFile struct { JSON FFProbeJSON AudioStream *FFProbeStream VideoStream *FFProbeStream Path string Title string Comment string Container string Duration float64 StartTime float64 Bitrate int64 Size int64 CreationTime time.Time VideoCodec string VideoBitrate int64 Width int Height int FrameRate float64 Rotation int64 FrameCount int64 AudioCodec string }
func (*VideoFile) GetAudioStream ¶
func (v *VideoFile) GetAudioStream() *FFProbeStream
func (*VideoFile) GetVideoStream ¶
func (v *VideoFile) GetVideoStream() *FFProbeStream