Debian Codegraph @

ffprobe.go

raw symbols SCIP
1 package ffprobescip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.13 bytes/"
5 "contextscip-go gomod github.com/golang/go/src go1.13 context/"
6 "encoding/jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/"
7 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
8 "ioscip-go gomod github.com/golang/go/src go1.13 io/"
9 "os/execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/"
10 )
11
12 var binPathscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/binPath. = "ffprobe"
13
14 // SetFFProbeBinPath sets the global path to find and execute the ffprobe program
15 func SetFFProbeBinPathscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/SetFFProbeBinPath().(newBinPath string) {
16 binPathscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/binPath. = newBinPath
17 }
18
19 // ProbeURL is used to probe the given media file using ffprobe. The URL can be a local path, a HTTP URL or any other
20 // protocol supported by ffprobe, see here for a full list: https://ffmpeg.org/ffmpeg-protocols.html
21 // This function takes a context to allow killing the ffprobe process if it takes too long or in case of shutdown.
22 // Any additional ffprobe parameter can be supplied as well using extraFFProbeOptions.
23 func ProbeURLscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeURL().(ctx contextscip-go gomod github.com/golang/go/src go1.13 context/.Contextscip-go gomod github.com/golang/go/src go1.13 context/Context#, fileURL string, extraFFProbeOptions ...string) (data *ProbeDatascip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#, err error) {
24 args := append([]string{
25 "-loglevel", "fatal",
26 "-print_format", "json",
27 "-show_format",
28 "-show_streams",
29 "-show_chapters",
30 }, extraFFProbeOptions...)
31
32 // Add the file argument
33 args = append(args, fileURL)
34
35 cmd := execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/.CommandContextscip-go gomod github.com/golang/go/src go1.13 `os/exec`/CommandContext().(ctx, binPathscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/binPath., args...)
36 cmd.SysProcAttrscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#SysProcAttr. = procAttributesscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/procAttributes().()
37
38 return runProbescip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/runProbe().(cmd)
39 }
40
41 // ProbeReader is used to probe a media file using an io.Reader. The reader is piped to the stdin of the ffprobe command
42 // and the data is returned.
43 // This function takes a context to allow killing the ffprobe process if it takes too long or in case of shutdown.
44 // Any additional ffprobe parameter can be supplied as well using extraFFProbeOptions.
45 func ProbeReaderscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeReader().(ctx contextscip-go gomod github.com/golang/go/src go1.13 context/.Contextscip-go gomod github.com/golang/go/src go1.13 context/Context#, reader ioscip-go gomod github.com/golang/go/src go1.13 io/.Readerscip-go gomod github.com/golang/go/src go1.13 io/Reader#, extraFFProbeOptions ...string) (data *ProbeDatascip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#, err error) {
46 args := append([]string{
47 "-loglevel", "fatal",
48 "-print_format", "json",
49 "-show_format",
50 "-show_streams",
51 "-show_chapters",
52 }, extraFFProbeOptions...)
53
54 // Add the file from stdin argument
55 args = append(args, "-")
56
57 cmd := execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/.CommandContextscip-go gomod github.com/golang/go/src go1.13 `os/exec`/CommandContext().(ctx, binPathscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/binPath., args...)
58 cmd.Stdinscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Stdin. = reader
59 cmd.SysProcAttrscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#SysProcAttr. = procAttributesscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/procAttributes().()
60
61 return runProbescip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/runProbe().(cmd)
62 }
63
64 // runProbe takes the fully configured ffprobe command and executes it, returning the ffprobe data if everything went fine.
65 func runProbescip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/runProbe().(cmd *execscip-go gomod github.com/golang/go/src go1.13 `os/exec`/.Cmdscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#) (data *ProbeDatascip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#, err error) {
66 var outputBuf bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#
67 var stdErr bytesscip-go gomod github.com/golang/go/src go1.13 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#
68
69 cmd.Stdoutscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Stdout. = &outputBuf
70 cmd.Stderrscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Stderr. = &stdErr
71
72 err = cmd.Runscip-go gomod github.com/golang/go/src go1.13 `os/exec`/Cmd#Run().()
73 if err != nil {
74 return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("error running %s [%s] %w", binPathscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/binPath., stdErr.Stringscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#String().(), err)
75 }
76
77 data = &ProbeDatascip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#{}
78 err = jsonscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.13 `encoding/json`/Unmarshal().(outputBuf.Bytesscip-go gomod github.com/golang/go/src go1.13 bytes/Buffer#Bytes().(), data)
79 if err != nil {
80 return data, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("error parsing ffprobe output: %w", err)
81 }
82
83 if data.Formatscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#Format. == nil {
84 return data, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("no format data found in ffprobe output")
85 }
86
87 // Populate the old Tags structs for backwards compatibility purposes:
88 if len(data.Formatscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#Format..TagListscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/Format#TagList.) > 0 {
89 data.Formatscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#Format..Tagsscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/Format#Tags. = &FormatTagsscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/FormatTags#{}
90 data.Formatscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#Format..Tagsscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/Format#Tags..setFromscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/FormatTags#setFrom().(data.Formatscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#Format..TagListscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/Format#TagList.)
91 }
92 for _, str := range data.Streamsscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/ProbeData#Streams. {
93 str.Tagsscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/Stream#Tags..setFromscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/StreamTags#setFrom().(str.TagListscip-go gomod gopkg.in/vansante/go-ffprobe.v2 . `gopkg.in/vansante/go-ffprobe.v2`/Stream#TagList.)
94 }
95
96 return data, nil
97 }