diff --git a/camera.go b/camera.go index 82ffe02..0605875 100644 --- a/camera.go +++ b/camera.go @@ -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. func NewCamera(stream int) (*Camera, error) { // Check if ffmpeg is installed on the users machine. - if err := checkExists("ffmpeg"); err != nil { + if err := installed("ffmpeg"); err != nil { return nil, err } diff --git a/utils.go b/utils.go index dbcff7e..ffaacc5 100644 --- a/utils.go +++ b/utils.go @@ -26,7 +26,7 @@ func exists(filename string) bool { } // Checks if the given program is installed. -func checkExists(program string) error { +func installed(program string) error { cmd := exec.Command(program, "-version") errmsg := fmt.Errorf("%s is not installed", program) if err := cmd.Start(); err != nil { @@ -74,13 +74,9 @@ func ffprobe(filename, stype string) (map[string]string, error) { return nil, err } - return parseFFprobe(buffer[:total]), nil -} - -// Parse ffprobe output to fill in video data. -func parseFFprobe(input []byte) map[string]string { + // Parse ffprobe output to fill in video data. data := make(map[string]string) - for _, line := range strings.Split(string(input), "|") { + for _, line := range strings.Split(string(buffer[:total]), "|") { if strings.Contains(line, "=") { keyValue := strings.Split(line, "=") 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. diff --git a/video.go b/video.go index 5d1b1c0..c7e58c1 100644 --- a/video.go +++ b/video.go @@ -90,10 +90,10 @@ func NewVideo(filename string) (*Video, error) { return nil, fmt.Errorf("video file %s does not exist", filename) } // 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 } - if err := checkExists("ffprobe"); err != nil { + if err := installed("ffprobe"); err != nil { return nil, err } diff --git a/videowriter.go b/videowriter.go index cca0954..456c1b9 100644 --- a/videowriter.go +++ b/videowriter.go @@ -98,7 +98,7 @@ func (writer *VideoWriter) AudioCodec() string { // Creates a new VideoWriter struct with default values from the Options struct. func NewVideoWriter(filename string, width, height int, options *Options) (*VideoWriter, error) { // Check if ffmpeg is installed on the users machine. - if err := checkExists("ffmpeg"); err != nil { + if err := installed("ffmpeg"); err != nil { return nil, err }