Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit cf02060

Browse files
committed
v0.1
1 parent f704851 commit cf02060

File tree

9 files changed

+57
-77
lines changed

9 files changed

+57
-77
lines changed

README.md

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
1-
# Golang Transcoding Library
2-
3-
<br />
4-
5-
<div align="center">
6-
<!-- Build status -->
7-
<a href="https://circleci.com/gh/floostack/transcoder">
8-
<img src="https://circleci.com/gh/floostack/transcoder.svg?style=svg" alt="Build Status" />
9-
</a>
10-
11-
<!-- Code Quality -->
12-
<a href="https://www.codacy.com/manual/floostack/transcoder?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=floostack/transcoder&amp;utm_campaign=Badge_Grade">
13-
<img src="https://app.codacy.com/project/badge/Grade/f8ee19ef723b4134bb8bb1f9c439959e" alt="Build Status" />
14-
</a>
15-
16-
</div>
17-
18-
<br />
19-
20-
<div align="center">
21-
<sub>Created by <a href="https://floostack.com">FlooStack</a>.</sub>
22-
</div>
1+
# Transcoder plus
232

243
## Features
254

265
<dl>
276
<dt>Ease use</dt>
287
<dd>Implement your own business logic around easy interfaces</dd>
29-
308
<dt>Transcoding progress</dt>
319
<dd>Obtain progress events generated by transcoding application process</dd>
3210
</dl>
3311

34-
## Download from Github
12+
## Download from GitLab
3513

3614
```shell
37-
go get github.com/floostack/transcoder
15+
go get -u http://gitlab.yiban.io/we-work-go-team/transcoder-plus
3816
```
3917

4018
## Example
@@ -45,31 +23,41 @@ package main
4523
import (
4624
"log"
4725

48-
ffmpeg "github.com/floostack/transcoder/ffmpeg"
26+
"transcoderplus/ffmpeg"
4927
)
5028

