u2takey / ffmpeg-go

golang binding for ffmpeg
Apache License 2.0
1.72k stars 170 forks source link

Permission denied on RunWithResource #100

Open dhanielsales opened 1 year ago

dhanielsales commented 1 year ago

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 commented 6 months ago

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