-
-
Notifications
You must be signed in to change notification settings - Fork 341
Supports specifying a file name during video recording, facilitating third-party access to the API for retrieving the recorded file name. #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||
| "io" | ||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| task "github.com/langhuihui/gotask" | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -148,6 +149,12 @@ type Recorder struct { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| var CustomFileName = func(job *m7s.RecordJob) string { | ||||||||||||||||||||||||||||||||||||||||
| if fn := job.RecConf.FileName; fn != "" { | ||||||||||||||||||||||||||||||||||||||||
| if !strings.HasSuffix(strings.ToLower(fn), ".flv") { | ||||||||||||||||||||||||||||||||||||||||
| fn = fn + ".flv" | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| return filepath.Join(job.RecConf.FilePath, fn) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+152
to
+156
|
||||||||||||||||||||||||||||||||||||||||
| if fn := job.RecConf.FileName; fn != "" { | |
| if !strings.HasSuffix(strings.ToLower(fn), ".flv") { | |
| fn = fn + ".flv" | |
| } | |
| return filepath.Join(job.RecConf.FilePath, fn) | |
| if fn := strings.TrimSpace(job.RecConf.FileName); fn != "" { | |
| if !strings.HasSuffix(strings.ToLower(fn), ".flv") { | |
| fn = fn + ".flv" | |
| } | |
| cleanFn := filepath.Clean(fn) | |
| if filepath.IsAbs(cleanFn) || cleanFn == "." || cleanFn == ".." || cleanFn != filepath.Base(cleanFn) { | |
| cleanFn = filepath.Base(cleanFn) | |
| } | |
| if cleanFn == "" || cleanFn == "." || cleanFn == ".." { | |
| cleanFn = fmt.Sprintf("%d.flv", time.Now().Unix()) | |
| } | |
| return filepath.Join(job.RecConf.FilePath, cleanFn) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,11 @@ | ||||||||||||||||||||||
| package hls | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import ( | ||||||||||||||||||||||
| "context" | ||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||
| "time" | ||||||||||||||||||||||
| "context" | ||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||
| "time" | ||||||||||||||||||||||
|
Comment on lines
+4
to
+8
|
||||||||||||||||||||||
| "context" | |
| "fmt" | |
| "strings" | |
| "path/filepath" | |
| "time" | |
| "context" | |
| "fmt" | |
| "path/filepath" | |
| "strings" | |
| "time" |
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom fileName is used directly with filepath.Join. If fileName is absolute or contains path separators (e.g. "../x"), Join can escape RecConf.FilePath and write outside the intended directory. Sanitize/validate the provided name (e.g., reject separators/absolute paths, or force filepath.Base) before joining.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -386,7 +386,6 @@ func (p *MP4Plugin) download(w http.ResponseWriter, r *http.Request) { | |||||
| if err != nil { | ||||||
| return | ||||||
| } | ||||||
| p.Info("read", "file", file.Name()) | ||||||
|
|
||||||
| // 创建解复用器并解析文件 | ||||||
| demuxer := mp4.NewDemuxer(file) | ||||||
|
|
@@ -558,16 +557,22 @@ func (p *MP4Plugin) download(w http.ResponseWriter, r *http.Request) { | |||||
| func (p *MP4Plugin) StartRecord(ctx context.Context, req *mp4pb.ReqStartRecord) (res *mp4pb.ResponseStartRecord, err error) { | ||||||
| var recordExists bool | ||||||
| var filePath = "." | ||||||
| var fileName = "" | ||||||
| var fragment = time.Minute | ||||||
| if req.Fragment != nil { | ||||||
| fragment = req.Fragment.AsDuration() | ||||||
| } | ||||||
| if req.FilePath != "" { | ||||||
| filePath = req.FilePath | ||||||
| } | ||||||
| if req.FileName != "" { | ||||||
| fileName = req.FileName | ||||||
| } | ||||||
|
|
||||||
| p.Debug("mp4 plugin start record", "streamPath", req.StreamPath, "filePath", filePath, "fileName", fileName, "fragment", fragment) | ||||||
| res = &mp4pb.ResponseStartRecord{} | ||||||
| _, recordExists = p.Server.Records.Find(func(job *m7s.RecordJob) bool { | ||||||
| return job.StreamPath == req.StreamPath && job.RecConf.FilePath == req.FilePath | ||||||
| return job.StreamPath == req.StreamPath && job.RecConf.FilePath == req.FilePath && job.RecConf.FileName == req.FileName | ||||||
|
||||||
| return job.StreamPath == req.StreamPath && job.RecConf.FilePath == req.FilePath && job.RecConf.FileName == req.FileName | |
| return job.StreamPath == req.StreamPath && job.RecConf.FilePath == filePath && job.RecConf.FileName == fileName |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example config change does more than demonstrate the new file-name feature (it changes global loglevel, adds an HTTP listen address, and enables the mp4 plugin by default). If the PR is only meant to add filename support, consider keeping unrelated example-default behavior unchanged or moving these changes to a separate PR to avoid surprising defaults.