-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (73 loc) · 2.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"context"
"flag"
"fmt"
"time"
"gopkg.in/vansante/go-ffprobe.v2"
)
func getInfo(filename string) (*ffprobe.ProbeData, error) {
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()
data, err := ffprobe.ProbeURL(ctx, filename)
if err != nil {
return nil, fmt.Errorf("error getting ffprobe data: %w", err)
}
return data, nil
}
func printInfo(info *ffprobe.ProbeData) {
fmt.Println("BitRate:", info.Format.BitRate)
fmt.Println("Duration:", info.Format.Duration())
fmt.Println("Format:", info.Format.FormatName, info.Format.FormatLongName)
fmt.Println("Size:", info.Format.Size)
fmt.Println("NBStreams", info.Format.NBStreams)
printVideoStreamsInfo(info.StreamType(ffprobe.StreamVideo))
printAudioStreamsInfo(info.StreamType(ffprobe.StreamAudio))
printSubtitleStreamsInfo(info.StreamType(ffprobe.StreamSubtitle))
}
func printVideoStreamsInfo(streams []ffprobe.Stream) {
for idx, s := range streams {
fmt.Printf("-> Video Stream #%d\n", idx)
fmt.Println("---> AvgFrameRate", s.AvgFrameRate)
fmt.Println("---> BitRate", s.BitRate)
fmt.Println("---> SampleRate", s.SampleRate)
fmt.Println("---> CodecName CodecLongName", s.CodecName, s.CodecLongName)
fmt.Println("---> Width Height", s.Width, s.Height)
fmt.Println("---> BitsPerSample", s.BitsPerSample)
}
}
func printAudioStreamsInfo(streams []ffprobe.Stream) {
for idx, s := range streams {
fmt.Printf("-> Audio Stream #%d\n", idx)
fmt.Println("---> AvgFrameRate", s.AvgFrameRate)
fmt.Println("---> BitRate", s.BitRate)
fmt.Println("---> SampleRate", s.SampleRate)
fmt.Println("---> CodecName CodecLongName", s.CodecName, s.CodecLongName)
fmt.Println("---> BitsPerSample", s.BitsPerSample)
}
}
func printSubtitleStreamsInfo(streams []ffprobe.Stream) {
for idx, s := range streams {
fmt.Printf("-> Subtitle Stream #%d\n", idx)
fmt.Println("---> AvgFrameRate", s)
fmt.Println("---> BitRate", s.BitRate)
fmt.Println("---> SampleRate", s.SampleRate)
fmt.Println("---> CodecName CodecLongName", s.CodecName, s.CodecLongName)
fmt.Println("---> BitsPerSample", s.BitsPerSample)
}
}
func main() {
flag.Parse()
for _, filename := range flag.Args() {
fmt.Printf("Probing “%s”...\n", filename)
probeData, err := getInfo(filename)
if err != nil {
panic(err)
}
numAttachments := len(probeData.StreamType(ffprobe.StreamSubtitle))
if numAttachments > 0 {
fmt.Printf("Found %d attachments!\n", numAttachments)
}
printInfo(probeData)
}
}