diff --git a/.circleci/config.yml b/.circleci/config.yml index 0c5b444..77eb9bd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,3 +15,4 @@ jobs: - run: sudo apt-get update && sudo apt-get install ffmpeg - run: go mod download - run: go test -failfast -v -run=. ./... + - run: go build diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2ad87fe --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 FlooStack + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index e7921d0..570791b 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,6 @@ # Golang Transcoding Library -
- -
- - - Build Status - - - - Test Coverage - - -
- -
- -
- Created by FlooStack. -
+> This repository is no longer maintained. Please use [Goffmpeg](https://github.com/xfrr/goffmpeg). ## Features @@ -33,7 +15,7 @@ ## Download from Github ```shell -go get github.com/floostack/gotrans +go get github.com/floostack/transcoder ``` ## Example @@ -44,15 +26,24 @@ package main import ( "log" - ffmpeg "github.com/floostack/gotrans/ffmpeg" + ffmpeg "github.com/floostack/transcoder/ffmpeg" ) func main() { + + hwaccel := "cuvid" + videoCodec := "h264_cuvid" + + inputOpts := ffmpeg.Options{ + Hwaccel: &hwaccel, + VideoCodec: &videoCodec, + } + format := "mp4" overwrite := true - opts := ffmpeg.Options{ + outputOpts := ffmpeg.Options{ OutputFormat: &format, Overwrite: &overwrite, } @@ -67,8 +58,9 @@ func main() { New(ffmpegConf). Input("/tmp/avi"). Output("/tmp/mp4"). - WithOptions(opts). - Start(opts) + WithInputOptions(inputOpts). + WithOutputOptions(outputOpts). + Start() if err != nil { log.Fatal(err) diff --git a/config.go b/config.go index 58d9071..527258a 100644 --- a/config.go +++ b/config.go @@ -1,4 +1,4 @@ -package gotrans +package transcoder // Config ... type Config interface{} diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index a61dd8a..6328104 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -3,6 +3,7 @@ package ffmpeg import ( "bufio" "bytes" + "context" "encoding/json" "errors" "fmt" @@ -13,34 +14,36 @@ import ( "strconv" "strings" - "github.com/floostack/gotrans" - "github.com/floostack/gotrans/utils" + "github.com/floostack/transcoder" + "github.com/floostack/transcoder/utils" ) // Transcoder ... type Transcoder struct { config *Config input string - output string - options []string - metadata *Metadata + output []string + inputOptions []string + outputOptions [][]string + metadata transcoder.Metadata inputPipeReader *io.ReadCloser outputPipeReader *io.ReadCloser inputPipeWriter *io.WriteCloser outputPipeWriter *io.WriteCloser + commandContext *context.Context } // New ... -func New(cfg *Config) gotrans.Transcoder { +func New(cfg *Config) transcoder.Transcoder { return &Transcoder{config: cfg} } // Start ... -func (t *Transcoder) Start(opts gotrans.Options) (<-chan gotrans.Progress, error) { +func (t *Transcoder) Start() (<-chan transcoder.Progress, error) { var stderrIn io.ReadCloser - out := make(chan gotrans.Progress) + out := make(chan transcoder.Progress) defer t.closePipes() @@ -50,21 +53,53 @@ func (t *Transcoder) Start(opts gotrans.Options) (<-chan gotrans.Progress, error } // Get file metadata - _, err := t.getMetadata() + _, err := t.GetMetadata() if err != nil { return nil, err } - // Get executable flags - args := append([]string{"-i", t.input}, opts.GetStrArguments()...) + // Append input file and standard options + var args []string - // Append output flag - args = append(args, []string{t.output}...) + if len(t.inputOptions) > 0 { + args = append(args, t.inputOptions...) + } - // Initialize command - cmd := exec.Command(t.config.FfmpegBinPath, args...) + args = append(args, []string{"-i", t.input}...) + outputLength := len(t.output) + outputOptionsLength := len(t.outputOptions) + + if outputLength == 1 && outputOptionsLength == 0 { + // Just append the 1 output file we've got + args = append(args, t.output[0]) + } else { + for index, out := range t.output { + // Get executable flags + // If we are at the last output file but still have several options, append them all at once + if index == outputLength-1 && outputLength < outputOptionsLength { + for i := index; i < len(t.outputOptions); i++ { + args = append(args, t.outputOptions[i]...) + } + // Otherwise just append the current options + } else { + args = append(args, t.outputOptions[index]...) + } - // cmd.Stderr = os.Stdout + // Append output flag + args = append(args, out) + } + } + + // Initialize command + // If a context object was supplied to this Transcoder before + // starting, use this context when creating the command to allow + // the command to be killed when the context expires + var cmd *exec.Cmd + if t.commandContext == nil { + cmd = exec.Command(t.config.FfmpegBinPath, args...) + } else { + cmd = exec.CommandContext(*t.commandContext, t.config.FfmpegBinPath, args...) + } // If progresss enabled, get stderr pipe and start progress process if t.config.ProgressEnabled && !t.config.Verbose { @@ -88,31 +123,32 @@ func (t *Transcoder) Start(opts gotrans.Options) (<-chan gotrans.Progress, error go func() { t.progress(stderrIn, out) }() - } - go func() { - defer close(out) - // Start process + go func() { + defer close(out) + err = cmd.Wait() + }() + } else { err = cmd.Wait() - }() + } return out, nil } // Input ... -func (t *Transcoder) Input(arg string) gotrans.Transcoder { +func (t *Transcoder) Input(arg string) transcoder.Transcoder { t.input = arg return t } // Output ... -func (t *Transcoder) Output(arg string) gotrans.Transcoder { - t.output = arg +func (t *Transcoder) Output(arg string) transcoder.Transcoder { + t.output = append(t.output, arg) return t } // InputPipe ... -func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) gotrans.Transcoder { +func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.Transcoder { if &t.input == nil { t.inputPipeWriter = w t.inputPipeReader = r @@ -121,7 +157,7 @@ func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) gotrans.Tran } // OutputPipe ... -func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) gotrans.Transcoder { +func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.Transcoder { if &t.output == nil { t.outputPipeWriter = w t.outputPipeReader = r @@ -129,9 +165,35 @@ func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) gotrans.Tra return t } -// WithOptions ... -func (t *Transcoder) WithOptions(opts gotrans.Options) gotrans.Transcoder { - t.options = opts.GetStrArguments() +// WithInputOptions Sets the options object +func (t *Transcoder) WithInputOptions(opts transcoder.Options) transcoder.Transcoder { + t.inputOptions = opts.GetStrArguments() + return t +} + +// WithAdditionalInputOptions Appends an additional options object +func (t *Transcoder) WithAdditionalInputOptions(opts transcoder.Options) transcoder.Transcoder { + t.inputOptions = append(t.inputOptions, opts.GetStrArguments()...) + return t +} + +// WithOutputOptions Sets the options object +func (t *Transcoder) WithOutputOptions(opts transcoder.Options) transcoder.Transcoder { + t.outputOptions = [][]string{opts.GetStrArguments()} + return t +} + +// WithAdditionalOutputOptions Appends an additional options object +func (t *Transcoder) WithAdditionalOutputOptions(opts transcoder.Options) transcoder.Transcoder { + t.outputOptions = append(t.outputOptions, opts.GetStrArguments()) + return t +} + +// WithContext is to be used on a Transcoder *before Starting* to +// pass in a context.Context object that can be used to kill +// a running transcoder process. Usage of this method is optional +func (t *Transcoder) WithContext(ctx *context.Context) transcoder.Transcoder { + t.commandContext = ctx return t } @@ -145,14 +207,29 @@ func (t *Transcoder) validate() error { return errors.New("missing input option") } - if t.output == "" { + outputLength := len(t.output) + + if outputLength == 0 { return errors.New("missing output option") } + // length of output files being greater than length of options would produce an invalid ffmpeg command + // unless there is only 1 output file, which obviously wouldn't be a problem + if outputLength > len(t.outputOptions) && outputLength != 1 { + return errors.New("number of options and output files does not match") + } + + for index, output := range t.output { + if output == "" { + return fmt.Errorf("output at index %d is an empty string", index) + } + } + return nil } -func (t *Transcoder) getMetadata() (metadata *Metadata, err error) { +// GetMetadata Returns metadata for the specified input file +func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) { if t.config.FfprobeBinPath != "" { var outb, errb bytes.Buffer @@ -174,6 +251,8 @@ func (t *Transcoder) getMetadata() (metadata *Metadata, err error) { return nil, fmt.Errorf("error executing (%s) with args (%s) | error: %s | message: %s %s", t.config.FfprobeBinPath, args, err, outb.String(), errb.String()) } + var metadata Metadata + if err = json.Unmarshal([]byte(outb.String()), &metadata); err != nil { return nil, err } @@ -187,7 +266,7 @@ func (t *Transcoder) getMetadata() (metadata *Metadata, err error) { } // progress sends through given channel the transcoding status -func (t *Transcoder) progress(stream io.ReadCloser, out chan gotrans.Progress) { +func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress) { defer stream.Close() @@ -220,7 +299,7 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan gotrans.Progress) { Progress := new(Progress) line := scanner.Text() - if strings.Contains(line, "frame=") && strings.Contains(line, "time=") && strings.Contains(line, "bitrate=") { + if strings.Contains(line, "time=") && strings.Contains(line, "bitrate=") { var re = regexp.MustCompile(`=\s+`) st := re.ReplaceAllString(line, `=`) @@ -257,7 +336,7 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan gotrans.Progress) { } timesec := utils.DurToSec(currentTime) - dursec, _ := strconv.ParseFloat(t.metadata.Format.Duration, 64) + dursec, _ := strconv.ParseFloat(t.metadata.GetFormat().GetDuration(), 64) progress := (timesec * 100) / dursec Progress.Progress = progress diff --git a/ffmpeg/metadata.go b/ffmpeg/metadata.go new file mode 100644 index 0000000..4e81910 --- /dev/null +++ b/ffmpeg/metadata.go @@ -0,0 +1,338 @@ +package ffmpeg + +import "github.com/floostack/transcoder" + +// Metadata ... +type Metadata struct { + Format Format `json:"format"` + Streams []Streams `json:"streams"` +} + +// Format ... +type Format struct { + Filename string + NbStreams int `json:"nb_streams"` + NbPrograms int `json:"nb_programs"` + FormatName string `json:"format_name"` + FormatLongName string `json:"format_long_name"` + Duration string `json:"duration"` + Size string `json:"size"` + BitRate string `json:"bit_rate"` + ProbeScore int `json:"probe_score"` + Tags Tags `json:"tags"` +} + +// Streams ... +type Streams struct { + Index int + ID string `json:"id"` + CodecName string `json:"codec_name"` + CodecLongName string `json:"codec_long_name"` + Profile string `json:"profile"` + CodecType string `json:"codec_type"` + CodecTimeBase string `json:"codec_time_base"` + CodecTagString string `json:"codec_tag_string"` + CodecTag string `json:"codec_tag"` + Width int `json:"width"` + Height int `json:"height"` + CodedWidth int `json:"coded_width"` + CodedHeight int `json:"coded_height"` + HasBFrames int `json:"has_b_frames"` + SampleAspectRatio string `json:"sample_aspect_ratio"` + DisplayAspectRatio string `json:"display_aspect_ratio"` + PixFmt string `json:"pix_fmt"` + Level int `json:"level"` + ChromaLocation string `json:"chroma_location"` + Refs int `json:"refs"` + QuarterSample string `json:"quarter_sample"` + DivxPacked string `json:"divx_packed"` + RFrameRrate string `json:"r_frame_rate"` + AvgFrameRate string `json:"avg_frame_rate"` + TimeBase string `json:"time_base"` + DurationTs int `json:"duration_ts"` + Duration string `json:"duration"` + Disposition Disposition `json:"disposition"` + BitRate string `json:"bit_rate"` +} + +// Tags ... +type Tags struct { + Encoder string `json:"ENCODER"` +} + +// Disposition ... +type Disposition struct { + Default int `json:"default"` + Dub int `json:"dub"` + Original int `json:"original"` + Comment int `json:"comment"` + Lyrics int `json:"lyrics"` + Karaoke int `json:"karaoke"` + Forced int `json:"forced"` + HearingImpaired int `json:"hearing_impaired"` + VisualImpaired int `json:"visual_impaired"` + CleanEffects int `json:"clean_effects"` +} + +// GetFormat ... +func (m Metadata) GetFormat() transcoder.Format { + return m.Format +} + +// GetStreams ... +func (m Metadata) GetStreams() (streams []transcoder.Streams) { + for _, element := range m.Streams { + streams = append(streams, element) + } + return streams +} + +// GetFilename ... +func (f Format) GetFilename() string { + return f.Filename +} + +// GetNbStreams ... +func (f Format) GetNbStreams() int { + return f.NbStreams +} + +// GetNbPrograms ... +func (f Format) GetNbPrograms() int { + return f.NbPrograms +} + +// GetFormatName ... +func (f Format) GetFormatName() string { + return f.FormatName +} + +// GetFormatLongName ... +func (f Format) GetFormatLongName() string { + return f.FormatLongName +} + +// GetDuration ... +func (f Format) GetDuration() string { + return f.Duration +} + +// GetSize ... +func (f Format) GetSize() string { + return f.Size +} + +// GetBitRate ... +func (f Format) GetBitRate() string { + return f.BitRate +} + +// GetProbeScore ... +func (f Format) GetProbeScore() int { + return f.ProbeScore +} + +// GetTags ... +func (f Format) GetTags() transcoder.Tags { + return f.Tags +} + +// GetEncoder ... +func (t Tags) GetEncoder() string { + return t.Encoder +} + +//GetIndex ... +func (s Streams) GetIndex() int { + return s.Index +} + +//GetID ... +func (s Streams) GetID() string { + return s.ID +} + +//GetCodecName ... +func (s Streams) GetCodecName() string { + return s.CodecName +} + +//GetCodecLongName ... +func (s Streams) GetCodecLongName() string { + return s.CodecLongName +} + +//GetProfile ... +func (s Streams) GetProfile() string { + return s.Profile +} + +//GetCodecType ... +func (s Streams) GetCodecType() string { + return s.CodecType +} + +//GetCodecTimeBase ... +func (s Streams) GetCodecTimeBase() string { + return s.CodecTimeBase +} + +//GetCodecTagString ... +func (s Streams) GetCodecTagString() string { + return s.CodecTagString +} + +//GetCodecTag ... +func (s Streams) GetCodecTag() string { + return s.CodecTag +} + +//GetWidth ... +func (s Streams) GetWidth() int { + return s.Width +} + +//GetHeight ... +func (s Streams) GetHeight() int { + return s.Height +} + +//GetCodedWidth ... +func (s Streams) GetCodedWidth() int { + return s.CodedWidth +} + +//GetCodedHeight ... +func (s Streams) GetCodedHeight() int { + return s.CodedHeight +} + +//GetHasBFrames ... +func (s Streams) GetHasBFrames() int { + return s.HasBFrames +} + +//GetSampleAspectRatio ... +func (s Streams) GetSampleAspectRatio() string { + return s.SampleAspectRatio +} + +//GetDisplayAspectRatio ... +func (s Streams) GetDisplayAspectRatio() string { + return s.DisplayAspectRatio +} + +//GetPixFmt ... +func (s Streams) GetPixFmt() string { + return s.PixFmt +} + +//GetLevel ... +func (s Streams) GetLevel() int { + return s.Level +} + +//GetChromaLocation ... +func (s Streams) GetChromaLocation() string { + return s.ChromaLocation +} + +//GetRefs ... +func (s Streams) GetRefs() int { + return s.Refs +} + +//GetQuarterSample ... +func (s Streams) GetQuarterSample() string { + return s.QuarterSample +} + +//GetDivxPacked ... +func (s Streams) GetDivxPacked() string { + return s.DivxPacked +} + +//GetRFrameRrate ... +func (s Streams) GetRFrameRrate() string { + return s.RFrameRrate +} + +//GetAvgFrameRate ... +func (s Streams) GetAvgFrameRate() string { + return s.AvgFrameRate +} + +//GetTimeBase ... +func (s Streams) GetTimeBase() string { + return s.TimeBase +} + +//GetDurationTs ... +func (s Streams) GetDurationTs() int { + return s.DurationTs +} + +//GetDuration ... +func (s Streams) GetDuration() string { + return s.Duration +} + +//GetDisposition ... +func (s Streams) GetDisposition() transcoder.Disposition { + return s.Disposition +} + +//GetBitRate ... +func (s Streams) GetBitRate() string { + return s.BitRate +} + +//GetDefault ... +func (d Disposition) GetDefault() int { + return d.Default +} + +//GetDub ... +func (d Disposition) GetDub() int { + return d.Dub +} + +//GetOriginal ... +func (d Disposition) GetOriginal() int { + return d.Original +} + +//GetComment ... +func (d Disposition) GetComment() int { + return d.Comment +} + +//GetLyrics ... +func (d Disposition) GetLyrics() int { + return d.Lyrics +} + +//GetKaraoke ... +func (d Disposition) GetKaraoke() int { + return d.Karaoke +} + +//GetForced ... +func (d Disposition) GetForced() int { + return d.Forced +} + +//GetHearingImpaired ... +func (d Disposition) GetHearingImpaired() int { + return d.HearingImpaired +} + +//GetVisualImpaired ... +func (d Disposition) GetVisualImpaired() int { + return d.VisualImpaired +} + +//GetCleanEffects ... +func (d Disposition) GetCleanEffects() int { + return d.CleanEffects +} diff --git a/ffmpeg/options.go b/ffmpeg/options.go index 3df7946..323d4b3 100644 --- a/ffmpeg/options.go +++ b/ffmpeg/options.go @@ -13,7 +13,7 @@ type Options struct { VideoBitRateTolerance *int `flag:"-bt"` VideoMaxBitRate *int `flag:"-maxrate"` VideoMinBitrate *int `flag:"-minrate"` - VideoCodec *string `flag:"--c:v"` + VideoCodec *string `flag:"-c:v"` Vframes *int `flag:"-vframes"` FrameRate *int `flag:"-r"` AudioRate *int `flag:"-ar"` @@ -97,86 +97,18 @@ func (opts Options) GetStrArguments() []string { } } - if vm, ok := value.(map[string]string); ok { + if vm, ok := value.(map[string]interface{}); ok { for k, v := range vm { - values = append(values, flag, fmt.Sprintf("%v:%v", k, v)) + values = append(values, k, fmt.Sprintf("%v", v)) } } + + if vi, ok := value.(*int); ok { + values = append(values, flag, fmt.Sprintf("%d", *vi)) + } } } return values } - -// Metadata ... -type Metadata struct { - Streams []Streams `json:"streams"` - Format Format `json:"format"` -} - -// Streams defines allowed stream options -type Streams struct { - Index int - ID string `json:"id"` - CodecName string `json:"codec_name"` - CodecLongName string `json:"codec_long_name"` - Profile string `json:"profile"` - CodecType string `json:"codec_type"` - CodecTimeBase string `json:"codec_time_base"` - CodecTagString string `json:"codec_tag_string"` - CodecTag string `json:"codec_tag"` - Width int `json:"width"` - Height int `json:"height"` - CodedWidth int `json:"coded_width"` - CodedHeight int `json:"coded_height"` - HasBFrames int `json:"has_b_frames"` - SampleAspectRatio string `json:"sample_aspect_ratio"` - DisplayAspectRatio string `json:"display_aspect_ratio"` - PixFmt string `json:"pix_fmt"` - Level int `json:"level"` - ChromaLocation string `json:"chroma_location"` - Refs int `json:"refs"` - QuarterSample string `json:"quarter_sample"` - DivxPacked string `json:"divx_packed"` - RFrameRrate string `json:"r_frame_rate"` - AvgFrameRate string `json:"avg_frame_rate"` - TimeBase string `json:"time_base"` - DurationTs int `json:"duration_ts"` - Duration string `json:"duration"` - Disposition Disposition `json:"disposition"` - BitRate string `json:"bit_rate"` -} - -// Disposition ... -type Disposition struct { - Default int `json:"default"` - Dub int `json:"dub"` - Original int `json:"original"` - Comment int `json:"comment"` - Lyrics int `json:"lyrics"` - Karaoke int `json:"karaoke"` - Forced int `json:"forced"` - HearingImpaired int `json:"hearing_impaired"` - VisualImpaired int `json:"visual_impaired"` - CleanEffects int `json:"clean_effects"` -} - -// Format ... -type Format struct { - Filename string - NbStreams int `json:"nb_streams"` - NbPrograms int `json:"nb_programs"` - FormatName string `json:"format_name"` - FormatLongName string `json:"format_long_name"` - Duration string `json:"duration"` - Size string `json:"size"` - BitRate string `json:"bit_rate"` - ProbeScore int `json:"probe_score"` - Tags Tags `json:"tags"` -} - -// Tags ... -type Tags struct { - Encoder string `json:"ENCODER"` -} diff --git a/ffmpeg/progress.go b/ffmpeg/progress.go index 8603695..62594c6 100644 --- a/ffmpeg/progress.go +++ b/ffmpeg/progress.go @@ -8,3 +8,28 @@ type Progress struct { Progress float64 Speed string } + +// GetFramesProcessed ... +func (p Progress) GetFramesProcessed() string { + return p.FramesProcessed +} + +// GetCurrentTime ... +func (p Progress) GetCurrentTime() string { + return p.CurrentTime +} + +// GetCurrentBitrate ... +func (p Progress) GetCurrentBitrate() string { + return p.CurrentBitrate +} + +// GetProgress ... +func (p Progress) GetProgress() float64 { + return p.Progress +} + +// GetSpeed ... +func (p Progress) GetSpeed() string { + return p.Speed +} diff --git a/go.mod b/go.mod index c6a607b..4c9ade4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/floostack/gotrans +module github.com/floostack/transcoder go 1.13 diff --git a/metadata.go b/metadata.go new file mode 100644 index 0000000..d03241d --- /dev/null +++ b/metadata.go @@ -0,0 +1,73 @@ +package transcoder + +// Metadata ... +type Metadata interface { + GetFormat() Format + GetStreams() []Streams +} + +// Format ... +type Format interface { + GetFilename() string + GetNbStreams() int + GetNbPrograms() int + GetFormatName() string + GetFormatLongName() string + GetDuration() string + GetSize() string + GetBitRate() string + GetProbeScore() int + GetTags() Tags +} + +// Streams ... +type Streams interface { + GetIndex() int + GetID() string + GetCodecName() string + GetCodecLongName() string + GetProfile() string + GetCodecType() string + GetCodecTimeBase() string + GetCodecTagString() string + GetCodecTag() string + GetWidth() int + GetHeight() int + GetCodedWidth() int + GetCodedHeight() int + GetHasBFrames() int + GetSampleAspectRatio() string + GetDisplayAspectRatio() string + GetPixFmt() string + GetLevel() int + GetChromaLocation() string + GetRefs() int + GetQuarterSample() string + GetDivxPacked() string + GetRFrameRrate() string + GetAvgFrameRate() string + GetTimeBase() string + GetDurationTs() int + GetDuration() string + GetDisposition() Disposition + GetBitRate() string +} + +// Tags ... +type Tags interface { + GetEncoder() string +} + +// Disposition ... +type Disposition interface { + GetDefault() int + GetDub() int + GetOriginal() int + GetComment() int + GetLyrics() int + GetKaraoke() int + GetForced() int + GetHearingImpaired() int + GetVisualImpaired() int + GetCleanEffects() int +} diff --git a/options.go b/options.go index 108ebad..3813a9f 100644 --- a/options.go +++ b/options.go @@ -1,4 +1,4 @@ -package gotrans +package transcoder // Options ... type Options interface { diff --git a/progress.go b/progress.go index 3f6f83f..4b7b060 100644 --- a/progress.go +++ b/progress.go @@ -1,5 +1,10 @@ -package gotrans +package transcoder // Progress ... type Progress interface { + GetFramesProcessed() string + GetCurrentTime() string + GetCurrentBitrate() string + GetProgress() float64 + GetSpeed() string } diff --git a/source.go b/source.go deleted file mode 100644 index 297e647..0000000 --- a/source.go +++ /dev/null @@ -1,4 +0,0 @@ -package gotrans - -// Source ... -type Source interface{} diff --git a/transcoder.go b/transcoder.go index b568c08..f53ca4e 100644 --- a/transcoder.go +++ b/transcoder.go @@ -1,13 +1,21 @@ -package gotrans +package transcoder -import "io" +import ( + "context" + "io" +) // Transcoder ... type Transcoder interface { - Start(opts Options) (<-chan Progress, error) + Start() (<-chan Progress, error) Input(i string) Transcoder InputPipe(w *io.WriteCloser, r *io.ReadCloser) Transcoder Output(o string) Transcoder OutputPipe(w *io.WriteCloser, r *io.ReadCloser) Transcoder - WithOptions(opts Options) Transcoder + WithInputOptions(opts Options) Transcoder + WithAdditionalInputOptions(opts Options) Transcoder + WithOutputOptions(opts Options) Transcoder + WithAdditionalOutputOptions(opts Options) Transcoder + WithContext(ctx *context.Context) Transcoder + GetMetadata() (Metadata, error) }