if frame size isn't divisable by 2 then use JPEG instead.
This commit is contained in:
@@ -536,24 +536,29 @@ func buildFrame(img *image.RGBA, display int, quality int) (wire.Frame, time.Dur
|
|||||||
codec := blockCodec()
|
codec := blockCodec()
|
||||||
|
|
||||||
if codec == "h264" {
|
if codec == "h264" {
|
||||||
h264Bytes, err := encodeH264Frame(img)
|
if width%2 != 0 || height%2 != 0 {
|
||||||
if err == nil && len(h264Bytes) > 0 {
|
log.Printf("capture: h264 skipped for odd dimensions (%dx%d), falling back to jpeg", width, height)
|
||||||
prevMu.Lock()
|
codec = "jpeg"
|
||||||
copyPrev(img)
|
} else {
|
||||||
prevMu.Unlock()
|
h264Bytes, err := encodeH264Frame(img)
|
||||||
lastKeyframe.Store(now.UnixNano())
|
if err == nil && len(h264Bytes) > 0 {
|
||||||
statFullFrames.Add(1)
|
prevMu.Lock()
|
||||||
return wire.Frame{Type: "frame", Header: wire.FrameHeader{Monitor: display, FPS: 0, Format: "h264"}, Data: h264Bytes}, time.Since(encStart), nil
|
copyPrev(img)
|
||||||
}
|
prevMu.Unlock()
|
||||||
h264WarnOnce.Do(func() {
|
lastKeyframe.Store(now.UnixNano())
|
||||||
detail := h264AvailabilityDetail()
|
statFullFrames.Add(1)
|
||||||
if detail != "" {
|
return wire.Frame{Type: "frame", Header: wire.FrameHeader{Monitor: display, FPS: 0, Format: "h264"}, Data: h264Bytes}, time.Since(encStart), nil
|
||||||
log.Printf("capture: h264 encode unavailable, falling back to jpeg: %v (%s)", err, detail)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
log.Printf("capture: h264 encode unavailable, falling back to jpeg: %v", err)
|
h264WarnOnce.Do(func() {
|
||||||
})
|
detail := h264AvailabilityDetail()
|
||||||
codec = "jpeg"
|
if detail != "" {
|
||||||
|
log.Printf("capture: h264 encode unavailable, falling back to jpeg: %v (%s)", err, detail)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("capture: h264 encode unavailable, falling back to jpeg: %v", err)
|
||||||
|
})
|
||||||
|
codec = "jpeg"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !enableBlocks {
|
if !enableBlocks {
|
||||||
@@ -636,25 +641,30 @@ func buildFrameHVNC(img *image.RGBA, display int, quality int) (wire.Frame, time
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if codec == "h264" {
|
if codec == "h264" {
|
||||||
h264Bytes, err := encodeH264Frame(img)
|
if width%2 != 0 || height%2 != 0 {
|
||||||
if err == nil && len(h264Bytes) > 0 {
|
log.Printf("hvnc capture: h264 skipped for odd dimensions (%dx%d), falling back to jpeg", width, height)
|
||||||
prevMu.Lock()
|
codec = "jpeg"
|
||||||
copyPrev(img)
|
} else {
|
||||||
prevMu.Unlock()
|
h264Bytes, err := encodeH264Frame(img)
|
||||||
lastKeyframe.Store(now.UnixNano())
|
if err == nil && len(h264Bytes) > 0 {
|
||||||
statFullFrames.Add(1)
|
prevMu.Lock()
|
||||||
frame := wire.Frame{Type: "frame", Header: wire.FrameHeader{Monitor: display, FPS: 0, Format: "h264", HVNC: true}, Data: h264Bytes}
|
copyPrev(img)
|
||||||
return frame, time.Since(encStart), nil
|
prevMu.Unlock()
|
||||||
}
|
lastKeyframe.Store(now.UnixNano())
|
||||||
h264WarnOnce.Do(func() {
|
statFullFrames.Add(1)
|
||||||
detail := h264AvailabilityDetail()
|
frame := wire.Frame{Type: "frame", Header: wire.FrameHeader{Monitor: display, FPS: 0, Format: "h264", HVNC: true}, Data: h264Bytes}
|
||||||
if detail != "" {
|
return frame, time.Since(encStart), nil
|
||||||
log.Printf("hvnc capture: h264 encode unavailable, falling back to jpeg: %v (%s)", err, detail)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
log.Printf("hvnc capture: h264 encode unavailable, falling back to jpeg: %v", err)
|
h264WarnOnce.Do(func() {
|
||||||
})
|
detail := h264AvailabilityDetail()
|
||||||
codec = "jpeg"
|
if detail != "" {
|
||||||
|
log.Printf("hvnc capture: h264 encode unavailable, falling back to jpeg: %v (%s)", err, detail)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("hvnc capture: h264 encode unavailable, falling back to jpeg: %v", err)
|
||||||
|
})
|
||||||
|
codec = "jpeg"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prevMu.Lock()
|
prevMu.Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user