add: live encode progress tracking and read-only status web UI

Stream ffmpeg -progress during the video encode into an in-memory tracker
(internal/status) so the long-running step is no longer a black box: percent,
fps, speed, and ETA are derived from the source duration and updated ~1/s.
Progress prints to stdout only (no logs.db row) to avoid burying real events.

Expose it over HTTP (internal/server, default :8080, set http_addr to "" to
disable): GET /status returns the live snapshot, the pending input queue, and
recent non-debug events; GET / serves an embedded dashboard that polls /status
every second. The server shuts down on the same SIGINT/SIGTERM context as the
watcher.
This commit is contained in:
Esa Kataja
2026-06-21 17:43:00 +03:00
parent 4147cb9470
commit aa8a341069
10 changed files with 740 additions and 8 deletions
+41
View File
@@ -87,6 +87,13 @@ func (l *Logger) Info(message string) {
l.write(LevelInfo, message, "", "")
}
// Progress prints to stdout only, without a db row. For high-frequency,
// ephemeral telemetry (live encode progress) that would otherwise bury real
// events in logs.db and churn until retention purges it.
func (l *Logger) Progress(message string) {
fmt.Fprintf(os.Stdout, "[%s] INFO: %s\n", stamp(), message)
}
func (l *Logger) Error(message, errStr string) {
msg := fmt.Sprintf("%s: %s", message, errStr)
fmt.Fprintf(os.Stderr, "[%s] ERROR: %s\n", stamp(), msg)
@@ -106,6 +113,40 @@ func (l *Logger) Debug(message, file, extra string) {
l.write(LevelDebug, message, file, extra)
}
// LogEntry is one row returned by RecentLogs, shaped for the status feed.
type LogEntry struct {
TS string `json:"ts"`
Level string `json:"level"`
Message string `json:"message"`
File string `json:"file,omitempty"`
}
// RecentLogs returns the newest-first non-debug entries, capped at n. Debug
// rows (per-command ffprobe/ffmpeg/API dumps) are excluded — the status feed
// wants real events, not invocation noise.
func (l *Logger) RecentLogs(n int) ([]LogEntry, error) {
if l.db == nil {
return nil, nil
}
rows, err := l.db.Query(
`SELECT ts, level, message, COALESCE(file, '') FROM logs WHERE level != ? ORDER BY id DESC LIMIT ?`,
LevelDebug, n)
if err != nil {
return nil, err
}
defer rows.Close()
var out []LogEntry
for rows.Next() {
var e LogEntry
if err := rows.Scan(&e.TS, &e.Level, &e.Message, &e.File); err != nil {
return nil, err
}
out = append(out, e)
}
return out, rows.Err()
}
func (l *Logger) Close() {
if l.db == nil {
return