Fix path to ffmpeg and ffprobe.
Added the ability to select the path to ffmpeg and ffprobe.
This commit is contained in:
@@ -11,11 +11,19 @@ import (
|
||||
type ServiceContract interface {
|
||||
RunConvert(setting ConvertSetting) error
|
||||
GetTotalDuration(file *File) (float64, error)
|
||||
GetFFmpegVesrion() (string, error)
|
||||
GetFFprobeVersion() (string, error)
|
||||
ChangeFFmpegPath(path string) (bool, error)
|
||||
ChangeFFprobePath(path string) (bool, error)
|
||||
}
|
||||
|
||||
type FFPathUtilities struct {
|
||||
FFmpeg string
|
||||
FFprobe string
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
pathFFmpeg string
|
||||
pathFFprobe string
|
||||
ffPathUtilities *FFPathUtilities
|
||||
}
|
||||
|
||||
type File struct {
|
||||
@@ -33,10 +41,9 @@ type ConvertData struct {
|
||||
totalDuration float64
|
||||
}
|
||||
|
||||
func NewService(pathFFmpeg string, pathFFprobe string) *Service {
|
||||
func NewService(ffPathUtilities FFPathUtilities) *Service {
|
||||
return &Service{
|
||||
pathFFmpeg: pathFFmpeg,
|
||||
pathFFprobe: pathFFprobe,
|
||||
ffPathUtilities: &ffPathUtilities,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +55,7 @@ func (s Service) RunConvert(setting ConvertSetting) error {
|
||||
//args := "-n -i " + setting.VideoFileInput.Path + " -c:v libx264 -progress unix://" + setting.SocketPath + " output-file.mp4"
|
||||
//args := "-y -i " + setting.VideoFileInput.Path + " -c:v libx264 -progress unix://" + setting.SocketPath + " output-file.mp4"
|
||||
args := []string{"-y", "-i", setting.VideoFileInput.Path, "-c:v", "libx264", "-progress", "unix://" + setting.SocketPath, "output-file.mp4"}
|
||||
cmd := exec.Command(s.pathFFmpeg, args...)
|
||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, args...)
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
@@ -64,7 +71,7 @@ func (s Service) RunConvert(setting ConvertSetting) error {
|
||||
|
||||
func (s Service) GetTotalDuration(file *File) (duration float64, err error) {
|
||||
args := []string{"-v", "error", "-select_streams", "v:0", "-count_packets", "-show_entries", "stream=nb_read_packets", "-of", "csv=p=0", file.Path}
|
||||
cmd := exec.Command(s.pathFFprobe, args...)
|
||||
cmd := exec.Command(s.ffPathUtilities.FFprobe, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
errString := strings.TrimSpace(string(out))
|
||||
@@ -75,3 +82,49 @@ func (s Service) GetTotalDuration(file *File) (duration float64, err error) {
|
||||
}
|
||||
return strconv.ParseFloat(strings.TrimSpace(string(out)), 64)
|
||||
}
|
||||
|
||||
func (s Service) GetFFmpegVesrion() (string, error) {
|
||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, "-version")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
text := regexp.MustCompile("\r?\n").Split(strings.TrimSpace(string(out)), -1)
|
||||
return text[0], nil
|
||||
}
|
||||
|
||||
func (s Service) GetFFprobeVersion() (string, error) {
|
||||
cmd := exec.Command(s.ffPathUtilities.FFprobe, "-version")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
text := regexp.MustCompile("\r?\n").Split(strings.TrimSpace(string(out)), -1)
|
||||
return text[0], nil
|
||||
}
|
||||
|
||||
func (s Service) ChangeFFmpegPath(path string) (bool, error) {
|
||||
cmd := exec.Command(path, "-version")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if strings.Contains(strings.TrimSpace(string(out)), "ffmpeg") == false {
|
||||
return false, nil
|
||||
}
|
||||
s.ffPathUtilities.FFmpeg = path
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s Service) ChangeFFprobePath(path string) (bool, error) {
|
||||
cmd := exec.Command(path, "-version")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if strings.Contains(strings.TrimSpace(string(out)), "ffprobe") == false {
|
||||
return false, nil
|
||||
}
|
||||
s.ffPathUtilities.FFprobe = path
|
||||
return true, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user