Fixed bugs, now working

This commit is contained in:
Saxon 2019-11-22 13:05:11 +10:30
parent ba25cdfd12
commit e3b6d2101a
4 changed files with 31 additions and 14 deletions

View File

@ -74,7 +74,11 @@ type Extractor struct {
} }
// NewExtractor returns a new Extractor. // NewExtractor returns a new Extractor.
func NewExtractor() *Extractor { return &Extractor{} } func NewExtractor() *Extractor {
return &Extractor{
buf: new(bytes.Buffer),
}
}
// Extract will continously read RTP packets from src containing JPEG (in RTP // Extract will continously read RTP packets from src containing JPEG (in RTP
// payload format) and extract the JPEG images, sending them to dst. This // payload format) and extract the JPEG images, sending them to dst. This
@ -248,7 +252,7 @@ func (b *byteStream) remaining() int {
} }
func (b *byteStream) writeTo(w io.Writer, n int) error { func (b *byteStream) writeTo(w io.Writer, n int) error {
_n,err := w.Write(b.bytes[b.i:n]) _n,err := w.Write(b.bytes[b.i:b.i+n])
b.i += _n b.i += _n
if err != nil { if err != nil {
return err return err

View File

@ -25,6 +25,7 @@ LICENSE
package mjpeg package mjpeg
import ( import (
"bytes"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
@ -35,7 +36,7 @@ const (
codeSOI = 0xd8 // Start of image. codeSOI = 0xd8 // Start of image.
codeDRI = 0xdd // Define restart interval. codeDRI = 0xdd // Define restart interval.
codeDQT = 0xdb // Define quantization tables. codeDQT = 0xdb // Define quantization tables.
codeDHT = 0xde // Define hierarchical progression. codeDHT = 0xc4 // Define huffman tables.
codeSOS = 0xda // Start of scan. codeSOS = 0xda // Start of scan.
codeAPP0 = 0xe0 // TODO: find out what this is. codeAPP0 = 0xe0 // TODO: find out what this is.
codeSOF0 = 0xc0 // Baseline codeSOF0 = 0xc0 // Baseline
@ -165,7 +166,7 @@ func writeHeader(w io.Writer, _type, width, height, nbqTab, dri int, qtable []by
return fmt.Errorf("could not write DRI marker code: %w", err) return fmt.Errorf("could not write DRI marker code: %w", err)
} }
_, err := w.Write([]byte{0x00, 0x04, byte(dri >> 4), byte(dri)}) _, err := w.Write([]byte{0x00, 0x04, byte(dri >> 8), byte(dri)})
if err != nil { if err != nil {
return fmt.Errorf("could not write restart interval value: %w", err) return fmt.Errorf("could not write restart interval value: %w", err)
} }
@ -179,7 +180,7 @@ func writeHeader(w io.Writer, _type, width, height, nbqTab, dri int, qtable []by
// Calculate table size and create slice for table. // Calculate table size and create slice for table.
ts := 2 + nbqTab*(1+64) ts := 2 + nbqTab*(1+64)
_, err = w.Write([]byte{byte(ts >> 4), byte(ts)}) _, err = w.Write([]byte{byte(ts >> 8), byte(ts)})
if err != nil { if err != nil {
return fmt.Errorf("could not write quantization table size: %w", err) return fmt.Errorf("could not write quantization table size: %w", err)
} }
@ -203,14 +204,25 @@ func writeHeader(w io.Writer, _type, width, height, nbqTab, dri int, qtable []by
} }
var me multiError var me multiError
me.add(writeHuffman(w, 0, 0, bitsDCLum, valDC)) buf := new(bytes.Buffer)
me.add(writeHuffman(w, 0, 1, bitsDCChr, valDC)) me.add(writeHuffman(buf, 0, 0, bitsDCLum, valDC))
me.add(writeHuffman(w, 1, 0, bitsACLum, valACLum)) me.add(writeHuffman(buf, 0, 1, bitsDCChr, valDC))
me.add(writeHuffman(w, 1, 1, bitsACChr, valACChr)) me.add(writeHuffman(buf, 1, 0, bitsACLum, valACLum))
me.add(writeHuffman(buf, 1, 1, bitsACChr, valACChr))
if me != nil { if me != nil {
return fmt.Errorf("error writing huffman tables: %w", err) return fmt.Errorf("error writing huffman tables: %w", err)
} }
return nil
l := buf.Len() + 2
_, err = w.Write([]byte{byte(l >> 8), byte(l)})
if err != nil {
return fmt.Errorf("could not write quantization table entry: %w", err)
}
_, err = buf.WriteTo(w)
if err != nil {
return fmt.Errorf("could not write huffman tables: %w", err)
}
// Start of frame. // Start of frame.
err = writeMarker(w, codeSOF0) err = writeMarker(w, codeSOF0)

View File

@ -68,7 +68,7 @@ const (
defaultFrameRate = 25 defaultFrameRate = 25
defaultBitrate = 400 defaultBitrate = 400
defaultVBRBitrate = 400 defaultVBRBitrate = 400
defaultMinFrames = 100 defaultMinFrames = 3
defaultVBRQuality = avconfig.QualityStandard defaultVBRQuality = avconfig.QualityStandard
defaultCameraChan = 2 defaultCameraChan = 2
) )
@ -136,9 +136,10 @@ func (g *GeoVision) Set(c avconfig.Config) error {
c.Bitrate = defaultBitrate c.Bitrate = defaultBitrate
} }
if c.MinFrames <= 0 { refresh := float64(c.MinFrames) / float64(c.FrameRate)
if refresh < 1 || refresh > 5 {
errs = append(errs, errGVBadMinFrames) errs = append(errs, errGVBadMinFrames)
c.MinFrames = defaultMinFrames c.MinFrames = 4 * c.FrameRate
} }
// If we're using RTMP then we should default to constant bitrate. // If we're using RTMP then we should default to constant bitrate.

View File

@ -362,7 +362,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
case codecutil.H265: case codecutil.H265:
r.lexTo = h265.NewLexer(false).Lex r.lexTo = h265.NewLexer(false).Lex
case codecutil.MJPEG: case codecutil.MJPEG:
panic("not implemented") r.lexTo = mjpeg.NewExtractor().Extract
} }
case config.InputAudio: case config.InputAudio: