revid: revid building and running with audio additions

This commit is contained in:
Trek H 2019-04-24 13:58:56 +09:30
parent 889d440259
commit 3484e35692
3 changed files with 20 additions and 8 deletions

View File

@ -127,7 +127,6 @@ func handleFlags() revid.Config {
heightPtr = flag.Uint("Height", 0, "Height in pixels") heightPtr = flag.Uint("Height", 0, "Height in pixels")
widthPtr = flag.Uint("Width", 0, "Width in pixels") widthPtr = flag.Uint("Width", 0, "Width in pixels")
frameRatePtr = flag.Uint("FrameRate", 0, "Frame rate of captured video") 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") quantizationPtr = flag.Uint("Quantization", 0, "Desired quantization value: 0-40")
intraRefreshPeriodPtr = flag.Uint("IntraRefreshPeriod", 0, "The IntraRefreshPeriod i.e. how many keyframes we send") 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)") 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)") saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)")
exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(revid.ExposureModes[:], ",")+")") 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[:], ",")+")") 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 var outputs flagStrings
@ -192,9 +195,9 @@ func handleFlags() revid.Config {
switch *inputPtr { switch *inputPtr {
case "Audio": case "Audio":
cfg.Rate = float64(*sampleRatePtr*sampleSize) / float64(blockSize) cfg.WriteRate = float64(*sampleRatePtr*sampleSize) / float64(blockSize)
default: default:
cfg.Rate = float64(*frameRatePtr) cfg.WriteRate = float64(*frameRatePtr)
} }
switch *inputCodecPtr { switch *inputCodecPtr {
@ -255,7 +258,6 @@ func handleFlags() revid.Config {
cfg.Height = *heightPtr cfg.Height = *heightPtr
cfg.Width = *widthPtr cfg.Width = *widthPtr
cfg.FrameRate = *frameRatePtr cfg.FrameRate = *frameRatePtr
cfg.SampleRate = *sampleRatePtr
cfg.HttpAddress = *httpAddressPtr cfg.HttpAddress = *httpAddressPtr
cfg.Quantization = *quantizationPtr cfg.Quantization = *quantizationPtr
cfg.IntraRefreshPeriod = *intraRefreshPeriodPtr cfg.IntraRefreshPeriod = *intraRefreshPeriodPtr
@ -265,6 +267,10 @@ func handleFlags() revid.Config {
cfg.Saturation = *saturationPtr cfg.Saturation = *saturationPtr
cfg.Exposure = *exposurePtr cfg.Exposure = *exposurePtr
cfg.AutoWhiteBalance = *autoWhiteBalancePtr cfg.AutoWhiteBalance = *autoWhiteBalancePtr
cfg.SampleRate = *sampleRatePtr
cfg.Channels = *channelsPtr
cfg.RecPeriod = *recPeriodPtr
cfg.BitDepth = *bitDepthPtr
return cfg return cfg
} }

View File

@ -77,7 +77,7 @@ type Config struct {
// Audio // Audio
SampleRate int // Samples a second (Hz). 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. Channels int // Number of audio channels, 1 for mono, 2 for stereo.
BitDepth int // Sample bit depth. BitDepth int // Sample bit depth.
} }
@ -147,7 +147,6 @@ const (
defaultOutput = Http defaultOutput = Http
defaultPacketization = Flv defaultPacketization = Flv
defaultFrameRate = 25 defaultFrameRate = 25
defaultSampleRate = 48000
defaultWriteRate = 25 defaultWriteRate = 25
defaultWidth = 1280 defaultWidth = 1280
defaultHeight = 720 defaultHeight = 720
@ -166,6 +165,11 @@ const (
defaultBrightness = 50 defaultBrightness = 50
defaultExposure = "auto" defaultExposure = "auto"
defaultAutoWhiteBalance = "auto" defaultAutoWhiteBalance = "auto"
defaultSampleRate = 48000
defaultBitDepth = 16
defaultChannels = 1
defaultRecPeriod = 5
) )
// Validate checks for any errors in the config fields and defaults settings // 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 { if c.Quantization > 0 || c.Bitrate == 0 {
return errors.New("bad bitrate or quantization for mjpeg input") return errors.New("bad bitrate or quantization for mjpeg input")
} }
case PCM, ADPCM:
case NothingDefined: case NothingDefined:
c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting",
"inputCodec", defaultInputCodec) "inputCodec", defaultInputCodec)

View File

@ -254,6 +254,8 @@ func (r *Revid) setupPipeline(mtsEnc, flvEnc func(dst io.Writer, rate int) (io.W
r.setupInput = r.startV4L r.setupInput = r.startV4L
case File: case File:
r.setupInput = r.setupInputForFile r.setupInput = r.setupInputForFile
case Audio:
r.setupInput = r.startAudioInput
} }
switch r.config.InputCodec { switch r.config.InputCodec {
@ -678,7 +680,7 @@ func (r *Revid) setupInputForFile() error {
func (r *Revid) startAudioInput() error { func (r *Revid) startAudioInput() error {
ai := NewAudioInput(&r.config) 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 return nil
} }