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

Commit 6ea55de

Browse files
committed
update
1 parent a354e6a commit 6ea55de

File tree

3 files changed

+51
-67
lines changed

3 files changed

+51
-67
lines changed

ffmpeg/ffmpeg.go

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,14 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
240240
input = "pipe:"
241241
}
242242

243-
args := []string{"-i", input, "-print_format", "json", "-show_format", "-show_streams", "-show_error"}
243+
args := []string{
244+
"-i", input,
245+
"-print_format", "json",
246+
"-show_entries", "stream=:stream_tags=rotate",
247+
"-show_format",
248+
"-show_streams",
249+
"-show_error",
250+
}
244251

245252
var cmd *exec.Cmd
246253
if t.commandContext == nil {
@@ -263,41 +270,7 @@ func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
263270
if err = json.Unmarshal(outb.Bytes(), &metadata); err != nil {
264271
return nil, err
265272
}
266-
metadata.Infos = map[string]string{}
267-
reader := bufio.NewReader(&errb)
268-
var prefix string
269-
var hasMetadata bool
270-
for {
271-
byteLine, isPrefix, err := reader.ReadLine()
272-
if err != nil && err != io.EOF {
273-
return metadata, err
274-
}
275-
line := string(byteLine)
276-
if isPrefix {
277-
prefix += line
278-
continue
279-
}
280-
line = prefix + line
281-
line = strings.TrimLeft(line, ` `)
282-
if !hasMetadata {
283-
if strings.HasPrefix(line, `Metadata:`) {
284-
hasMetadata = true
285-
}
286-
} else {
287-
parts := strings.SplitN(line, `:`, 2)
288-
if len(parts) == 2 {
289-
parts[0] = strings.TrimRight(parts[0], ` `)
290-
if len(parts[0]) > 0 && parts[0] != `Metadata:` {
291-
parts[1] = strings.TrimSpace(parts[1])
292-
metadata.Infos[parts[0]] = parts[1]
293-
}
294-
}
295-
}
296-
prefix = ""
297-
if err == io.EOF {
298-
break
299-
}
300-
}
273+
301274
t.metadata = metadata
302275

303276
return metadata, nil

ffmpeg/metadata.go

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import "github.com/admpub/transcoder"
44

55
// Metadata ...
66
type Metadata struct {
7-
Format Format `json:"format"`
8-
Streams []Streams `json:"streams"`
9-
Infos map[string]string `json:"infos"`
7+
Format Format `json:"format"`
8+
Streams []Streams `json:"streams"`
109
}
1110

1211
// Format ...
@@ -26,34 +25,36 @@ type Format struct {
2625
// Streams ...
2726
type Streams struct {
2827
Index int
29-
ID string `json:"id"`
30-
CodecName string `json:"codec_name"`
31-
CodecLongName string `json:"codec_long_name"`
32-
Profile string `json:"profile"`
33-
CodecType string `json:"codec_type"`
34-
CodecTimeBase string `json:"codec_time_base"`
35-
CodecTagString string `json:"codec_tag_string"`
36-
CodecTag string `json:"codec_tag"`
37-
Width int `json:"width"`
38-
Height int `json:"height"`
39-
CodedWidth int `json:"coded_width"`
40-
CodedHeight int `json:"coded_height"`
41-
HasBFrames int `json:"has_b_frames"`
42-
SampleAspectRatio string `json:"sample_aspect_ratio"`
43-
DisplayAspectRatio string `json:"display_aspect_ratio"`
44-
PixFmt string `json:"pix_fmt"`
45-
Level int `json:"level"`
46-
ChromaLocation string `json:"chroma_location"`
47-
Refs int `json:"refs"`
48-
QuarterSample string `json:"quarter_sample"`
49-
DivxPacked string `json:"divx_packed"`
50-
RFrameRrate string `json:"r_frame_rate"`
51-
AvgFrameRate string `json:"avg_frame_rate"`
52-
TimeBase string `json:"time_base"`
53-
DurationTs int `json:"duration_ts"`
54-
Duration string `json:"duration"`
55-
Disposition Disposition `json:"disposition"`
56-
BitRate string `json:"bit_rate"`
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+
Tags map[string]string `json:"tags"`
57+
SideDataList []map[string]string `json:"side_data_list"`
5758
}
5859

5960
// Tags ...
@@ -288,6 +289,14 @@ func (s Streams) GetBitRate() string {
288289
return s.BitRate
289290
}
290291

292+
func (s Streams) GetTags() map[string]string {
293+
return s.Tags
294+
}
295+
296+
func (s Streams) GetSideDataList() []map[string]string {
297+
return s.SideDataList
298+
}
299+
291300
//GetDefault ...
292301
func (d Disposition) GetDefault() int {
293302
return d.Default

metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type Streams interface {
5151
GetDuration() string
5252
GetDisposition() Disposition
5353
GetBitRate() string
54+
GetTags() map[string]string
55+
GetSideDataList() []map[string]string
5456
}
5557

5658
// Tags ...

0 commit comments

Comments
 (0)