Skip to content

Commit

Permalink
Merge pull request #288 from kira1928/feature/convert-after-recorded
Browse files Browse the repository at this point in the history
增加录制后转成mp4和转换成功后删除原文件的选项
  • Loading branch information
kira1928 authored Jan 2, 2023
2 parents 5e6726c + 992d8c6 commit b6b6d2d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type VideoSplitStrategies struct {
MaxDuration time.Duration `yaml:"max_duration"`
}

// On record finished actions.
type OnRecordFinished struct {
ConvertToMp4 bool `yaml:"convert_to_mp4"`
DeleteFlvAfterConvert bool `yaml:"delete_flv_after_convert"`
}

// Config content all config info.
type Config struct {
file string
Expand All @@ -58,6 +64,7 @@ type Config struct {
OutputTmpl string `yaml:"out_put_tmpl"`
VideoSplitStrategies VideoSplitStrategies `yaml:"video_split_strategies"`
Cookies map[string]string `yaml:"cookies"`
OnRecordFinished OnRecordFinished `yaml:"on_record_finished"`
}

var defaultConfig = Config{
Expand All @@ -73,6 +80,10 @@ var defaultConfig = Config{
VideoSplitStrategies: VideoSplitStrategies{
OnRoomNameChanged: false,
},
OnRecordFinished: OnRecordFinished{
ConvertToMp4: false,
DeleteFlvAfterConvert: false,
},
}

// Verify will return an error when this config has problem.
Expand Down
18 changes: 18 additions & 0 deletions src/recorders/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -140,6 +141,23 @@ func (r *recorder) tryRecode() {
r.startTime = time.Now()
r.getLogger().Debugln(r.parser.ParseLiveStream(url, r.Live, fileName))
removeEmptyFile(fileName)
if r.config.OnRecordFinished.ConvertToMp4 {
convertCmd := exec.Command(
"ffmpeg",
"-hide_banner",
"-i",
fileName,
"-c",
"copy",
fileName+".mp4",
)
if err = convertCmd.Run(); err != nil {
convertCmd.Process.Kill()
r.getLogger().Debugln(err)
} else if r.config.OnRecordFinished.DeleteFlvAfterConvert {
os.Remove(fileName)
}
}
}

func (r *recorder) run() {
Expand Down

0 comments on commit b6b6d2d

Please sign in to comment.