vansante / go-ffprobe

Library to easily get the ffprobe output of a given file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ffprobe.ProbeReader() can't get video bit_rate, but ffprobe.ProbeURL() can

outer199 opened this issue · comments

Desc

ffprobe.ProbeReader can't get video bit_rate, but ffprobe.ProbeURL

go-ffprobe version

v2.0.3

Video url

https://vd2.bdstatic.com/mda-nc0b8c1h3j8a10xb/sc/cae_h264_delogo/1646122561546642219/mda-nc0b8c1h3j8a10xb.mp4?v_from_s=hkapp-haokan-hna&auth_key=1646278120-0-0-71a75d560bc2a0c1e57650b90229774e&bcevod_channel=searchbox_feed&cd=0&pd=1&pt=3&logid=3520827687&vid=9708211585893377830&abtest=100815_1&klogid=3520827687

Download Video locally

Code

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

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

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

	data, err := ffprobe.ProbeURL(ctx, "/home/aa/aa.mp4")
	if err != nil {
		log.Panicf("Error getting data: %v", err)
	}

	fmt.Println("Filename", data.Format.Filename)
	fmt.Println("BitRate", data.Format.BitRate)
	fmt.Println("FormatName", data.Format.FormatName)
	fmt.Println("DurationSeconds", data.Format.Duration().Seconds())
	fmt.Println("Size", data.Format.Size)
	fmt.Println("ProbeScore", data.Format.ProbeScore)
	fmt.Println("Tags", data.Format.Tags)
	fmt.Println("Width", data.FirstVideoStream().Width)
	fmt.Println("Height", data.FirstVideoStream().Height)

	fmt.Println("--------------------------")

	ctx1, cancelFn1 := context.WithTimeout(context.Background(), 15*time.Second)
	defer cancelFn1()

	fileReader, err := os.Open("/home/aa/aa.mp4")
	if err != nil {
		log.Panicf("Error opening test file: %v", err)
	}
	defer fileReader.Close()

	data1, err := ffprobe.ProbeReader(ctx1, fileReader)
	if err != nil {
		log.Panicf("Error getting data: %v", err)
	}

	fmt.Println("Filename", data1.Format.Filename)
	fmt.Println("BitRate", data1.Format.BitRate)
	fmt.Println("FormatName", data1.Format.FormatName)
	fmt.Println("DurationSeconds", data1.Format.Duration().Seconds())
	fmt.Println("Size", data1.Format.Size)
	fmt.Println("ProbeScore", data1.Format.ProbeScore)
	fmt.Println("Tags", data1.Format.Tags)
	fmt.Println("Width", data1.FirstVideoStream().Width)
	fmt.Println("Height", data1.FirstVideoStream().Height)
}

Prints

Filename /home/aa/aa.mp4
BitRate 195875
FormatName mov,mp4,m4a,3gp,3g2,mj2
DurationSeconds 55.832
Size 1367012
ProbeScore 100
Tags &{isom 512 isomiso2avc1mp41 }
Width 1280
Height 720
--------------------------
Filename pipe:
BitRate 
FormatName mov,mp4,m4a,3gp,3g2,mj2
DurationSeconds 55.832
Size 
ProbeScore 100
Tags &{isom 512 isomiso2avc1mp41 }
Width 1280
Height 720

@outer199 did you ever solve this?

I got same issue. ProbeReader can't get duration, but ProbeURL does.