Skip to content
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

Fix volume option not working #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (

// EncodeOptions is a set of options for encoding dca
type EncodeOptions struct {
Volume int // change audio volume (256=normal)
Volume float32 // change audio volume (1=normal)
Channels int // audio channels
FrameRate int // audio sampling rate (ex 48000)
FrameDuration int // audio frame duration can be 20, 40, or 60 (ms)
Expand Down Expand Up @@ -65,8 +65,9 @@ func (e EncodeOptions) PCMFrameLen() int {

// Validate returns an error if the options are not correct
func (opts *EncodeOptions) Validate() error {
if opts.Volume < 0 || opts.Volume > 512 {
return errors.New("Out of bounds volume (0-512)")

if opts.Volume < 0 || opts.Volume > 2 {
return errors.New("Out of bounds volume (0-2)")
}

if opts.FrameDuration != 20 && opts.FrameDuration != 40 && opts.FrameDuration != 60 {
Expand Down Expand Up @@ -94,7 +95,7 @@ func (opts *EncodeOptions) Validate() error {

// StdEncodeOptions is the standard options for encoding
var StdEncodeOptions = &EncodeOptions{
Volume: 256,
Volume: 1,
Channels: 2,
FrameRate: 48000,
FrameDuration: 20,
Expand Down Expand Up @@ -212,7 +213,6 @@ func (e *EncodeSession) run() {
"-f", "ogg",
"-vbr", vbrStr,
"-compression_level", strconv.Itoa(e.options.CompressionLevel),
"-vol", strconv.Itoa(e.options.Volume),
"-ar", strconv.Itoa(e.options.FrameRate),
"-ac", strconv.Itoa(e.options.Channels),
"-b:a", strconv.Itoa(e.options.Bitrate * 1000),
Expand All @@ -221,6 +221,7 @@ func (e *EncodeSession) run() {
"-packet_loss", strconv.Itoa(e.options.PacketLoss),
"-threads", strconv.Itoa(e.options.Threads),
"-ss", strconv.Itoa(e.options.StartTime),
"-filter:a", fmt.Sprintf("volume=%.2f", e.options.Volume),
}

if e.options.AudioFilter != "" {
Expand Down Expand Up @@ -477,7 +478,7 @@ func (e *EncodeSession) handleStderrLine(line string) {

_, err := fmt.Sscanf(line, "size=%dkB time=%d:%d:%f bitrate=%fkbits/s speed=%fx", &size, &timeH, &timeM, &timeS, &bitrate, &speed)
if err != nil {
logln("Error parsing ffmpeg stats:", err)
//logln("Error parsing ffmpeg stats:", err)
}

dur := time.Duration(timeH) * time.Hour
Expand Down