-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ffmpeg pkg for reading files and parsing ffmpeg version
- Loading branch information
Showing
5 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,47 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"os/exec" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/AlexxIT/go2rtc/pkg/ffmpeg" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
var checkMu sync.Mutex | ||
var checkErr error | ||
var checkVer string | ||
|
||
const ( | ||
FFmpeg50 = "59. 16" | ||
FFmpeg51 = "59. 27" | ||
FFmpeg60 = "60. 3" | ||
FFmpeg61 = "60. 16" | ||
FFmpeg70 = "61. 1" | ||
) | ||
var verMu sync.Mutex | ||
var verErr error | ||
var verFF string | ||
var verAV string | ||
|
||
func Version() (string, error) { | ||
checkMu.Lock() | ||
defer checkMu.Unlock() | ||
verMu.Lock() | ||
defer verMu.Unlock() | ||
|
||
if checkVer != "" { | ||
return checkVer, checkErr | ||
if verFF != "" { | ||
return verFF, verErr | ||
} | ||
|
||
cmd := exec.Command(defaults["bin"], "-version") | ||
b, err := cmd.Output() | ||
if err != nil { | ||
checkVer = "-" | ||
checkErr = err | ||
return checkVer, checkErr | ||
verFF = "-" | ||
verErr = err | ||
return verFF, verErr | ||
} | ||
|
||
if len(b) < 100 { | ||
checkVer = "?" | ||
return checkVer, nil | ||
} | ||
verFF, verAV = ffmpeg.ParseVersion(b) | ||
|
||
// ffmpeg version n7.0-30-g8b0fe91754-20240520 Copyright (c) 2000-2024 the FFmpeg developers | ||
b = b[15:] | ||
if i := bytes.IndexByte(b, ' '); i > 0 { | ||
checkVer = string(b[:i]) | ||
if verFF == "" { | ||
verFF = "?" | ||
} | ||
|
||
// libavformat 60. 16.100 / 60. 16.100 | ||
if i := strings.Index(string(b), "libavformat"); i > 0 { | ||
// better to compare libavformat, because nightly/master builds | ||
libav := string(b[i+15 : i+25]) | ||
if libav < FFmpeg50 { | ||
checkErr = errors.New("ffmpeg: unsupported version: " + checkVer) | ||
return checkVer, checkErr | ||
} | ||
if libav < FFmpeg61 && strings.Contains(defaults["file"], "readrate_initial_burst") { | ||
defaults["file"] = "-re -i {input}" | ||
} | ||
// better to compare libavformat, because nightly/master builds | ||
if verAV != "" && verAV < ffmpeg.Version50 { | ||
verErr = errors.New("ffmpeg: unsupported version: " + verFF) | ||
} | ||
|
||
log.Debug().Str("version", checkVer).Msgf("[ffmpeg] bin") | ||
log.Debug().Str("version", verFF).Str("libavformat", verAV).Msgf("[ffmpeg] bin") | ||
|
||
return checkVer, nil | ||
return verFF, verErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters