mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-17 22:00:42 +08:00
Improve ascii stream for any one symbol
This commit is contained in:
@@ -9,18 +9,19 @@
|
|||||||
- escape text param with urlencode
|
- escape text param with urlencode
|
||||||
- you can stream any camera or file from a disc
|
- you can stream any camera or file from a disc
|
||||||
|
|
||||||
**go2rtc.yaml** - transcoding to MJPEG, terminal size - 210x60, fps - 4
|
**go2rtc.yaml** - transcoding to MJPEG, terminal size - 210x59 (16/9), fps - 10
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
streams:
|
streams:
|
||||||
macarena: ffmpeg:macarena.mp4#video=mjpeg#hardware#width=210#height=60#raw=-r 4
|
macarena: ffmpeg:macarena.mp4#video=mjpeg#hardware#width=210#height=59#raw=-r 10
|
||||||
```
|
```
|
||||||
|
|
||||||
**API params**
|
**API params**
|
||||||
|
|
||||||
- `color` - foreground color, values: empty, `8`, `256`, `rgb`
|
- `color` - foreground color, values: empty, `8`, `256`, `rgb`
|
||||||
- `back` - background color, values: empty, `8`, `256`, `rgb`
|
- `back` - background color, values: empty, `8`, `256`, `rgb`
|
||||||
- `text` - character set, values: empty, one space, two spaces, anything you like (in order of brightness)
|
- `text` - character set, values: empty, one char, `block`, list of chars (in order of brightness)
|
||||||
|
- example: `%20` (space), `block` (block elements), `ox` (two chars)
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
|
@@ -61,35 +61,30 @@ func NewWriter(w io.Writer, foreground, background, text string) io.Writer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ascii string
|
if len(text) == 1 {
|
||||||
switch text {
|
// fast 1 symbol version
|
||||||
case "":
|
a.text = func(_, _, _ uint32) {
|
||||||
ascii = ` .::--~~==++**##%%$@`
|
a.buf = append(a.buf, text[0])
|
||||||
case " ":
|
|
||||||
a.text = func(r, g, b uint32) {
|
|
||||||
a.buf = append(a.buf, ' ')
|
|
||||||
}
|
}
|
||||||
case " ":
|
} else {
|
||||||
a.text = func(r, g, b uint32) {
|
switch text {
|
||||||
a.buf = append(a.buf, ' ', ' ')
|
case "":
|
||||||
|
text = ` .::--~~==++**##%%$@` // default for empty text
|
||||||
|
case "block":
|
||||||
|
text = " ░░▒▒▓▓█" // https://en.wikipedia.org/wiki/Block_Elements
|
||||||
}
|
}
|
||||||
case "block":
|
|
||||||
ascii = " ░░▒▒▓▓█" // https://en.wikipedia.org/wiki/Block_Elements
|
if runes := []rune(text); len(runes) != len(text) {
|
||||||
default:
|
|
||||||
ascii = text
|
|
||||||
}
|
|
||||||
if ascii != "" {
|
|
||||||
if runes := []rune(ascii); len(runes) != len(ascii) {
|
|
||||||
k := float32(len(runes)-1) / 255
|
k := float32(len(runes)-1) / 255
|
||||||
a.text = func(r, g, b uint32) {
|
a.text = func(r, g, b uint32) {
|
||||||
i := gray(r, g, b, k)
|
i := gray(r, g, b, k)
|
||||||
a.buf = utf8.AppendRune(a.buf, runes[i])
|
a.buf = utf8.AppendRune(a.buf, runes[i])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
k := float32(len(ascii)-1) / 255
|
k := float32(len(text)-1) / 255
|
||||||
a.text = func(r, g, b uint32) {
|
a.text = func(r, g, b uint32) {
|
||||||
i := gray(r, g, b, k)
|
i := gray(r, g, b, k)
|
||||||
a.buf = append(a.buf, ascii[i])
|
a.buf = append(a.buf, text[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,7 +125,7 @@ func (a *writer) Write(p []byte) (n int, err error) {
|
|||||||
a.buf = append(a.buf, '\n')
|
a.buf = append(a.buf, '\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
a.buf = append(a.buf, "\033[0m\n"...)
|
a.buf = append(a.buf, "\033[0m"...)
|
||||||
|
|
||||||
if n, err = a.wr.Write(a.buf); err == nil {
|
if n, err = a.wr.Write(a.buf); err == nil {
|
||||||
a.wr.(http.Flusher).Flush()
|
a.wr.(http.Flusher).Flush()
|
||||||
|
Reference in New Issue
Block a user