Skip to content

Commit

Permalink
fix crash when running ffmpeg command in current folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kira1928 committed Jan 5, 2023
1 parent f5523d5 commit 4fb8825
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/pkg/parser/ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/hr3lxphr6j/bililive-go/src/live"
"github.com/hr3lxphr6j/bililive-go/src/pkg/parser"
"github.com/hr3lxphr6j/bililive-go/src/pkg/utils"
)

const (
Expand Down Expand Up @@ -119,8 +120,12 @@ func (p *Parser) Status() (map[string]string, error) {
}

func (p *Parser) ParseLiveStream(url *url.URL, live live.Live, file string) (err error) {
ffmpegPath, err := utils.GetFFmpegPath()
if err != nil {
return err
}
p.cmd = exec.Command(
"ffmpeg",
ffmpegPath,
"-nostats",
"-progress", "-",
"-y", "-re",
Expand Down
11 changes: 8 additions & 3 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ import (
"regexp"
)

func IsFFmpegExist() bool {
_, err := exec.LookPath("ffmpeg")
func GetFFmpegPath() (string, error) {
path, err := exec.LookPath("ffmpeg")
if errors.Is(err, exec.ErrDot) {
// put ffmpeg.exe and binary like bililive-windows-amd64.exe to the same folder is allowed
err = nil
path, err = exec.LookPath("./ffmpeg")
}
return path, err
}

func IsFFmpegExist() bool {
_, err := GetFFmpegPath()
return err == nil
}

Expand Down
7 changes: 6 additions & 1 deletion src/recorders/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ func (r *recorder) tryRecode() {
r.getLogger().Debugln(r.parser.ParseLiveStream(url, r.Live, fileName))
removeEmptyFile(fileName)
if r.config.OnRecordFinished.ConvertToMp4 {
ffmpegPath, err := utils.GetFFmpegPath()
if err != nil {
r.getLogger().WithError(err).Error("failed to find ffmpeg")
return
}
convertCmd := exec.Command(
"ffmpeg",
ffmpegPath,
"-hide_banner",
"-i",
fileName,
Expand Down

0 comments on commit 4fb8825

Please sign in to comment.