[Go言語] MP4の時間(duration)を取得する

// コマンドラインでffprobeを実行した場合
$ ffprobe src/video.mp4
ffprobe version 4.2.4-1ubuntu0.1 Copyright (c) 2007-2020 the FFmpeg developers
// 省略
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘src/video.mp4’:
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41isomavc1
creation_time : 2021-07-20T06:13:11.000000Z
Duration: 00:00:14.56, start: 0.000000, bitrate: 1530 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280×720, 1527 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
Metadata:
creation_time : 2021-07-20T06:13:11.000000Z
handler_name : L-SMASH Video Handler
encoder : AVC Coding

### goでffprobe
$ go get github.com/vansante/go-ffprobe

package main

import (
	"log"
	"time"
	"context"

	ffprobe "github.com/vansante/go-ffprobe"
)

func main() {
	ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancelFn()

	data, err := ffprobe.ProbeURL(ctx, "src/video.mp4")
	if err != nil {
	    log.Panicf("Error getting data: %v", data)
	}
	log.Print(data.Format.Duration())
	
}

$ go run test.go
2021/11/13 21:37:01 14.56s

mp4が作成された日時とdurationが表示される
OKKKKKKKKKKKKKKKKKKKK