summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rhimport/converter.go54
-rw-r--r--rhimport/core.go2
2 files changed, 55 insertions, 1 deletions
diff --git a/rhimport/converter.go b/rhimport/converter.go
index d375ad0..82e7f8b 100644
--- a/rhimport/converter.go
+++ b/rhimport/converter.go
@@ -51,6 +51,8 @@ func NewFetchConverter(convType, filename string, metadata map[string]string) (F
return NewNullFetchConverter(filename, metadata)
case "ffmpeg":
return NewFFMpegFetchConverter(filename, metadata)
+ case "ffmpeg-bs1770":
+ return NewFFMpegBS1770FetchConverter(filename, metadata)
}
return nil, "", errors.New("unknown fetch converter type: " + convType)
}
@@ -132,3 +134,55 @@ func (ff *FFMpegFetchConverter) GetResult() (result string, err error, loudnessC
}
return "", nil, 0.0
}
+
+//
+// FFMpeg Converter: converts all files into flac and calculates loudness correction value
+// using ITU BS1770 (EBU R128)
+//
+
+type FFMpegBS1770FetchConverter struct {
+ ffmpeg *exec.Cmd
+ bs1770 *exec.Cmd
+ pipe io.WriteCloser
+ result chan ConverterResult
+}
+
+func NewFFMpegBS1770FetchConverter(filename string, metadata map[string]string) (ff *FFMpegBS1770FetchConverter, filenameFlac string, err error) {
+ ff = &FFMpegBS1770FetchConverter{}
+ ext := filepath.Ext(filename)
+ filenameFlac = strings.TrimSuffix(filename, ext) + ".flac"
+ rhl.Printf("ffmpeg-converter: starting ffmpeg for file '%s' (had extension: '%s')", filenameFlac, ext)
+ ff.ffmpeg = exec.Command("ffmpeg", "-loglevel", "warning", "-i", "-", "-map_metadata", "0")
+ if metadata != nil {
+ for key, value := range metadata {
+ ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-metadata", fmt.Sprintf("%s=%s", key, value))
+ }
+ }
+ ff.ffmpeg.Args = append(ff.ffmpeg.Args, "-f", "flac", filenameFlac)
+ if ff.pipe, err = ff.ffmpeg.StdinPipe(); err != nil {
+ return nil, "", err
+ }
+
+ ff.result = make(chan ConverterResult, 1)
+ go func() {
+ output, err := ff.ffmpeg.CombinedOutput()
+ ff.result <- ConverterResult{strings.TrimSpace(string(output)), err, 0.0}
+ }()
+ return
+}
+
+func (ff *FFMpegBS1770FetchConverter) Write(p []byte) (n int, err error) {
+ return ff.pipe.Write(p)
+}
+
+func (ff *FFMpegBS1770FetchConverter) Close() (err error) {
+ return ff.pipe.Close()
+}
+
+func (ff *FFMpegBS1770FetchConverter) GetResult() (result string, err error, loudnessCorr float64) {
+ if ff.result != nil {
+ r := <-ff.result
+ return r.output, r.err, r.loudnessCorr
+ }
+ return "", nil, 0.0
+}
diff --git a/rhimport/core.go b/rhimport/core.go
index 5dd0355..289857c 100644
--- a/rhimport/core.go
+++ b/rhimport/core.go
@@ -158,7 +158,7 @@ func NewContext(conf *Config, db *rddb.DBChan) *Context {
ctx.AutotrimLevel = conf.ImportParamDefaults.AutotrimLevel
ctx.UseMetaData = conf.ImportParamDefaults.UseMetaData
ctx.AttachmentChan = nil
- ctx.FetchConverter = "ffmpeg"
+ ctx.FetchConverter = "ffmpeg-bs1770"
ctx.OrigFilename = ""
ctx.SourceFile = ""
ctx.DeleteSourceFile = false