From 752e8a1359272b95226d90eec37d6aaa7df9658f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wilczy=C5=84ski?= Date: Tue, 26 Mar 2024 15:11:03 +0100 Subject: [PATCH] ffmpeg with nice/ionice --- video/ffmpeg-nice.sh | 4 ++++ video/transmux.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 video/ffmpeg-nice.sh diff --git a/video/ffmpeg-nice.sh b/video/ffmpeg-nice.sh new file mode 100644 index 000000000..89acbeb85 --- /dev/null +++ b/video/ffmpeg-nice.sh @@ -0,0 +1,4 @@ +#!/bin/bash -ex +# Run ffmpeg with low CPU (nice) and IO (ionice) priority +# so it doesn't interfere with other processes too much +nice -n19 ionice -c2 -n7 ffmpeg "$@" diff --git a/video/transmux.go b/video/transmux.go index 814a1152d..cf9f0b13e 100644 --- a/video/transmux.go +++ b/video/transmux.go @@ -25,6 +25,7 @@ func MuxTStoMP4(tsInputFile, mp4OutputFile string) ([]string, error) { // transmux the .ts file into a standalone MP4 file ffmpegErr := bytes.Buffer{} err := ffmpeg.Input(tsInputFile). + SetFfmpegPath("/path/to/ffmpeg-nice.sh"). Output(mp4OutputFile, ffmpeg.KwArgs{ "analyzeduration": "15M", // Analyze up to 15s of video to figure out the format. We saw failures to detect the video codec without this "movflags": "faststart", // Need this for progressive playback and probing @@ -81,7 +82,7 @@ func MuxTStoFMP4(fmp4ManifestOutputFile string, inputs ...string) error { timeout, cancel := context.WithTimeout(context.Background(), 10*time.Minute) defer cancel() - cmd := exec.CommandContext(timeout, "ffmpeg", args...) + cmd := exec.CommandContext(timeout, "/path/to/ffmpeg-nice.sh", args...) var outputBuf bytes.Buffer var stdErr bytes.Buffer