+
Skip to content

new command line option to customize the location of transcode logs #117

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

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ RUN go build -trimpath -buildmode=pie -ldflags="-s -w" -o dms
FROM docker.io/alpine:edge
COPY --from=build --chown=1000:1000 /dms/dms /dms
RUN apk add --no-cache ffmpeg ffmpegthumbnailer mailcap
USER 1000:1000
RUN adduser user || true
USER user:user
WORKDIR /dmsdir
VOLUME /dmsdir
ENTRYPOINT ["/dms"]
32 changes: 16 additions & 16 deletions README.rst
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@ Usage of dms:
- browse root path
* - ``-stallEventSubscribe``
- workaround for some bad event subscribers
* - ``-transcodeLogPattern``
- pattern where to write transcode logs to. The ``[tsname]`` placeholder is replaced with the name of the item currently being played. The default is ``$HOME/.dms/log/[tsname]``. You may turn off transcode logging entirely by setting it to ``/dev/null``. You may log to stderr by setting ``/dev/stderr``.

Dynamic streams
===============
DMS supports "dynamic streams" generated on the fly. This feature can be activated with the
`-allowDynamicStreams` command line flag and can be configured by placing special metadata
``-allowDynamicStreams`` command line flag and can be configured by placing special metadata
files in your content directory.
The name of these metadata files ends with `.dms.json`, their structure is [documented here](https://pkg.go.dev/github.com/anacrolix/dms/dlna/dms)

An example:

```
{
"Title": "My awesome webcam",
"Resources": [
{
"MimeType": "video/webm",
"Command": "ffmpeg -i rtsp://10.6.8.161:554/Streaming/Channels/502/ -c:v copy -c:a copy -movflags +faststart+frag_keyframe+empty_moov -f matroska -"
}
]
}
```
The name of these metadata files ends with ``.dms.json``, their structure is `documented here <https://pkg.go.dev/github.com/anacrolix/dms/dlna/dms>`_.

An example::

{
"Title": "My awesome webcam",
"Resources": [
{
"MimeType": "video/webm",
"Command": "ffmpeg -i rtsp://10.6.8.161:554/Streaming/Channels/502/ -c:v copy -c:a copy -movflags +faststart+frag_keyframe+empty_moov -f matroska -"
}
]
}
34 changes: 18 additions & 16 deletions dlna/dms/dms.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ type Server struct {
// This feature is not enabled by default, since having write access to a shared media
// folder allows executing arbitrary commands in the context of the DLNA server.
AllowDynamicStreams bool
// pattern where to write transcode logs to. The [tsname] placeholder is replaced with the name
// of the item currently being played. The default is $HOME/.dms/log/[tsname]
TranscodeLogPattern string
Logger log.Logger
eventingLogger log.Logger
}
Expand Down Expand Up @@ -425,7 +428,7 @@ func (me *Server) serveDLNATranscode(w http.ResponseWriter, r *http.Request, pat
return
}

var stderrPath string
var logTsName string
if !dynamicMode {
ffInfo, _ := me.ffmpegProbe(path_)
if ffInfo != nil {
Expand All @@ -436,23 +439,22 @@ func (me *Server) serveDLNATranscode(w http.ResponseWriter, r *http.Request, pat
}
}

stderrPath = func() string {
u, _ := user.Current()
return filepath.Join(u.HomeDir, ".dms", "log", tsname, filepath.Base(path_))
}()
logTsName = filepath.Join(tsname, filepath.Base(path_))
} else {
stderrPath = func() string {
u, _ := user.Current()
return filepath.Join(u.HomeDir, ".dms", "log", tsname)
}()
logTsName = tsname
}
os.MkdirAll(filepath.Dir(stderrPath), 0o750)
logFile, err := os.Create(stderrPath)
if err != nil {
log.Printf("couldn't create transcode log file: %s", err)
} else {
defer logFile.Close()
log.Printf("logging transcode to %q", stderrPath)
stderrPath:= strings.Replace(me.TranscodeLogPattern, "[tsname]", logTsName, -1)
var logFile io.Writer
if stderrPath != "" {
os.MkdirAll(filepath.Dir(stderrPath), 0o750)
aLogFile, err := os.Create(stderrPath)
if err != nil {
log.Printf("couldn't create transcode log file: %s", err)
} else {
defer aLogFile.Close()
log.Printf("logging transcode to %q", stderrPath)
}
logFile = aLogFile
}
p, err := ts.Transcode(path_, range_.Start, range_.End-range_.Start, logFile)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions main.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type dmsConfig struct {
IgnoreUnreadable bool
AllowedIpNets []*net.IPNet
AllowDynamicStreams bool
TranscodeLogPattern string
}

func (config *dmsConfig) load(configPath string) {
Expand Down Expand Up @@ -130,6 +131,7 @@ func mainErr() error {
configFilePath := flag.String("config", "", "json configuration file")
allowedIps := flag.String("allowedIps", "", "allowed ip of clients, separated by comma")
forceTranscodeTo := flag.String("forceTranscodeTo", config.ForceTranscodeTo, "force transcoding to certain format, supported: 'chromecast', 'vp8', 'web'")
transcodeLogPattern := flag.String("transcodeLogPattern", "", "pattern where to write transcode logs to. The [tsname] placeholder is replaced with the name of the item currently being played. The default is $HOME/.dms/log/[tsname]")
flag.BoolVar(&config.NoTranscode, "noTranscode", false, "disable transcoding")
flag.BoolVar(&config.NoProbe, "noProbe", false, "disable media probing with ffprobe")
flag.BoolVar(&config.StallEventSubscribe, "stallEventSubscribe", false, "workaround for some bad event subscribers")
Expand All @@ -155,6 +157,15 @@ func mainErr() error {
config.FFprobeCachePath = *fFprobeCachePath
config.AllowedIpNets = makeIpNets(*allowedIps)
config.ForceTranscodeTo = *forceTranscodeTo
config.TranscodeLogPattern = *transcodeLogPattern

if config.TranscodeLogPattern == "" {
u, err := user.Current()
if err != nil {
return fmt.Errorf("unable to resolve current user: %q", err)
}
config.TranscodeLogPattern = filepath.Join(u.HomeDir, ".dms", "log", "[tsname]")
}

logger.Printf("allowed ip nets are %q", config.AllowedIpNets)
logger.Printf("serving folder %q", config.Path)
Expand Down Expand Up @@ -210,6 +221,7 @@ func mainErr() error {
NoTranscode: config.NoTranscode,
AllowDynamicStreams: config.AllowDynamicStreams,
ForceTranscodeTo: config.ForceTranscodeTo,
TranscodeLogPattern: config.TranscodeLogPattern,
NoProbe: config.NoProbe,
Icons: []dms.Icon{
{
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载