mirror of
https://github.com/m1k1o/neko.git
synced 2025-08-02 16:29:55 +02:00
Use VAAPI but its quality is horrible
This commit is contained in:
parent
dead16ac07
commit
a5830dc440
4 changed files with 22 additions and 8 deletions
|
@ -36,7 +36,7 @@ RUN ./build
|
|||
FROM ghcr.io/m1k1o/neko/intel-firefox:latest
|
||||
|
||||
RUN set -eux; apt-get update; \
|
||||
apt-get install -y --no-install-recommends i965-va-driver; \
|
||||
apt-get install -y --no-install-recommends intel-media-va-driver-non-free i965-va-driver-shaders; \
|
||||
#
|
||||
# clean up
|
||||
apt-get clean -y; \
|
||||
|
|
|
@ -30,7 +30,7 @@ import (
|
|||
*/
|
||||
|
||||
const (
|
||||
videoSrc = "ximagesrc display-name=%s show-pointer=true use-damage=false ! video/x-raw,framerate=%d/1 ! videoconvert ! queue ! "
|
||||
videoSrc = "ximagesrc display-name=%s show-pointer=true use-damage=false ! video/x-raw,framerate=%d/1 ! vaapipostproc ! queue ! "
|
||||
audioSrc = "pulsesrc device=%s ! audio/x-raw,channels=2 ! audioconvert ! "
|
||||
)
|
||||
|
||||
|
@ -47,7 +47,7 @@ func NewBroadcastPipeline(device string, display string, pipelineSrc string, url
|
|||
// replace display
|
||||
pipelineStr = strings.Replace(pipelineStr, "{display}", display, -1)
|
||||
} else {
|
||||
pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw,format=NV12 ! x264enc bitrate=%d bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", url, audio, video, 8000)
|
||||
pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw,format=NV12 ! vaapih264enc rate-control=cbr bitrate=%d keyframe-period=180 quality-level=7 ! h264parse ! mux.", url, audio, video, 8000)
|
||||
}
|
||||
|
||||
return pipelineStr, nil
|
||||
|
@ -149,7 +149,7 @@ func NewVideoPipeline(rtpCodec codec.RTPCodec, display string, pipelineSrc strin
|
|||
return "", err
|
||||
}
|
||||
|
||||
pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! vaapih264enc rate-control=vbr bitrate=%d keyframe-period=180 quality-level=7 ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"+pipelineStr, display, fps, bitrate)
|
||||
pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! vaapih264enc rate-control=vbr bitrate=%d keyframe-period=180 quality-level=7 ! h264parse ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"+pipelineStr, display, fps, bitrate)
|
||||
} else if hwenc == config.HwEncNVENC {
|
||||
if err := gst.CheckPlugins([]string{"nvcodec"}); err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -54,6 +54,10 @@ func (c *Client) readPump() {
|
|||
c.conn.SetReadDeadline(time.Now().Add(pongWait))
|
||||
return nil
|
||||
})
|
||||
defer func() {
|
||||
c.hub.unregister <- c
|
||||
c.conn.Close()
|
||||
}()
|
||||
|
||||
for {
|
||||
_, raw, err := c.conn.ReadMessage()
|
||||
|
@ -61,7 +65,7 @@ func (c *Client) readPump() {
|
|||
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
|
||||
log.Printf("error: %v", err)
|
||||
}
|
||||
return
|
||||
break
|
||||
}
|
||||
c.hub.broadcast <- raw
|
||||
}
|
||||
|
@ -71,16 +75,19 @@ func (c *Client) writePump() {
|
|||
ticker := time.NewTicker(pingPeriod)
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
c.hub.unregister <- c
|
||||
close(c.send)
|
||||
c.conn.Close()
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case raw := <-c.send:
|
||||
case raw, ok := <-c.send:
|
||||
c.conn.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
|
||||
if !ok {
|
||||
c.conn.WriteMessage(websocket.CloseMessage, []byte{})
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.conn.WriteMessage(websocket.BinaryMessage, raw); err != nil {
|
||||
log.Printf("Error writing message: %v", err)
|
||||
return
|
||||
|
|
|
@ -22,6 +22,10 @@ func NewHub() *Hub {
|
|||
}
|
||||
}
|
||||
|
||||
func (h *Hub) PrintConns() {
|
||||
log.Printf("Current connections, clients: %d, hosts: %d", len(h.clients), len(h.hosts))
|
||||
}
|
||||
|
||||
func (h *Hub) Run() {
|
||||
for {
|
||||
select {
|
||||
|
@ -41,6 +45,7 @@ func (h *Hub) Run() {
|
|||
h.hosts[client] = true
|
||||
}
|
||||
log.Printf("New connection: %s", client.connectionType)
|
||||
h.PrintConns()
|
||||
case client := <-h.unregister:
|
||||
log.Printf("Disconnecting %s", client.connectionType)
|
||||
|
||||
|
@ -57,7 +62,9 @@ func (h *Hub) Run() {
|
|||
|
||||
if _, ok := pool[client]; ok {
|
||||
delete(pool, client)
|
||||
close(client.send)
|
||||
}
|
||||
h.PrintConns()
|
||||
case raw := <-h.broadcast:
|
||||
for client := range h.hosts {
|
||||
client.send <- raw
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue