Cleanup in utils

This commit is contained in:
Alex Eidt 2022-09-06 15:26:47 -07:00
parent 34c0e44380
commit 32f30850c4
4 changed files with 8 additions and 12 deletions

View file

@ -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
}

View file

@ -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 {
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.

View file

@ -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
}

View file

@ -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
}