Skip to content

Commit

Permalink
ffmpeg with nice/ionice
Browse files Browse the repository at this point in the history
  • Loading branch information
pwilczynskiclearcode committed Mar 26, 2024
1 parent 98aa627 commit 33e8784
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions video/ffmpeg-nice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -ex
# Run ffmpeg with low CPU (nice) and IO (ionice) priority
# so it deosn't interfere with other processes too much
nice -n19 ionice -c2 -n7 ffmpeg "$@"
3 changes: 2 additions & 1 deletion video/transmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 33e8784

Please sign in to comment.