Cleanup in utils
This commit is contained in:
parent
34c0e44380
commit
32f30850c4
4 changed files with 8 additions and 12 deletions
|
@ -65,7 +65,7 @@ func (camera *Camera) SetFrameBuffer(buffer []byte) error {
|
||||||
// Creates a new camera struct that can read from the device with the given stream index.
|
// Creates a new camera struct that can read from the device with the given stream index.
|
||||||
func NewCamera(stream int) (*Camera, error) {
|
func NewCamera(stream int) (*Camera, error) {
|
||||||
// Check if ffmpeg is installed on the users machine.
|
// Check if ffmpeg is installed on the users machine.
|
||||||
if err := checkExists("ffmpeg"); err != nil {
|
if err := installed("ffmpeg"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
utils.go
12
utils.go
|
@ -26,7 +26,7 @@ func exists(filename string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if the given program is installed.
|
// Checks if the given program is installed.
|
||||||
func checkExists(program string) error {
|
func installed(program string) error {
|
||||||
cmd := exec.Command(program, "-version")
|
cmd := exec.Command(program, "-version")
|
||||||
errmsg := fmt.Errorf("%s is not installed", program)
|
errmsg := fmt.Errorf("%s is not installed", program)
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
|
@ -74,13 +74,9 @@ func ffprobe(filename, stype string) (map[string]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseFFprobe(buffer[:total]), nil
|
// Parse ffprobe output to fill in video data.
|
||||||
}
|
|
||||||
|
|
||||||
// Parse ffprobe output to fill in video data.
|
|
||||||
func parseFFprobe(input []byte) map[string]string {
|
|
||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
for _, line := range strings.Split(string(input), "|") {
|
for _, line := range strings.Split(string(buffer[:total]), "|") {
|
||||||
if strings.Contains(line, "=") {
|
if strings.Contains(line, "=") {
|
||||||
keyValue := strings.Split(line, "=")
|
keyValue := strings.Split(line, "=")
|
||||||
if _, ok := data[keyValue[0]]; !ok {
|
if _, ok := data[keyValue[0]]; !ok {
|
||||||
|
@ -88,7 +84,7 @@ func parseFFprobe(input []byte) map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses the given data into a float64.
|
// Parses the given data into a float64.
|
||||||
|
|
4
video.go
4
video.go
|
@ -90,10 +90,10 @@ func NewVideo(filename string) (*Video, error) {
|
||||||
return nil, fmt.Errorf("video file %s does not exist", filename)
|
return nil, fmt.Errorf("video file %s does not exist", filename)
|
||||||
}
|
}
|
||||||
// Check if ffmpeg and ffprobe are installed on the users machine.
|
// Check if ffmpeg and ffprobe are installed on the users machine.
|
||||||
if err := checkExists("ffmpeg"); err != nil {
|
if err := installed("ffmpeg"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := checkExists("ffprobe"); err != nil {
|
if err := installed("ffprobe"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ func (writer *VideoWriter) AudioCodec() string {
|
||||||
// Creates a new VideoWriter struct with default values from the Options struct.
|
// Creates a new VideoWriter struct with default values from the Options struct.
|
||||||
func NewVideoWriter(filename string, width, height int, options *Options) (*VideoWriter, error) {
|
func NewVideoWriter(filename string, width, height int, options *Options) (*VideoWriter, error) {
|
||||||
// Check if ffmpeg is installed on the users machine.
|
// Check if ffmpeg is installed on the users machine.
|
||||||
if err := checkExists("ffmpeg"); err != nil {
|
if err := installed("ffmpeg"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue