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

How to obtain the playback duration of MP3 through ffmpeg-go #83

Open
f1748x opened this issue Mar 27, 2023 · 2 comments
Open

How to obtain the playback duration of MP3 through ffmpeg-go #83

f1748x opened this issue Mar 27, 2023 · 2 comments

Comments

@f1748x
Copy link

f1748x commented Mar 27, 2023

How to obtain the playback duration of MP3 through ffmpeg-go.
thanks

@IgorRSGraziano
Copy link

You can get from JSON like (if you want, you can use gjson lib)

func GetDurationFromJson() float32 {
	file := "yourfilepath"

	out, err := ffmpeg.Probe(file, []ffmpeg.KwArgs{
		{"show_entries": "format=duration"},
		{"v": "quiet"},
	}...)

	if err != nil {
		log.Fatal(err)
	}

	var JSONData map[string]interface{}

	json.Unmarshal([]byte(out), &JSONData)

	return JSONData["format"].(map[string]interface{})["duration"].(float32)
}

@danepoirier0
Copy link

It helped me,thk u

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

3 participants