Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
fix(transcoder): rotate transcoder.log to cap its disk usage (#4994)
Gabe Kangas1bc49add0362
diff --git a/.gitignore b/.gitignoreindex f4c6c36f02..8c5c3484ce 100644--- a/.gitignore+++ b/.gitignore@@ -31,7 +31,7 @@ hls/!test/automated/hls/dist/data/-transcoder.log+transcoder.log*owncast.log*chat.db.yp.keydiff --git a/logging/transcoder.go b/logging/transcoder.gonew file mode 100644index 0000000000..d48565c678--- /dev/null+++ b/logging/transcoder.go@@ -0,0 +1,41 @@+package logging++import (+ "io"+ "sync"++ rotatelogs "github.com/lestrrat-go/file-rotatelogs"+ log "github.com/sirupsen/logrus"+)++// Caps the transcoder log's disk usage at roughly maxSize * rotationCount.+const (+ transcoderLogMaxSizeBytes = 10 * 1024 * 1024+ transcoderLogRotationCount = 5+)++var (+ transcoderWriterOnce sync.Once+ transcoderWriter io.Writer+)++// GetTranscoderLogWriter returns the shared size-rotated writer for ffmpeg+// transcoder output.+func GetTranscoderLogWriter(logDirectory string) io.Writer {+ transcoderWriterOnce.Do(func() {+ path := GetTranscoderLogFilePath(logDirectory)+ writer, err := rotatelogs.New(+ path+".%Y%m%d%H%M",+ rotatelogs.WithLinkName(path),+ rotatelogs.WithRotationSize(transcoderLogMaxSizeBytes),+ rotatelogs.WithRotationCount(transcoderLogRotationCount),+ )+ if err != nil {+ log.Errorln("unable to create transcoder log", path, err)+ transcoderWriter = io.Discard+ return+ }+ transcoderWriter = writer+ })+ return transcoderWriter+}diff --git a/services/transcoder/transcoder.go b/services/transcoder/transcoder.goindex bf9d80d957..ed235f9c5b 100644--- a/services/transcoder/transcoder.go+++ b/services/transcoder/transcoder.go@@ -6,10 +6,10 @@ import ("io""net""os/exec"- "runtime""strconv""strings""sync"+ "time"log "github.com/sirupsen/logrus""github.com/teris-io/shortid"@@ -26,11 +26,10 @@ const ffmpegFlagMap = "-map"type execInfo struct {binPath stringcommand []string- environ []string}func (e *execInfo) String() string {- return strings.Join(e.environ, " ") + " " + e.binPath + " " + strings.Join(e.command, " ")+ return e.binPath + " " + strings.Join(e.command, " ")}// Transcoder is a single instance of a video transcoder.@@ -159,7 +158,6 @@ func (t *Transcoder) Start(shouldLog bool) {}t.commandExec = exec.Command(flags.binPath, flags.command...) // nolint: gosec- t.commandExec.Env = flags.environif t.stdin != nil {t.commandExec.Stdin = t.stdin@@ -175,11 +173,17 @@ func (t *Transcoder) Start(shouldLog bool) {log.Panicln(err, command)}+ transcoderLog := logging.GetTranscoderLogWriter(t.cfg.LogDirectory)+ fmt.Fprintf(transcoderLog, "ffmpeg started on %s\nCommand line:\n%s\n", time.Now().Format(time.RFC3339), command)+go func() {scanner := bufio.NewScanner(stdout)for scanner.Scan() {line := scanner.Text()- t.handleTranscoderMessage(line)+ fmt.Fprintln(transcoderLog, line)+ if message, ok := surfaceableTranscoderMessage(line); ok {+ t.handleTranscoderMessage(message)+ }}}()@@ -241,17 +245,11 @@ func (t *Transcoder) getFlags() *execInfo {hlsOptionsString = append(hlsOptionsString, "-hls_flags", strings.Join(hlsOptionFlags, "+"))}- logPath := logging.GetTranscoderLogFilePath(t.cfg.LogDirectory)- reportEnv := fmt.Sprintf(`FFREPORT=file=%s:level=32`, logPath)- if runtime.GOOS == "windows" {- logPath = strings.ReplaceAll(logPath, "\\", "/")- reportEnv = fmt.Sprintf(`FFREPORT=file=%s:level=32`, logPath)- }- environ := []string{- reportEnv,- }ffmpegFlags := make([]string, 0, 64)- ffmpegFlags = append(ffmpegFlags, "-hide_banner", "-loglevel", "warning")+ // level+info tags each stderr line with its log level so the scanner can+ // separate diagnostic output (kept in transcoder.log) from problems that+ // get surfaced to the owncast log.+ ffmpegFlags = append(ffmpegFlags, "-hide_banner", "-nostats", "-loglevel", "level+info")ffmpegFlags = append(ffmpegFlags, t.codec.GlobalFlags()...)ffmpegFlags = append(ffmpegFlags, []string{"-fflags", "+genpts", // Generate presentation time stamp if missing@@ -293,7 +291,6 @@ func (t *Transcoder) getFlags() *execInfo {return &execInfo{binPath: t.ffmpegPath,command: ffmpegFlags,- environ: environ,}}diff --git a/services/transcoder/transcoderMessage_test.go b/services/transcoder/transcoderMessage_test.gonew file mode 100644index 0000000000..48f6b229e8--- /dev/null+++ b/services/transcoder/transcoderMessage_test.go@@ -0,0 +1,57 @@+package transcoder++import "testing"++// TestSurfaceableTranscoderMessage proves the stderr classification contract+// under ffmpeg's `-loglevel level+info`: diagnostic levels are suppressed,+// problem levels are surfaced with only the level tag (and its trailing+// space) removed so errorMap/ignoredErrors substring matching still sees the+// original message text, and rare untagged lines pass through verbatim.+func TestSurfaceableTranscoderMessage(t *testing.T) {+ cases := []struct {+ name string+ line string+ want string+ wantOK bool+ }{+ {+ "plain info suppressed",+ "[info] Stream mapping:",+ "", false,+ },+ {+ "component-prefixed info suppressed",+ "[hls @ 0x55d3] [info] Opening '/x/stream0.ts' for writing",+ "", false,+ },+ {+ "warning surfaced with tag stripped",+ "[warning] VBV underflow (frame 12, -224 bits)",+ "VBV underflow (frame 12, -224 bits)", true,+ },+ {+ "component-prefixed error keeps component tag",+ "[flv @ 0x1] [error] Failed to open file 'http://127.0.0.1'",+ "[flv @ 0x1] Failed to open file 'http://127.0.0.1'", true,+ },+ {+ "untagged line surfaced verbatim",+ "Press [q] to stop, [?] for help",+ "Press [q] to stop, [?] for help", true,+ },+ {+ "fatal surfaced stripped",+ "[fatal] Unable to find a suitable output format for 'pipe:'",+ "Unable to find a suitable output format for 'pipe:'", true,+ },+ }++ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ got, ok := surfaceableTranscoderMessage(tc.line)+ if got != tc.want || ok != tc.wantOK {+ t.Errorf("surfaceableTranscoderMessage(%q) = (%q, %v), want (%q, %v)", tc.line, got, ok, tc.want, tc.wantOK)+ }+ })+ }+}diff --git a/services/transcoder/transcoder_nvenc_test.go b/services/transcoder/transcoder_nvenc_test.goindex 1981804a15..5fd426cce8 100644--- a/services/transcoder/transcoder_nvenc_test.go+++ b/services/transcoder/transcoder_nvenc_test.go@@ -43,8 +43,7 @@ func TestFFmpegNvencCommand(t *testing.T) {cmd := transcoder.GetString()- expectedLogPath := "data/logs/transcoder.log"- expected := `FFREPORT=file=` + expectedLogPath + `:level=32 ` + transcoder.ffmpegPath + ` -hide_banner -loglevel warning -hwaccel cuda -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_nvenc -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -tune:v:0 ll -map a:0? -c:a:0 copy -preset p3 -map v:0 -c:v:1 h264_nvenc -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -tune:v:1 ll -map a:0? -c:a:1 copy -preset p5 -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset p1 -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt yuv420p -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdoieGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`+ expected := transcoder.ffmpegPath + ` -hide_banner -nostats -loglevel level+info -hwaccel cuda -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_nvenc -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -tune:v:0 ll -map a:0? -c:a:0 copy -preset p3 -map v:0 -c:v:1 h264_nvenc -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -tune:v:1 ll -map a:0? -c:a:1 copy -preset p5 -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset p1 -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt yuv420p -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdoieGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`if cmd != expected {t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)diff --git a/services/transcoder/transcoder_omx_test.go b/services/transcoder/transcoder_omx_test.goindex 1f547ba161..ef7be62dfe 100644--- a/services/transcoder/transcoder_omx_test.go+++ b/services/transcoder/transcoder_omx_test.go@@ -43,8 +43,7 @@ func TestFFmpegOmxCommand(t *testing.T) {cmd := transcoder.GetString()- expectedLogPath := "data/logs/transcoder.log"- expected := `FFREPORT=file=` + expectedLogPath + `:level=32 ` + transcoder.ffmpegPath + ` -hide_banner -loglevel warning -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_omx -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -map a:0? -c:a:0 copy -preset veryfast -map v:0 -c:v:1 h264_omx -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -tune zerolatency -pix_fmt yuv420p -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdFsdfzGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`+ expected := transcoder.ffmpegPath + ` -hide_banner -nostats -loglevel level+info -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_omx -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -map a:0? -c:a:0 copy -preset veryfast -map v:0 -c:v:1 h264_omx -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -tune zerolatency -pix_fmt yuv420p -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdFsdfzGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`if cmd != expected {t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)diff --git a/services/transcoder/transcoder_qsv_test.go b/services/transcoder/transcoder_qsv_test.goindex 20fa3a9bee..c9064d1803 100644--- a/services/transcoder/transcoder_qsv_test.go+++ b/services/transcoder/transcoder_qsv_test.go@@ -43,8 +43,7 @@ func TestFFmpegQuicksyncCommand(t *testing.T) {cmd := transcoder.GetString()- expectedLogPath := "data/logs/transcoder.log"- expected := `FFREPORT=file=` + expectedLogPath + `:level=32 ` + transcoder.ffmpegPath + ` -hide_banner -loglevel warning -init_hw_device qsv=hw -filter_hw_device hw -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_qsv -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -map a:0? -c:a:0 copy -filter:v:0 hwupload=extra_hw_frames=64,format=qsv -preset medium -map v:0 -c:v:1 h264_qsv -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -filter:v:1 hwupload=extra_hw_frames=64,format=qsv -preset veryslow -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset veryfast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt qsv -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`+ expected := transcoder.ffmpegPath + ` -hide_banner -nostats -loglevel level+info -init_hw_device qsv=hw -filter_hw_device hw -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_qsv -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -map a:0? -c:a:0 copy -filter:v:0 hwupload=extra_hw_frames=64,format=qsv -preset medium -map v:0 -c:v:1 h264_qsv -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -filter:v:1 hwupload=extra_hw_frames=64,format=qsv -preset veryslow -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset veryfast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt qsv -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`if cmd != expected {t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)diff --git a/services/transcoder/transcoder_vaapi_test.go b/services/transcoder/transcoder_vaapi_test.goindex 38db9c081a..9627dcbe8e 100644--- a/services/transcoder/transcoder_vaapi_test.go+++ b/services/transcoder/transcoder_vaapi_test.go@@ -43,8 +43,7 @@ func TestFFmpegVaapiCommand(t *testing.T) {cmd := transcoder.GetString()- expectedLogPath := "data/logs/transcoder.log"- expected := `FFREPORT=file=` + expectedLogPath + `:level=32 ` + transcoder.ffmpegPath + ` -hide_banner -loglevel warning -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_vaapi -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -map a:0? -c:a:0 copy -filter:v:0 hwupload=extra_hw_frames=64,format=vaapi -preset veryfast -map v:0 -c:v:1 h264_vaapi -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -filter:v:1 hwupload=extra_hw_frames=64,format=vaapi -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt vaapi -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`+ expected := transcoder.ffmpegPath + ` -hide_banner -nostats -loglevel level+info -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_vaapi -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -map a:0? -c:a:0 copy -filter:v:0 hwupload=extra_hw_frames=64,format=vaapi -preset veryfast -map v:0 -c:v:1 h264_vaapi -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -filter:v:1 hwupload=extra_hw_frames=64,format=vaapi -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt vaapi -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`if cmd != expected {t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)diff --git a/services/transcoder/transcoder_videotoolbox_test.go b/services/transcoder/transcoder_videotoolbox_test.goindex 352a63296b..ece760216d 100644--- a/services/transcoder/transcoder_videotoolbox_test.go+++ b/services/transcoder/transcoder_videotoolbox_test.go@@ -43,8 +43,7 @@ func TestFFmpegVideoToolboxCommand(t *testing.T) {cmd := transcoder.GetString()- expectedLogPath := "data/logs/transcoder.log"- expected := `FFREPORT=file=` + expectedLogPath + `:level=32 ` + transcoder.ffmpegPath + ` -hide_banner -loglevel warning -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_videotoolbox -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -realtime true -map a:0? -c:a:0 copy -preset veryfast -map v:0 -c:v:1 h264_videotoolbox -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt nv12 -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdFsdfzGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`+ expected := transcoder.ffmpegPath + ` -hide_banner -nostats -loglevel level+info -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 h264_videotoolbox -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -realtime true -map a:0? -c:a:0 copy -preset veryfast -map v:0 -c:v:1 h264_videotoolbox -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -map a:0? -c:a:1 copy -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -pix_fmt nv12 -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdFsdfzGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`if cmd != expected {t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)diff --git a/services/transcoder/transcoder_x264_test.go b/services/transcoder/transcoder_x264_test.goindex 0c5d41e1eb..74d625b7d3 100644--- a/services/transcoder/transcoder_x264_test.go+++ b/services/transcoder/transcoder_x264_test.go@@ -43,8 +43,7 @@ func TestFFmpegx264Command(t *testing.T) {cmd := transcoder.GetString()- expectedLogPath := "data/logs/transcoder.log"- expected := `FFREPORT=file=` + expectedLogPath + `:level=32 ` + transcoder.ffmpegPath + ` -hide_banner -loglevel warning -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 libx264 -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -x264-params:v:0 scenecut=0:open_gop=0 -bufsize:v:0 1088k -profile:v:0 high -map a:0? -c:a:0 copy -preset veryfast -map v:0 -c:v:1 libx264 -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -x264-params:v:1 scenecut=0:open_gop=0 -bufsize:v:1 3572k -profile:v:1 high -map a:0? -c:a:1 copy -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -tune zerolatency -pix_fmt yuv420p -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`+ expected := transcoder.ffmpegPath + ` -hide_banner -nostats -loglevel level+info -fflags +genpts -flags +cgop -i fakecontent.flv -map v:0 -c:v:0 libx264 -b:v:0 1008k -maxrate:v:0 1088k -g:v:0 90 -keyint_min:v:0 90 -r:v:0 30 -x264-params:v:0 scenecut=0:open_gop=0 -bufsize:v:0 1088k -profile:v:0 high -map a:0? -c:a:0 copy -preset veryfast -map v:0 -c:v:1 libx264 -b:v:1 3308k -maxrate:v:1 3572k -g:v:1 72 -keyint_min:v:1 72 -r:v:1 24 -x264-params:v:1 scenecut=0:open_gop=0 -bufsize:v:1 3572k -profile:v:1 high -map a:0? -c:a:1 copy -preset fast -map v:0 -c:v:2 copy -map a:0? -c:a:2 copy -preset ultrafast -var_stream_map v:0,a:0 v:1,a:1 v:2,a:2 -f hls -hls_time 3 -hls_list_size 10 -hls_flags program_date_time+independent_segments+omit_endlist -segment_format_options mpegts_flags=mpegts_copyts=1 -tune zerolatency -pix_fmt yuv420p -sc_threshold 0 -master_pl_name stream.m3u8 -hls_segment_filename http://127.0.0.1:8123/%v/stream-jdofFGg-%d.ts -max_muxing_queue_size 400 -method PUT http://127.0.0.1:8123/%v/stream.m3u8`if cmd != expected {t.Errorf("ffmpeg command does not match expected.\nGot %s\n, want: %s", cmd, expected)diff --git a/services/transcoder/utils.go b/services/transcoder/utils.goindex 95fd69882f..766ab1c2c5 100644--- a/services/transcoder/utils.go+++ b/services/transcoder/utils.go@@ -57,6 +57,29 @@ var ignoredErrors = []string{"Failed to allocate a vaapi/nv12 frame from a fixed pool of hardware frames.",}+// Levels emitted by ffmpeg's "level" loglevel flag that are diagnostic+// output only, not problems to surface to the owncast log.+var quietLogLevels = []string{"[info]", "[verbose]", "[debug]", "[trace]"}++var surfacedLogLevels = []string{"[warning] ", "[error] ", "[fatal] ", "[panic] "}++// surfaceableTranscoderMessage reports whether a transcoder stderr line+// represents a problem worth surfacing to the owncast log. It returns the+// message with its level tag removed so it matches the message shapes+// errorMap and ignoredErrors expect. Untagged lines are surfaced as-is.+func surfaceableTranscoderMessage(line string) (string, bool) {+ for _, level := range quietLogLevels {+ if strings.Contains(line, level) {+ return "", false+ }+ }+ message := line+ for _, level := range surfacedLogLevels {+ message = strings.Replace(message, level, "", 1)+ }+ return message, true+}+func (t *Transcoder) handleTranscoderMessage(message string) {log.Debugln(message)