support cgroup for limit resource

This commit is contained in:
wanglei.w
2020-12-03 22:56:04 +08:00
parent 0782179c94
commit ceeee69afe
4 changed files with 191 additions and 0 deletions

33
examples/limitcpu_test.go Normal file
View File

@@ -0,0 +1,33 @@
//+build linux
package examples
import (
"testing"
"github.com/stretchr/testify/assert"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
func ComplexFilterExample(testInputFile, testOverlayFile, testOutputFile string) *ffmpeg.Stream {
split := ffmpeg.Input(testInputFile).VFlip().Split()
split0, split1 := split.Get("0"), split.Get("1")
overlayFile := ffmpeg.Input(testOverlayFile).Crop(10, 10, 158, 112)
return ffmpeg.Concat([]*ffmpeg.Stream{
split0.Trim(ffmpeg.KwArgs{"start_frame": 10, "end_frame": 20}),
split1.Trim(ffmpeg.KwArgs{"start_frame": 30, "end_frame": 40})}).
Overlay(overlayFile.HFlip(), "").
DrawBox(50, 50, 120, 120, "red", 5).
Output(testOutputFile).
OverWriteOutput()
}
// PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
// 1386105 root 20 0 2114152 273780 31672 R 50.2 1.7 0:16.79 ffmpeg
func TestLimitCpu(t *testing.T) {
e := ComplexFilterExample("./sample_data/in1.mp4", "./sample_data/overlay.png", "./sample_data/out2.mp4")
err := e.WithCpuCoreRequest(0.1).WithCpuCoreLimit(0.5).RunLinux()
if err != nil {
assert.Nil(t, err)
}
}