From 333882849913e01ab80aee34929e633ea6fc8747 Mon Sep 17 00:00:00 2001 From: xfrr Date: Fri, 26 Jun 2020 15:07:52 +0200 Subject: [PATCH 01/23] added go build to circleci --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) 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 From 6fff98e1caa843a9cc63d2a9e43a457448cc34ef Mon Sep 17 00:00:00 2001 From: xfrr Date: Fri, 26 Jun 2020 15:21:37 +0200 Subject: [PATCH 02/23] added codacy badge --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e7921d0..1621826 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,14 @@
- - - Build Status + + + Build Status - - - Test Coverage + + + + Build Status
From 125ff889213f0b9c0b565ab51e7b728c709d9124 Mon Sep 17 00:00:00 2001 From: xfrr Date: Fri, 26 Jun 2020 16:49:12 +0200 Subject: [PATCH 03/23] fixed readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1621826..64c9fe5 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@
- Created by FlooStack. + Created by FlooStack.
## Features From 9fd349b5c931e7398f248ab1383be316f6fb9b01 Mon Sep 17 00:00:00 2001 From: Fran <35836929+xfrr@users.noreply.github.com> Date: Thu, 30 Jul 2020 15:46:35 +0200 Subject: [PATCH 04/23] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 64c9fe5..651b613 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@
- - Build Status + + Build Status - + Build Status @@ -34,7 +34,7 @@ ## Download from Github ```shell -go get github.com/floostack/gotrans +go get github.com/floostack/transcoder ``` ## Example @@ -45,7 +45,7 @@ package main import ( "log" - ffmpeg "github.com/floostack/gotrans/ffmpeg" + ffmpeg "github.com/floostack/transcoder/ffmpeg" ) func main() { From 1f7b65086680138d5f3c1ea5e391c97305f54e75 Mon Sep 17 00:00:00 2001 From: xfrr Date: Tue, 4 Aug 2020 17:44:57 +0200 Subject: [PATCH 05/23] Fixed dependencies --- config.go | 2 +- ffmpeg/ffmpeg.go | 35 +++++++++++++++++------------------ go.mod | 2 +- options.go | 2 +- progress.go | 2 +- source.go | 4 ---- transcoder.go | 2 +- 7 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 source.go 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..013bc6a 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -13,8 +13,8 @@ import ( "strconv" "strings" - "github.com/floostack/gotrans" - "github.com/floostack/gotrans/utils" + "github.com/floostack/transcoder" + "github.com/floostack/transcoder/utils" ) // Transcoder ... @@ -31,16 +31,16 @@ type Transcoder struct { } // 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(opts transcoder.Options) (<-chan transcoder.Progress, error) { var stderrIn io.ReadCloser - out := make(chan gotrans.Progress) + out := make(chan transcoder.Progress) defer t.closePipes() @@ -64,8 +64,6 @@ func (t *Transcoder) Start(opts gotrans.Options) (<-chan gotrans.Progress, error // Initialize command cmd := exec.Command(t.config.FfmpegBinPath, args...) - // cmd.Stderr = os.Stdout - // If progresss enabled, get stderr pipe and start progress process if t.config.ProgressEnabled && !t.config.Verbose { stderrIn, err = cmd.StderrPipe() @@ -88,31 +86,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 { +func (t *Transcoder) Output(arg string) transcoder.Transcoder { 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 +120,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 @@ -130,7 +129,7 @@ func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) gotrans.Tra } // WithOptions ... -func (t *Transcoder) WithOptions(opts gotrans.Options) gotrans.Transcoder { +func (t *Transcoder) WithOptions(opts transcoder.Options) transcoder.Transcoder { t.options = opts.GetStrArguments() return t } @@ -187,7 +186,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() 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/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..5a65dd2 100644 --- a/progress.go +++ b/progress.go @@ -1,4 +1,4 @@ -package gotrans +package transcoder // Progress ... type Progress interface { 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..a4da0b6 100644 --- a/transcoder.go +++ b/transcoder.go @@ -1,4 +1,4 @@ -package gotrans +package transcoder import "io" From 5f826d4f6ac36c16e47dcb310ba444107f3a99a6 Mon Sep 17 00:00:00 2001 From: sidney Date: Mon, 14 Sep 2020 19:40:29 +0800 Subject: [PATCH 06/23] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 4c9ade4..1674b82 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/floostack/transcoder +module github.com/hatw/transcoder go 1.13 From 9c7b484280f23659a4848ef5a6e8e915c4f50327 Mon Sep 17 00:00:00 2001 From: sidney Date: Mon, 14 Sep 2020 19:41:17 +0800 Subject: [PATCH 07/23] Update options.go --- ffmpeg/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/options.go b/ffmpeg/options.go index 3df7946..d046758 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"` From 85fb5db8e685e01491efa35e3ccfecc761f65e39 Mon Sep 17 00:00:00 2001 From: sidney Date: Mon, 14 Sep 2020 19:51:00 +0800 Subject: [PATCH 08/23] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1674b82..4c9ade4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/hatw/transcoder +module github.com/floostack/transcoder go 1.13 From 725d471cfca84e872f7424ce3e079d9ff34b34ac Mon Sep 17 00:00:00 2001 From: Fran <35836929+xfrr@users.noreply.github.com> Date: Thu, 24 Sep 2020 10:44:27 +0200 Subject: [PATCH 09/23] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE 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. From 9a7b7ac512a7d065fd4ed0744b323a195f94459f Mon Sep 17 00:00:00 2001 From: xh Date: Wed, 14 Oct 2020 15:28:10 +0200 Subject: [PATCH 10/23] Adds method to append additional options --- ffmpeg/ffmpeg.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index 013bc6a..14fc2e8 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -134,6 +134,11 @@ func (t *Transcoder) WithOptions(opts transcoder.Options) transcoder.Transcoder return t } +func (t *Transcoder) WithAdditionalOptions(opts transcoder.Options) transcoder.Transcoder { + t.options = append(t.options, opts.GetStrArguments()...) + return t +} + // validate ... func (t *Transcoder) validate() error { if t.config.FfmpegBinPath == "" { From cb57beb39e9cc666f2008f10ca936cf7c63f6f05 Mon Sep 17 00:00:00 2001 From: xh Date: Thu, 15 Oct 2020 11:56:09 +0200 Subject: [PATCH 11/23] make it possible to use multiple options and output files and make options set in the transcoder object available in general --- ffmpeg/ffmpeg.go | 55 +++++++++++++++++++++++++++++++++++++++--------- transcoder.go | 1 + 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index 14fc2e8..3ff0487 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -21,8 +21,8 @@ import ( type Transcoder struct { config *Config input string - output string - options []string + output []string + options [][]string metadata *Metadata inputPipeReader *io.ReadCloser outputPipeReader *io.ReadCloser @@ -55,11 +55,31 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, return nil, err } - // Get executable flags + // Append input file and standard options args := append([]string{"-i", t.input}, opts.GetStrArguments()...) + outputLength := len(t.output) + optionsLength := len(t.options) - // Append output flag - args = append(args, []string{t.output}...) + if outputLength == 1 && optionsLength == 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 < optionsLength { + for i := index; i < len(t.options); i++ { + args = append(args, t.options[i]...) + } + // Otherwise just append the current options + } else { + args = append(args, t.options[index]...) + } + + // Append output flag + args = append(args, out) + } + } // Initialize command cmd := exec.Command(t.config.FfmpegBinPath, args...) @@ -106,7 +126,7 @@ func (t *Transcoder) Input(arg string) transcoder.Transcoder { // Output ... func (t *Transcoder) Output(arg string) transcoder.Transcoder { - t.output = arg + t.output = append(t.output, arg) return t } @@ -128,14 +148,15 @@ func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder. return t } -// WithOptions ... +// WithOptions Sets the options object func (t *Transcoder) WithOptions(opts transcoder.Options) transcoder.Transcoder { - t.options = opts.GetStrArguments() + t.options = [][]string{opts.GetStrArguments()} return t } +// WithAdditionalOptions Appends an additional options object func (t *Transcoder) WithAdditionalOptions(opts transcoder.Options) transcoder.Transcoder { - t.options = append(t.options, opts.GetStrArguments()...) + t.options = append(t.options, opts.GetStrArguments()) return t } @@ -149,10 +170,24 @@ 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.options) && outputLength != 1 { + return errors.New("number of options and output files does not match") + } + + for index, output := range t.output { + if output == "" { + return errors.New(fmt.Sprintf("output at index %d is an empty string", index)) + } + } + return nil } diff --git a/transcoder.go b/transcoder.go index a4da0b6..012055c 100644 --- a/transcoder.go +++ b/transcoder.go @@ -10,4 +10,5 @@ type Transcoder interface { Output(o string) Transcoder OutputPipe(w *io.WriteCloser, r *io.ReadCloser) Transcoder WithOptions(opts Options) Transcoder + WithAdditionalOptions(opts Options) Transcoder } From 10c7d3155d72f80992e34b4abd339798b0ec8465 Mon Sep 17 00:00:00 2001 From: xh Date: Thu, 15 Oct 2020 14:31:00 +0200 Subject: [PATCH 12/23] replace error.New(fmt.Sprintf) with fmt.Errorf --- ffmpeg/ffmpeg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index 3ff0487..9ac83ab 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -184,7 +184,7 @@ func (t *Transcoder) validate() error { for index, output := range t.output { if output == "" { - return errors.New(fmt.Sprintf("output at index %d is an empty string", index)) + return fmt.Errorf("output at index %d is an empty string", index) } } From eec0343fc7a1da5c5b89056ca940df6e02f19f9b Mon Sep 17 00:00:00 2001 From: xh Date: Fri, 16 Oct 2020 17:47:26 +0200 Subject: [PATCH 13/23] Moves metadata types into own files, implements getters for all fields, adds interfaces and exports Transcoder.GetMetadata --- ffmpeg/ffmpeg.go | 10 +- ffmpeg/metadata.go | 338 +++++++++++++++++++++++++++++++++++++++++++++ ffmpeg/options.go | 74 +--------- metadata.go | 68 +++++++++ transcoder.go | 5 +- 5 files changed, 417 insertions(+), 78 deletions(-) create mode 100644 ffmpeg/metadata.go create mode 100644 metadata.go diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index 013bc6a..585be0b 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -23,7 +23,7 @@ type Transcoder struct { input string output string options []string - metadata *Metadata + metadata transcoder.Metadata inputPipeReader *io.ReadCloser outputPipeReader *io.ReadCloser inputPipeWriter *io.WriteCloser @@ -50,7 +50,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, } // Get file metadata - _, err := t.getMetadata() + _, err := t.GetMetadata() if err != nil { return nil, err } @@ -151,7 +151,7 @@ func (t *Transcoder) validate() error { return nil } -func (t *Transcoder) getMetadata() (metadata *Metadata, err error) { +func (t *Transcoder) GetMetadata() ( transcoder.Metadata, error) { if t.config.FfprobeBinPath != "" { var outb, errb bytes.Buffer @@ -173,6 +173,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 } @@ -256,7 +258,7 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.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..5dc2e82 --- /dev/null +++ b/ffmpeg/metadata.go @@ -0,0 +1,338 @@ +package ffmpeg + +import "github.com/Borloxos/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 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"` +} + +// 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 d046758..927cebe 100644 --- a/ffmpeg/options.go +++ b/ffmpeg/options.go @@ -107,76 +107,4 @@ func (opts Options) GetStrArguments() []string { } 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"` -} +} \ No newline at end of file diff --git a/metadata.go b/metadata.go new file mode 100644 index 0000000..702d77c --- /dev/null +++ b/metadata.go @@ -0,0 +1,68 @@ +package transcoder + +type Metadata interface { + GetFormat() Format + GetStreams() []Streams +} + +type Format interface { + GetFilename() string + GetNbStreams() int + GetNbPrograms() int + GetFormatName() string + GetFormatLongName() string + GetDuration() string + GetSize() string + GetBitRate() string + GetProbeScore() int + GetTags() Tags +} + +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 +} + +type Tags interface { + GetEncoder() string +} + +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/transcoder.go b/transcoder.go index a4da0b6..e8e260f 100644 --- a/transcoder.go +++ b/transcoder.go @@ -1,6 +1,8 @@ package transcoder -import "io" +import ( + "io" +) // Transcoder ... type Transcoder interface { @@ -10,4 +12,5 @@ type Transcoder interface { Output(o string) Transcoder OutputPipe(w *io.WriteCloser, r *io.ReadCloser) Transcoder WithOptions(opts Options) Transcoder + GetMetadata() (Metadata, error) } From f6adee65c98381d163706d9bdbb1bc74092d1126 Mon Sep 17 00:00:00 2001 From: sidney Date: Mon, 26 Oct 2020 16:58:36 +0800 Subject: [PATCH 14/23] fix int type parameters invalid --- ffmpeg/options.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ffmpeg/options.go b/ffmpeg/options.go index d046758..5e56b71 100644 --- a/ffmpeg/options.go +++ b/ffmpeg/options.go @@ -102,6 +102,10 @@ func (opts Options) GetStrArguments() []string { values = append(values, flag, fmt.Sprintf("%v:%v", k, v)) } } + + if vi, ok := value.(*int); ok { + values = append(values, flag, fmt.Sprintf("%d", *vi)) + } } } From 0e169502a9aa6be9c2e0834466bf68732dc27953 Mon Sep 17 00:00:00 2001 From: xh Date: Mon, 26 Oct 2020 11:38:26 +0100 Subject: [PATCH 15/23] fix comments --- ffmpeg/ffmpeg.go | 1 + ffmpeg/metadata.go | 82 +++++++++++++++++++++++----------------------- metadata.go | 5 +++ 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index 585be0b..51097b0 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -151,6 +151,7 @@ func (t *Transcoder) validate() error { return nil } +// GetMetadata Returns metadata for the specified input file func (t *Transcoder) GetMetadata() ( transcoder.Metadata, error) { if t.config.FfprobeBinPath != "" { diff --git a/ffmpeg/metadata.go b/ffmpeg/metadata.go index 5dc2e82..e291132 100644 --- a/ffmpeg/metadata.go +++ b/ffmpeg/metadata.go @@ -22,7 +22,7 @@ type Format struct { Tags Tags `json:"tags"` } -// Streams defines allowed stream options +// Streams ... type Streams struct { Index int ID string `json:"id"` @@ -137,202 +137,202 @@ func (f Format) GetTags() transcoder.Tags { return f.Tags } -// GetEncoder +// GetEncoder ... func (t Tags) GetEncoder() string { return t.Encoder } -//GetIndex +//GetIndex ... func (s Streams) GetIndex() int { return s.Index } -//GetID +//GetID ... func (s Streams) GetID() string { return s.ID } -//GetCodecName +//GetCodecName ... func (s Streams) GetCodecName() string { return s.CodecName } -//GetCodecLongName +//GetCodecLongName ... func (s Streams) GetCodecLongName() string { return s.CodecLongName } -//GetProfile +//GetProfile ... func (s Streams) GetProfile() string { return s.Profile } -//GetCodecType +//GetCodecType ... func (s Streams) GetCodecType() string { return s.CodecType } -//GetCodecTimeBase +//GetCodecTimeBase ... func (s Streams) GetCodecTimeBase() string { return s.CodecTimeBase } -//GetCodecTagString +//GetCodecTagString ... func (s Streams) GetCodecTagString() string { return s.CodecTagString } -//GetCodecTag +//GetCodecTag ... func (s Streams) GetCodecTag() string { return s.CodecTag } -//GetWidth +//GetWidth ... func (s Streams) GetWidth() int { return s.Width } -//GetHeight +//GetHeight ... func (s Streams) GetHeight() int { return s.Height } -//GetCodedWidth +//GetCodedWidth ... func (s Streams) GetCodedWidth() int { return s.CodedWidth } -//GetCodedHeight +//GetCodedHeight ... func (s Streams) GetCodedHeight() int { return s.CodedHeight } -//GetHasBFrames +//GetHasBFrames ... func (s Streams) GetHasBFrames() int { return s.HasBFrames } -//GetSampleAspectRatio +//GetSampleAspectRatio ... func (s Streams) GetSampleAspectRatio() string { return s.SampleAspectRatio } -//GetDisplayAspectRatio +//GetDisplayAspectRatio ... func (s Streams) GetDisplayAspectRatio() string { return s.DisplayAspectRatio } -//GetPixFmt +//GetPixFmt ... func (s Streams) GetPixFmt() string { return s.PixFmt } -//GetLevel +//GetLevel ... func (s Streams) GetLevel() int { return s.Level } -//GetChromaLocation +//GetChromaLocation ... func (s Streams) GetChromaLocation() string { return s.ChromaLocation } -//GetRefs +//GetRefs ... func (s Streams) GetRefs() int { return s.Refs } -//GetQuarterSample +//GetQuarterSample ... func (s Streams) GetQuarterSample() string { return s.QuarterSample } -//GetDivxPacked +//GetDivxPacked ... func (s Streams) GetDivxPacked() string { return s.DivxPacked } -//GetRFrameRrate +//GetRFrameRrate ... func (s Streams) GetRFrameRrate() string { return s.RFrameRrate } -//GetAvgFrameRate +//GetAvgFrameRate ... func (s Streams) GetAvgFrameRate() string { return s.AvgFrameRate } -//GetTimeBase +//GetTimeBase ... func (s Streams) GetTimeBase() string { return s.TimeBase } -//GetDurationTs +//GetDurationTs ... func (s Streams) GetDurationTs() int { return s.DurationTs } -//GetDuration +//GetDuration ... func (s Streams) GetDuration() string { return s.Duration } -//GetDisposition +//GetDisposition ... func (s Streams) GetDisposition() transcoder.Disposition { return s.Disposition } -//GetBitRate +//GetBitRate ... func (s Streams) GetBitRate() string { return s.BitRate } -//GetDefault +//GetDefault ... func (d Disposition) GetDefault() int { return d.Default } -//GetDub +//GetDub ... func (d Disposition) GetDub() int { return d.Dub } -//GetOriginal +//GetOriginal ... func (d Disposition) GetOriginal() int { return d.Original } -//GetComment +//GetComment ... func (d Disposition) GetComment() int { return d.Comment } -//GetLyrics +//GetLyrics ... func (d Disposition) GetLyrics() int { return d.Lyrics } -//GetKaraoke +//GetKaraoke ... func (d Disposition) GetKaraoke() int { return d.Karaoke } -//GetForced +//GetForced ... func (d Disposition) GetForced() int { return d.Forced } -//GetHearingImpaired +//GetHearingImpaired ... func (d Disposition) GetHearingImpaired() int { return d.HearingImpaired } -//GetVisualImpaired +//GetVisualImpaired ... func (d Disposition) GetVisualImpaired() int { return d.VisualImpaired } -//GetCleanEffects +//GetCleanEffects ... func (d Disposition) GetCleanEffects() int { return d.CleanEffects } diff --git a/metadata.go b/metadata.go index 702d77c..d03241d 100644 --- a/metadata.go +++ b/metadata.go @@ -1,10 +1,12 @@ package transcoder +// Metadata ... type Metadata interface { GetFormat() Format GetStreams() []Streams } +// Format ... type Format interface { GetFilename() string GetNbStreams() int @@ -18,6 +20,7 @@ type Format interface { GetTags() Tags } +// Streams ... type Streams interface { GetIndex() int GetID() string @@ -50,10 +53,12 @@ type Streams interface { GetBitRate() string } +// Tags ... type Tags interface { GetEncoder() string } +// Disposition ... type Disposition interface { GetDefault() int GetDub() int From f79eea11a8b6d30d36f7e53f73f0a69002b917fd Mon Sep 17 00:00:00 2001 From: xh Date: Fri, 30 Oct 2020 12:07:05 +0100 Subject: [PATCH 16/23] Make Progress readable --- ffmpeg/progress.go | 25 +++++++++++++++++++++++++ progress.go | 5 +++++ 2 files changed, 30 insertions(+) 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/progress.go b/progress.go index 5a65dd2..4b7b060 100644 --- a/progress.go +++ b/progress.go @@ -2,4 +2,9 @@ package transcoder // Progress ... type Progress interface { + GetFramesProcessed() string + GetCurrentTime() string + GetCurrentBitrate() string + GetProgress() float64 + GetSpeed() string } From 99250dc3134a322c5b1dae467494a82b4dea8de2 Mon Sep 17 00:00:00 2001 From: Fran <35836929+xfrr@users.noreply.github.com> Date: Tue, 3 Nov 2020 17:56:52 +0100 Subject: [PATCH 17/23] Update metadata.go Fixed references --- ffmpeg/metadata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/metadata.go b/ffmpeg/metadata.go index e291132..bb1149f 100644 --- a/ffmpeg/metadata.go +++ b/ffmpeg/metadata.go @@ -1,6 +1,6 @@ package ffmpeg -import "github.com/Borloxos/transcoder" +import "github.com/flooostack/transcoder" // Metadata ... type Metadata struct { From aa6374b9ec87c4d1fc190dfd64c74d322dc1e605 Mon Sep 17 00:00:00 2001 From: Fran <35836929+xfrr@users.noreply.github.com> Date: Tue, 3 Nov 2020 17:58:26 +0100 Subject: [PATCH 18/23] Update metadata.go Fixed references --- ffmpeg/metadata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/metadata.go b/ffmpeg/metadata.go index bb1149f..4e81910 100644 --- a/ffmpeg/metadata.go +++ b/ffmpeg/metadata.go @@ -1,6 +1,6 @@ package ffmpeg -import "github.com/flooostack/transcoder" +import "github.com/floostack/transcoder" // Metadata ... type Metadata struct { From e61a87438e16bb709e7da2f4f21ffc59c218f6e5 Mon Sep 17 00:00:00 2001 From: Viktor Menchikov Date: Tue, 29 Dec 2020 13:22:49 +0500 Subject: [PATCH 19/23] Fiexd ExtraArgs feature map[string]string is replaced by map[string]interface{}. The map key is used as a flag. --- ffmpeg/options.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ffmpeg/options.go b/ffmpeg/options.go index 43918bb..323d4b3 100644 --- a/ffmpeg/options.go +++ b/ffmpeg/options.go @@ -97,9 +97,9 @@ 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)) } } @@ -111,4 +111,4 @@ func (opts Options) GetStrArguments() []string { } return values -} \ No newline at end of file +} From d1fa30ce4185cfc78de69b87b32ad4581e464b67 Mon Sep 17 00:00:00 2001 From: Ali Irani Date: Wed, 5 May 2021 20:14:15 +0430 Subject: [PATCH 20/23] fix bug for working progress with audio files audio files doesn't have frame in output --- ffmpeg/ffmpeg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index ea84fbc..d67b2e9 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -262,7 +262,7 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.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, `=`) From 4b93d4d9f576a5820e8bc0e734f046a69412573f Mon Sep 17 00:00:00 2001 From: Harry Felton Date: Wed, 7 Jul 2021 16:45:58 +1200 Subject: [PATCH 21/23] feat(context): added WithContext method for Transcoder --- ffmpeg/ffmpeg.go | 22 ++++++++++++++++++++-- transcoder.go | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index d67b2e9..ce262f8 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -3,6 +3,7 @@ package ffmpeg import ( "bufio" "bytes" + "context" "encoding/json" "errors" "fmt" @@ -28,6 +29,7 @@ type Transcoder struct { outputPipeReader *io.ReadCloser inputPipeWriter *io.WriteCloser outputPipeWriter *io.WriteCloser + commandContext *context.Context } // New ... @@ -82,7 +84,15 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, } // Initialize command - cmd := exec.Command(t.config.FfmpegBinPath, args...) + // 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 { @@ -160,6 +170,14 @@ func (t *Transcoder) WithAdditionalOptions(opts transcoder.Options) transcoder.T 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 +} + // validate ... func (t *Transcoder) validate() error { if t.config.FfmpegBinPath == "" { @@ -192,7 +210,7 @@ func (t *Transcoder) validate() error { } // GetMetadata Returns metadata for the specified input file -func (t *Transcoder) GetMetadata() ( transcoder.Metadata, error) { +func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) { if t.config.FfprobeBinPath != "" { var outb, errb bytes.Buffer diff --git a/transcoder.go b/transcoder.go index 9e58206..c93bc4a 100644 --- a/transcoder.go +++ b/transcoder.go @@ -1,6 +1,7 @@ package transcoder import ( + "context" "io" ) @@ -13,5 +14,6 @@ type Transcoder interface { OutputPipe(w *io.WriteCloser, r *io.ReadCloser) Transcoder WithOptions(opts Options) Transcoder WithAdditionalOptions(opts Options) Transcoder + WithContext(ctx *context.Context) Transcoder GetMetadata() (Metadata, error) } From d91fbf5bec10b4fc0a6a6037fd55bbe056b534cf Mon Sep 17 00:00:00 2001 From: r6c <45527749+r6c@users.noreply.github.com> Date: Tue, 1 Mar 2022 16:38:02 +0800 Subject: [PATCH 22/23] support input options (#32) --- README.md | 16 ++++++++++++--- ffmpeg/ffmpeg.go | 51 +++++++++++++++++++++++++++++++++--------------- transcoder.go | 8 +++++--- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 651b613..967d5b9 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,19 @@ import ( 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, } @@ -68,8 +77,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/ffmpeg/ffmpeg.go b/ffmpeg/ffmpeg.go index ce262f8..6328104 100644 --- a/ffmpeg/ffmpeg.go +++ b/ffmpeg/ffmpeg.go @@ -23,7 +23,8 @@ type Transcoder struct { config *Config input string output []string - options [][]string + inputOptions []string + outputOptions [][]string metadata transcoder.Metadata inputPipeReader *io.ReadCloser outputPipeReader *io.ReadCloser @@ -38,7 +39,7 @@ func New(cfg *Config) transcoder.Transcoder { } // Start ... -func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, error) { +func (t *Transcoder) Start() (<-chan transcoder.Progress, error) { var stderrIn io.ReadCloser @@ -58,24 +59,30 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, } // Append input file and standard options - args := append([]string{"-i", t.input}, opts.GetStrArguments()...) + var args []string + + if len(t.inputOptions) > 0 { + args = append(args, t.inputOptions...) + } + + args = append(args, []string{"-i", t.input}...) outputLength := len(t.output) - optionsLength := len(t.options) + outputOptionsLength := len(t.outputOptions) - if outputLength == 1 && optionsLength == 0 { + 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 < optionsLength { - for i := index; i < len(t.options); i++ { - args = append(args, t.options[i]...) + 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.options[index]...) + args = append(args, t.outputOptions[index]...) } // Append output flag @@ -158,15 +165,27 @@ func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder. return t } -// WithOptions Sets the options object -func (t *Transcoder) WithOptions(opts transcoder.Options) transcoder.Transcoder { - t.options = [][]string{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 } -// WithAdditionalOptions Appends an additional options object -func (t *Transcoder) WithAdditionalOptions(opts transcoder.Options) transcoder.Transcoder { - t.options = append(t.options, opts.GetStrArguments()) +// WithAdditionalOutputOptions Appends an additional options object +func (t *Transcoder) WithAdditionalOutputOptions(opts transcoder.Options) transcoder.Transcoder { + t.outputOptions = append(t.outputOptions, opts.GetStrArguments()) return t } @@ -196,7 +215,7 @@ func (t *Transcoder) validate() error { // 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.options) && outputLength != 1 { + if outputLength > len(t.outputOptions) && outputLength != 1 { return errors.New("number of options and output files does not match") } diff --git a/transcoder.go b/transcoder.go index c93bc4a..f53ca4e 100644 --- a/transcoder.go +++ b/transcoder.go @@ -7,13 +7,15 @@ import ( // 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 - WithAdditionalOptions(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) } From 715a99488353b557b7fff6c29c770f7aa9ff2be0 Mon Sep 17 00:00:00 2001 From: Fran <35836929+xfrr@users.noreply.github.com> Date: Fri, 29 Sep 2023 18:45:20 +0200 Subject: [PATCH 23/23] Update README.md --- README.md | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/README.md b/README.md index 967d5b9..570791b 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,6 @@ # Golang Transcoding Library -
- -
- - - Build Status - - - - - Build Status - - -
- -
- -
- Created by FlooStack. -
+> This repository is no longer maintained. Please use [Goffmpeg](https://github.com/xfrr/goffmpeg). ## Features