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

Commit 25708ec

Browse files
authored
Merge branch 'master' into multipleOptionsAndOutputs
2 parents 10c7d31 + 2c44ff9 commit 25708ec

File tree

7 files changed

+457
-78
lines changed

7 files changed

+457
-78
lines changed

ffmpeg/ffmpeg.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Transcoder struct {
2323
input string
2424
output []string
2525
options [][]string
26-
metadata *Metadata
26+
metadata transcoder.Metadata
2727
inputPipeReader *io.ReadCloser
2828
outputPipeReader *io.ReadCloser
2929
inputPipeWriter *io.WriteCloser
@@ -50,7 +50,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
5050
}
5151

5252
// Get file metadata
53-
_, err := t.getMetadata()
53+
_, err := t.GetMetadata()
5454
if err != nil {
5555
return nil, err
5656
}
@@ -191,7 +191,8 @@ func (t *Transcoder) validate() error {
191191
return nil
192192
}
193193

194-
func (t *Transcoder) getMetadata() (metadata *Metadata, err error) {
194+
// GetMetadata Returns metadata for the specified input file
195+
func (t *Transcoder) GetMetadata() ( transcoder.Metadata, error) {
195196

196197
if t.config.FfprobeBinPath != "" {
197198
var outb, errb bytes.Buffer
@@ -213,6 +214,8 @@ func (t *Transcoder) getMetadata() (metadata *Metadata, err error) {
213214
return nil, fmt.Errorf("error executing (%s) with args (%s) | error: %s | message: %s %s", t.config.FfprobeBinPath, args, err, outb.String(), errb.String())
214215
}
215216

217+
var metadata Metadata
218+
216219
if err = json.Unmarshal([]byte(outb.String()), &metadata); err != nil {
217220
return nil, err
218221
}
@@ -296,7 +299,7 @@ func (t *Transcoder) progress(stream io.ReadCloser, out chan transcoder.Progress
296299
}
297300

298301
timesec := utils.DurToSec(currentTime)
299-
dursec, _ := strconv.ParseFloat(t.metadata.Format.Duration, 64)
302+
dursec, _ := strconv.ParseFloat(t.metadata.GetFormat().GetDuration(), 64)
300303

301304
progress := (timesec * 100) / dursec
302305
Progress.Progress = progress

ffmpeg/metadata.go

Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
package ffmpeg
2+
3+
import "github.com/Borloxos/transcoder"
4+
5+
// Metadata ...
6+
type Metadata struct {
7+
Format Format `json:"format"`
8+
Streams []Streams `json:"streams"`
9+
}
10+
11+
// Format ...
12+
type Format struct {
13+
Filename string
14+
NbStreams int `json:"nb_streams"`
15+
NbPrograms int `json:"nb_programs"`
16+
FormatName string `json:"format_name"`
17+
FormatLongName string `json:"format_long_name"`
18+
Duration string `json:"duration"`
19+
Size string `json:"size"`
20+
BitRate string `json:"bit_rate"`
21+
ProbeScore int `json:"probe_score"`
22+
Tags Tags `json:"tags"`
23+
}
24+
25+
// Streams ...
26+
type Streams struct {
27+
Index int
28+
ID string `json:"id"`
29+
CodecName string `json:"codec_name"`
30+
CodecLongName string `json:"codec_long_name"`
31+
Profile string `json:"profile"`
32+
CodecType string `json:"codec_type"`
33+
CodecTimeBase string `json:"codec_time_base"`
34+
CodecTagString string `json:"codec_tag_string"`
35+
CodecTag string `json:"codec_tag"`
36+
Width int `json:"width"`
37+
Height int `json:"height"`
38+
CodedWidth int `json:"coded_width"`
39+
CodedHeight int `json:"coded_height"`
40+
HasBFrames int `json:"has_b_frames"`
41+
SampleAspectRatio string `json:"sample_aspect_ratio"`
42+
DisplayAspectRatio string `json:"display_aspect_ratio"`
43+
PixFmt string `json:"pix_fmt"`
44+
Level int `json:"level"`
45+
ChromaLocation string `json:"chroma_location"`
46+
Refs int `json:"refs"`
47+
QuarterSample string `json:"quarter_sample"`
48+
DivxPacked string `json:"divx_packed"`
49+
RFrameRrate string `json:"r_frame_rate"`
50+
AvgFrameRate string `json:"avg_frame_rate"`
51+
TimeBase string `json:"time_base"`
52+
DurationTs int `json:"duration_ts"`
53+
Duration string `json:"duration"`
54+
Disposition Disposition `json:"disposition"`
55+
BitRate string `json:"bit_rate"`
56+
}
57+
58+
// Tags ...
59+
type Tags struct {
60+
Encoder string `json:"ENCODER"`
61+
}
62+
63+
// Disposition ...
64+
type Disposition struct {
65+
Default int `json:"default"`
66+
Dub int `json:"dub"`
67+
Original int `json:"original"`
68+
Comment int `json:"comment"`
69+
Lyrics int `json:"lyrics"`
70+
Karaoke int `json:"karaoke"`
71+
Forced int `json:"forced"`
72+
HearingImpaired int `json:"hearing_impaired"`
73+
VisualImpaired int `json:"visual_impaired"`
74+
CleanEffects int `json:"clean_effects"`
75+
}
76+
77+
// GetFormat ...
78+
func (m Metadata) GetFormat() transcoder.Format {
79+
return m.Format
80+
}
81+
82+
// GetStreams ...
83+
func (m Metadata) GetStreams() (streams []transcoder.Streams) {
84+
for _, element := range m.Streams {
85+
streams = append(streams, element)
86+
}
87+
return streams
88+
}
89+
90+
// GetFilename ...
91+
func (f Format) GetFilename() string {
92+
return f.Filename
93+
}
94+
95+
// GetNbStreams ...
96+
func (f Format) GetNbStreams() int {
97+
return f.NbStreams
98+
}
99+
100+
// GetNbPrograms ...
101+
func (f Format) GetNbPrograms() int {
102+
return f.NbPrograms
103+
}
104+
105+
// GetFormatName ...
106+
func (f Format) GetFormatName() string {
107+
return f.FormatName
108+
}
109+
110+
// GetFormatLongName ...
111+
func (f Format) GetFormatLongName() string {
112+
return f.FormatLongName
113+
}
114+
115+
// GetDuration ...
116+
func (f Format) GetDuration() string {
117+
return f.Duration
118+
}
119+
120+
// GetSize ...
121+
func (f Format) GetSize() string {
122+
return f.Size
123+
}
124+
125+
// GetBitRate ...
126+
func (f Format) GetBitRate() string {
127+
return f.BitRate
128+
}
129+
130+
// GetProbeScore ...
131+
func (f Format) GetProbeScore() int {
132+
return f.ProbeScore
133+
}
134+
135+
// GetTags ...
136+
func (f Format) GetTags() transcoder.Tags {
137+
return f.Tags
138+
}
139+
140+
// GetEncoder ...
141+
func (t Tags) GetEncoder() string {
142+
return t.Encoder
143+
}
144+
145+
//GetIndex ...
146+
func (s Streams) GetIndex() int {
147+
return s.Index
148+
}
149+
150+
//GetID ...
151+
func (s Streams) GetID() string {
152+
return s.ID
153+
}
154+
155+
//GetCodecName ...
156+
func (s Streams) GetCodecName() string {
157+
return s.CodecName
158+
}
159+
160+
//GetCodecLongName ...
161+
func (s Streams) GetCodecLongName() string {
162+
return s.CodecLongName
163+
}
164+
165+
//GetProfile ...
166+
func (s Streams) GetProfile() string {
167+
return s.Profile
168+
}
169+
170+
//GetCodecType ...
171+
func (s Streams) GetCodecType() string {
172+
return s.CodecType
173+
}
174+
175+
//GetCodecTimeBase ...
176+
func (s Streams) GetCodecTimeBase() string {
177+
return s.CodecTimeBase
178+
}
179+
180+
//GetCodecTagString ...
181+
func (s Streams) GetCodecTagString() string {
182+
return s.CodecTagString
183+
}
184+
185+
//GetCodecTag ...
186+
func (s Streams) GetCodecTag() string {
187+
return s.CodecTag
188+
}
189+
190+
//GetWidth ...
191+
func (s Streams) GetWidth() int {
192+
return s.Width
193+
}
194+
195+
//GetHeight ...
196+
func (s Streams) GetHeight() int {
197+
return s.Height
198+
}
199+
200+
//GetCodedWidth ...
201+
func (s Streams) GetCodedWidth() int {
202+
return s.CodedWidth
203+
}
204+
205+
//GetCodedHeight ...
206+
func (s Streams) GetCodedHeight() int {
207+
return s.CodedHeight
208+
}
209+
210+
//GetHasBFrames ...
211+
func (s Streams) GetHasBFrames() int {
212+
return s.HasBFrames
213+
}
214+
215+
//GetSampleAspectRatio ...
216+
func (s Streams) GetSampleAspectRatio() string {
217+
return s.SampleAspectRatio
218+
}
219+
220+
//GetDisplayAspectRatio ...
221+
func (s Streams) GetDisplayAspectRatio() string {
222+
return s.DisplayAspectRatio
223+
}
224+
225+
//GetPixFmt ...
226+
func (s Streams) GetPixFmt() string {
227+
return s.PixFmt
228+
}
229+
230+
//GetLevel ...
231+
func (s Streams) GetLevel() int {
232+
return s.Level
233+
}
234+
235+
//GetChromaLocation ...
236+
func (s Streams) GetChromaLocation() string {
237+
return s.ChromaLocation
238+
}
239+
240+
//GetRefs ...
241+
func (s Streams) GetRefs() int {
242+
return s.Refs
243+
}
244+
245+
//GetQuarterSample ...
246+
func (s Streams) GetQuarterSample() string {
247+
return s.QuarterSample
248+
}
249+
250+
//GetDivxPacked ...
251+
func (s Streams) GetDivxPacked() string {
252+
return s.DivxPacked
253+
}
254+
255+
//GetRFrameRrate ...
256+
func (s Streams) GetRFrameRrate() string {
257+
return s.RFrameRrate
258+
}
259+
260+
//GetAvgFrameRate ...
261+
func (s Streams) GetAvgFrameRate() string {
262+
return s.AvgFrameRate
263+
}
264+
265+
//GetTimeBase ...
266+
func (s Streams) GetTimeBase() string {
267+
return s.TimeBase
268+
}
269+
270+
//GetDurationTs ...
271+
func (s Streams) GetDurationTs() int {
272+
return s.DurationTs
273+
}
274+
275+
//GetDuration ...
276+
func (s Streams) GetDuration() string {
277+
return s.Duration
278+
}
279+
280+
//GetDisposition ...
281+
func (s Streams) GetDisposition() transcoder.Disposition {
282+
return s.Disposition
283+
}
284+
285+
//GetBitRate ...
286+
func (s Streams) GetBitRate() string {
287+
return s.BitRate
288+
}
289+
290+
//GetDefault ...
291+
func (d Disposition) GetDefault() int {
292+
return d.Default
293+
}
294+
295+
//GetDub ...
296+
func (d Disposition) GetDub() int {
297+
return d.Dub
298+
}
299+
300+
//GetOriginal ...
301+
func (d Disposition) GetOriginal() int {
302+
return d.Original
303+
}
304+
305+
//GetComment ...
306+
func (d Disposition) GetComment() int {
307+
return d.Comment
308+
}
309+
310+
//GetLyrics ...
311+
func (d Disposition) GetLyrics() int {
312+
return d.Lyrics
313+
}
314+
315+
//GetKaraoke ...
316+
func (d Disposition) GetKaraoke() int {
317+
return d.Karaoke
318+
}
319+
320+
//GetForced ...
321+
func (d Disposition) GetForced() int {
322+
return d.Forced
323+
}
324+
325+
//GetHearingImpaired ...
326+
func (d Disposition) GetHearingImpaired() int {
327+
return d.HearingImpaired
328+
}
329+
330+
//GetVisualImpaired ...
331+
func (d Disposition) GetVisualImpaired() int {
332+
return d.VisualImpaired
333+
}
334+
335+
//GetCleanEffects ...
336+
func (d Disposition) GetCleanEffects() int {
337+
return d.CleanEffects
338+
}

0 commit comments

Comments
 (0)