5129
func main() {
52-
53-
format := "mp4"
30+
31+
inputformat := "mulaw"
32+
filtercomplex := "amix=inputs=2"
33+
audiorate := 8000
34+
outputformat := "mp3"
5435
overwrite := true
5536

56-
opts := ffmpeg.Options{
57-
OutputFormat: &format,
58-
Overwrite: &overwrite,
37+
outputopts := ffmpeg.Options{
38+
OutputFormat: &outputformat,
39+
Overwrite: &overwrite,
40+
FilterComplex: &filtercomplex,
41+
}
42+
43+
inputopts := ffmpeg.Options{
44+
OutputFormat: &inputformat,
45+
AudioRate: &audiorate,
5946
}
6047

6148
ffmpegConf := &ffmpeg.Config{
62-
FfmpegBinPath: "/usr/local/bin/ffmpeg",
63-
FfprobeBinPath: "/usr/local/bin/ffprobe",
49+
FfmpegBinPath: "ffmpegPath",
50+
FfprobeBinPath: "ffprobePath",
6451
ProgressEnabled: true,
6552
}
6653

6754
progress, err := ffmpeg.
6855
New(ffmpegConf).
69-
Input("/tmp/avi").
70-
Output("/tmp/mp4").
71-
WithOptions(opts).
72-
Start(opts)
56+
Input("inputfile1Path").
57+
Input("inputfile2Path").
58+
Output("outputfile1Path").
59+
WithOptions(outputopts).
60+
Start(inputopts)
7361

7462
if err != nil {
7563
log.Fatal(err)
@@ -79,4 +67,5 @@ func main() {
7967
log.Printf("%+v", msg)
8068
}
8169
}
70+
8271
```

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transcoder
1+
package transcoderplus
22

33
// Config ...
44
type Config interface{}

ffmpeg/ffmpeg.go

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"strconv"
1414
"strings"
1515

16-
"transcoder"
17-
"transcoder/utils"
16+
"transcoderplus"
17+
"transcoderplus/utils"
1818
)
1919

2020
// Transcoder ...
@@ -23,25 +23,25 @@ type Transcoder struct {
2323
input []string
2424
output []string
2525
options [][]string
26-
metadata transcoder.Metadata
26+
metadata transcoderplus.Metadata
2727
inputPipeReader *io.ReadCloser
2828
outputPipeReader *io.ReadCloser
2929
inputPipeWriter *io.WriteCloser
3030
outputPipeWriter *io.WriteCloser
3131
}
3232

3333
// New ...
34-
func New(cfg *Config) transcoder.Transcoder {
34+
func New(cfg *Config) transcoderplus.Transcoder {
3535
return &Transcoder{config: cfg}
3636
}
3737

3838
// Start ...
39-
func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, error) {
39+
func (t *Transcoder) Start(opts transcoderplus.Options) (<-chan transcoderplus.Progress, error) {
4040

4141
var stderrIn io.ReadCloser
4242
var err error
4343

44-
out := make(chan transcoder.Progress)
44+
out := make(chan transcoderplus.Progress)
4545

4646
defer t.closePipes()
4747

@@ -50,8 +50,9 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
5050
return nil, err
5151
}
5252

53+
// 不能使用,因为ffprobe不支持mulaw格式的识别
5354
//Get file metadata
54-
//_, err := t.GetMetadata()
55+
//_, err = t.GetMetadata()
5556
//if err != nil {
5657
// return nil, err
5758
//}
@@ -126,28 +127,19 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
126127
}
127128

128129
// Input ...
129-
func (t *Transcoder) Input(arg string) transcoder.Transcoder {
130-
//args := make([]string, 0)
131-
//optionsLength := len(t.options)
132-
//if optionsLength != 0 {
133-
// args = append(args, t.options[0]...)
134-
// t.options = t.options[1:]
135-
//}
136-
//args = append(args, "-i")
137-
//args = append(args, arg)
138-
//arg = strings.Join(args, " ")
130+
func (t *Transcoder) Input(arg string) transcoderplus.Transcoder {
139131
t.input = append(t.input, arg)
140132
return t
141133
}
142134

143135
// Output ...
144-
func (t *Transcoder) Output(arg string) transcoder.Transcoder {
136+
func (t *Transcoder) Output(arg string) transcoderplus.Transcoder {
145137
t.output = append(t.output, arg)
146138
return t
147139
}
148140

149141
// InputPipe ...
150-
func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.Transcoder {
142+
func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoderplus.Transcoder {
151143
if &t.input == nil {
152144
t.inputPipeWriter = w
153145
t.inputPipeReader = r
@@ -156,7 +148,7 @@ func (t *Transcoder) InputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.T
156148
}
157149

158150
// OutputPipe ...
159-
func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.Transcoder {
151+
func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoderplus.Transcoder {
160152
if &t.output == nil {
161153
t.outputPipeWriter = w
162154
t.outputPipeReader = r
@@ -165,13 +157,13 @@ func (t *Transcoder) OutputPipe(w *io.WriteCloser, r *io.ReadCloser) transcoder.
165157
}
166158

167159
// WithOptions Sets the options object
168-
func (t *Transcoder) WithOptions(opts transcoder.Options) transcoder.Transcoder {
160+
func (t *Transcoder) WithOptions(opts transcoderplus.Options) transcoderplus.Transcoder {
169161
t.options = [][]string{opts.GetStrArguments()}
170162
return t
171163
}
172164

173165
// WithAdditionalOptions Appends an additional options object
174-
func (t *Transcoder) WithAdditionalOptions(opts transcoder.Options) transcoder.Transcoder {
166+
func (t *Transcoder) WithAdditionalOptions(opts transcoderplus.Options) transcoderplus.Transcoder {
175167
t.options = append(t.options, opts.GetStrArguments())
176168
return t
177169
}
@@ -208,14 +200,15 @@ func (t *Transcoder) validate() error {
208200
}
209201

210202
// GetMetadata Returns metadata for the specified input file
211-
func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
203+
func (t *Transcoder) GetMetadata() (transcoderplus.Metadata, error) {
212204

213205
if t.config.FfprobeBinPath != "" {
214-
var outb, errb bytes.Buffer
215-
var metadata []Metadata
206+
//var metadata []Metadata
216207
var metapice Metadata
217208

218-
for _, input := range t.input {
209+
input := t.input[0]
210+
211+
var outb, errb bytes.Buffer
219212

220213
if t.inputPipeReader != nil {
221214
input = "pipe:"
@@ -235,8 +228,6 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
235228
}
236229

237230
t.metadata = metapice
238-
metadata = append(metadata, metapice)
239-
}
240231

241232
return metapice, nil
242233
}
@@ -245,7 +236,7 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
245236
}
246237

247238
// progress sends through given channel the transcoding status
248-
func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress) {
239+
func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoderplus.Progress) {
249240

250241
defer stream.Close()
251242

ffmpeg/metadata.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ffmpeg
22

3-
import "transcoder"
3+
import "transcoderplus"
44

55
// Metadata ...
66
type Metadata struct {
@@ -75,12 +75,12 @@ type Disposition struct {
7575
}
7676

7777
// GetFormat ...
78-
func (m Metadata) GetFormat() transcoder.Format {
78+
func (m Metadata) GetFormat() transcoderplus.Format {
7979
return m.Format
8080
}
8181

8282
// GetStreams ...
83-
func (m Metadata) GetStreams() (streams []transcoder.Streams) {
83+
func (m Metadata) GetStreams() (streams []transcoderplus.Streams) {
8484
for _, element := range m.Streams {
8585
streams = append(streams, element)
8686
}
@@ -133,7 +133,7 @@ func (f Format) GetProbeScore() int {
133133
}
134134

135135
// GetTags ...
136-
func (f Format) GetTags() transcoder.Tags {
136+
func (f Format) GetTags() transcoderplus.Tags {
137137
return f.Tags
138138
}
139139

@@ -278,7 +278,7 @@ func (s Streams) GetDuration() string {
278278
}
279279

280280
//GetDisposition ...
281-
func (s Streams) GetDisposition() transcoder.Disposition {
281+
func (s Streams) GetDisposition() transcoderplus.Disposition {
282282
return s.Disposition
283283
}
284284

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module transcoder
1+
module transcoderplus
22

33
go 1.13

metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transcoder
1+
package transcoderplus
22

33
// Metadata ...
44
type Metadata interface {

options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transcoder
1+
package transcoderplus
22

33
// Options ...
44
type Options interface {

progress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transcoder
1+
package transcoderplus
22

33
// Progress ...
44
type Progress interface {

transcoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transcoder
1+
package transcoderplus
22

33
import (
44
"io"

0 commit comments

Comments
 (0)