ffmpeg-go icon indicating copy to clipboard operation
ffmpeg-go copied to clipboard

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

Open f1748x opened this issue 3 years ago • 2 comments

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

f1748x avatar Mar 27 '23 16:03 f1748x

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)
}

IgorRSGraziano avatar Sep 20 '24 03:09 IgorRSGraziano

It helped me,thk u

danepoirier0 avatar Sep 26 '24 08:09 danepoirier0