From e61a87438e16bb709e7da2f4f21ffc59c218f6e5 Mon Sep 17 00:00:00 2001 From: Viktor Menchikov Date: Tue, 29 Dec 2020 13:22:49 +0500 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy