stream

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MIT Imports: 7 Imported by: 0

README

HLS and MPEG-DASH Encoding with Go

About

Commands used for generating hls and dash in bstore

To see how to integrate in a server environment check out.

  1. Upload API
  2. File Hosting API

Installation

go get github.com/cartersusi/stream

Usage

package main

import (
	"fmt"
	"os"

	"github.com/cartersusi/stream"
)

func dash(input_path, codec string) {
	encoder := stream.VideoEncoder{}
	err := encoder.New(input_path, codec, "dash")
	if err != nil {
		fmt.Println("Error:", err)
	}

	encoder.Print()
	err = encoder.Encode()
	if err != nil {
		fmt.Println("Error:", err)
	}
}

func hls(input_path, codec string) {
	encoder := stream.VideoEncoder{
		InputFile:  input_path,
		Codec:      codec,
		StreamType: stream.HLS,
		OutputDir:  "custom_output",
		OutputFile: "custom_output/index.m3u8",
	}

	encoder.CheckAudio() // not necessary, will auto check when encoding
	encoder.SetCommand() // not necessary, will auto set when encoding
	encoder.Print()

	err := encoder.Encode()
	if err != nil {
		fmt.Println("Error:", err)
	}
}

func main() {
	input_path := os.Args[1]
	codec := os.Args[2]

	dash(input_path, codec)
	hls(input_path, codec)
}

Documentation

Index

Constants

View Source
const (
	DASH = iota
	HLS
)

Variables

View Source
var MethodFMap = map[int]string{
	DASH: "index.mpd",
	HLS:  "index.m3u8",
}
View Source
var NameFMap = map[int]string{
	DASH: "DASH",
	HLS:  "HLS",
}
View Source
var VidEXT = []string{".mp4", ".webm", ".ogg", ".wmv", ".mov", ".avchd", ".av1"}

Functions

func CheckEXT

func CheckEXT(fname string) bool

func Contains

func Contains(source, target string) bool

func GetCMD

func GetCMD(name string, arg ...string) (string, error)

Types

type VideoEncoder

type VideoEncoder struct {
	InputFile  string
	Codec      string
	StreamType int
	OutputDir  string
	OutputFile string
	Audio      bool
	Command    string
}

func (*VideoEncoder) CheckAll

func (v *VideoEncoder) CheckAll() error

func (*VideoEncoder) CheckAudio

func (v *VideoEncoder) CheckAudio()

func (*VideoEncoder) CheckCodec

func (v *VideoEncoder) CheckCodec() bool

func (*VideoEncoder) DASHcmd

func (v *VideoEncoder) DASHcmd()

func (*VideoEncoder) Encode

func (v *VideoEncoder) Encode() error

func (*VideoEncoder) HLScmd

func (v *VideoEncoder) HLScmd()

func (*VideoEncoder) New

func (v *VideoEncoder) New(input_file, codec string, stream_type interface{}) error

func (*VideoEncoder) Print

func (v *VideoEncoder) Print()

func (*VideoEncoder) SetCommand

func (v *VideoEncoder) SetCommand()

func (*VideoEncoder) SetOutput

func (v *VideoEncoder) SetOutput()

func (*VideoEncoder) SetOutputDir

func (v *VideoEncoder) SetOutputDir()

func (*VideoEncoder) SetOutputFile

func (v *VideoEncoder) SetOutputFile()

func (*VideoEncoder) ValidateEncode

func (v *VideoEncoder) ValidateEncode() error

Jump to

Keyboard shortcuts

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