diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index e4019887..97cc8ecc 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -127,7 +127,6 @@ func handleFlags() revid.Config { heightPtr = flag.Uint("Height", 0, "Height in pixels") widthPtr = flag.Uint("Width", 0, "Width in pixels") frameRatePtr = flag.Uint("FrameRate", 0, "Frame rate of captured video") - sampleRatePtr = flag.Uint("SampleRate", 0, "Sample rate of recorded audio") quantizationPtr = flag.Uint("Quantization", 0, "Desired quantization value: 0-40") intraRefreshPeriodPtr = flag.Uint("IntraRefreshPeriod", 0, "The IntraRefreshPeriod i.e. how many keyframes we send") rotationPtr = flag.Uint("Rotation", 0, "Rotate video output. (0-359 degrees)") @@ -135,6 +134,10 @@ func handleFlags() revid.Config { saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)") exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(revid.ExposureModes[:], ",")+")") autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(revid.AutoWhiteBalanceModes[:], ",")+")") + sampleRatePtr = flag.Int("SampleRate", 48000, "Sample rate of recorded audio") + channelsPtr = flag.Int("Channels", 1, "Record in Mono or Stereo (1 or 2)") + recPeriodPtr = flag.Int("recPeriod", 5, "How many seconds to record at a time") + bitDepthPtr = flag.Int("bitDepth", 16, "Bit Depth to record audio at.") ) var outputs flagStrings @@ -192,9 +195,9 @@ func handleFlags() revid.Config { switch *inputPtr { case "Audio": - cfg.Rate = float64(*sampleRatePtr*sampleSize) / float64(blockSize) + cfg.WriteRate = float64(*sampleRatePtr*sampleSize) / float64(blockSize) default: - cfg.Rate = float64(*frameRatePtr) + cfg.WriteRate = float64(*frameRatePtr) } switch *inputCodecPtr { @@ -255,7 +258,6 @@ func handleFlags() revid.Config { cfg.Height = *heightPtr cfg.Width = *widthPtr cfg.FrameRate = *frameRatePtr - cfg.SampleRate = *sampleRatePtr cfg.HttpAddress = *httpAddressPtr cfg.Quantization = *quantizationPtr cfg.IntraRefreshPeriod = *intraRefreshPeriodPtr @@ -265,6 +267,10 @@ func handleFlags() revid.Config { cfg.Saturation = *saturationPtr cfg.Exposure = *exposurePtr cfg.AutoWhiteBalance = *autoWhiteBalancePtr + cfg.SampleRate = *sampleRatePtr + cfg.Channels = *channelsPtr + cfg.RecPeriod = *recPeriodPtr + cfg.BitDepth = *bitDepthPtr return cfg } diff --git a/revid/config.go b/revid/config.go index 63f6d017..ab686e43 100644 --- a/revid/config.go +++ b/revid/config.go @@ -77,7 +77,7 @@ type Config struct { // Audio SampleRate int // Samples a second (Hz). - Period int // How many seconds to record at a time. + RecPeriod int // How many seconds to record at a time. Channels int // Number of audio channels, 1 for mono, 2 for stereo. BitDepth int // Sample bit depth. } @@ -147,7 +147,6 @@ const ( defaultOutput = Http defaultPacketization = Flv defaultFrameRate = 25 - defaultSampleRate = 48000 defaultWriteRate = 25 defaultWidth = 1280 defaultHeight = 720 @@ -166,6 +165,11 @@ const ( defaultBrightness = 50 defaultExposure = "auto" defaultAutoWhiteBalance = "auto" + + defaultSampleRate = 48000 + defaultBitDepth = 16 + defaultChannels = 1 + defaultRecPeriod = 5 ) // Validate checks for any errors in the config fields and defaults settings @@ -208,7 +212,7 @@ func (c *Config) Validate(r *Revid) error { if c.Quantization > 0 || c.Bitrate == 0 { return errors.New("bad bitrate or quantization for mjpeg input") } - + case PCM, ADPCM: case NothingDefined: c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec) diff --git a/revid/revid.go b/revid/revid.go index cda7f127..8b0ea88b 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -254,6 +254,8 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.Writer, rate int) (io.W r.setupInput = r.startV4L case File: r.setupInput = r.setupInputForFile + case Audio: + r.setupInput = r.startAudioInput } switch r.config.InputCodec { @@ -678,7 +680,7 @@ func (r *Revid) setupInputForFile() error { func (r *Revid) startAudioInput() error { ai := NewAudioInput(&r.config) - go r.processFrom(ai, time.Second/time.Duration(r.config.Rate)) + go r.processFrom(ai, time.Second/time.Duration(r.config.WriteRate)) return nil }