vansante / go-ffprobe

Library to easily get the ffprobe output of a given file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duration of mp4 is wrong when getting metadata (4.2 vs 10)

Minipada opened this issue · comments

Hi,
I'm getting a wrong value for the video duration.

Environment:
Ubuntu 22
ffprobe version n5.1.2 Copyright (c) 2007-2022 the FFmpeg developers
built with gcc 12.2.0 (GCC)

ffprobe -i 2023-01-05T09-19-23.mp4 -show_entries format=duration -v quiet -of csv="p=0"
Gives 10.000

While running

package main

import (
    "os"
	"context"
	"fmt"

	"gopkg.in/vansante/go-ffprobe.v2"
)


func getDurationVideo(path string) float64 {
	fileReader, err := os.Open(path)
	if err != nil {
		fmt.Printf("Could not get open the file\n")
		result := -1.0
		return result
	}

	ctx_dur := context.TODO()
	data, err := ffprobe.ProbeReader(ctx_dur, fileReader)
	if err != nil {
		fmt.Printf("Error getting data: %v", err)
		result := -1.0
		return result
	}
	return data.Format.Duration().Seconds()
}

func main() {
    var dur float64 = getDurationVideo("2023-01-05T09-19-23.mp4")
    fmt.Printf("%f", dur)
}

returns 4.2.

Not sure what's needed to be done. Thanks!

commented

Can you provide the file you tested this with for easier reproduction?

commented

Closing for inactivity, please let me know if you still experience this problem.