Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied on RunWithResource #100

Open
dhanielsales opened this issue Aug 21, 2023 · 1 comment
Open

Permission denied on RunWithResource #100

dhanielsales opened this issue Aug 21, 2023 · 1 comment

Comments

@dhanielsales
Copy link

I'm trying to run a command with Run With Resource and i receive a permission denied error like above

OS: Fedora 37
GO version: go1.20.4 linux/amd64

Error:

panic: mkdir /sys/fs/cgroup/cpu,cpuacct/ffmpeg_go_2wtdg9: permission denied

goroutine 47 [running]:
main.main.func1(0x1e)
        /home/dhanielsales/MyProjects/video-preview-progress/main.go:45 +0x432
created by main.main
        /home/dhanielsales/MyProjects/video-preview-progress/main.go:32 +0xc5
panic: mkdir /sys/fs/cgroup/cpu,cpuacct/ffmpeg_go_pg6wsj: permission denied

goroutine 68 [running]:
main.main.func1(0x33)
        /home/dhanielsales/MyProjects/video-preview-progress/main.go:45 +0x432
created by main.main
        /home/dhanielsales/MyProjects/video-preview-progress/main.go:32 +0xc5
exit status 2

Code:

package main

import (
	"encoding/json"
	"fmt"
	"strconv"
	"sync"

	ffmpeg "github.com/u2takey/ffmpeg-go"
)

func main() {
	a, err := ffmpeg.Probe("./video.mp4")
	if err != nil {
		panic(err)
	}

	totalDuration, err := probeDuration(a)
	if err != nil {
		panic(err)
	}

	totalSeconds := int(totalDuration)

	totalIntervals := totalSeconds / 10

	var wg sync.WaitGroup

	wg.Add(totalIntervals)

	for i := 1; i <= totalIntervals; i++ {
		go func(interval int) {
			defer wg.Done()
			currentTime := interval * 10

			if currentTime <= totalSeconds {
				err := ffmpeg.
					Input("./video.mp4").
					Output(fmt.Sprintf("outputs/output%d.jpg", interval), ffmpeg.KwArgs{"ss": fmt.Sprintf("%d", interval*10), "frames:v": "1", "q:v": "2", "vf": "scale=160:96"}).
					OverWriteOutput().
					ErrorToStdOut().
					RunWithResource(0.1, 0.5)

				if err != nil {
					panic(err)
				}
			}
		}(i)
	}

	wg.Wait()
}

type probeFormat struct {
	Duration string `json:"duration"`
}

type probeData struct {
	Format probeFormat `json:"format"`
}

func probeDuration(a string) (float64, error) {
	pd := probeData{}
	err := json.Unmarshal([]byte(a), &pd)

	if err != nil {
		return 0, err
	}

	f, err := strconv.ParseFloat(pd.Format.Duration, 64)

	if err != nil {
		return 0, err
	}

	return f, nil
}

I already try to build and run the code with Sudo but receive the same error.

@ashkan-esz
Copy link

did you managed to fix this? i have the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants