remove gjson dependency

This commit is contained in:
Connor Baker
2021-10-28 15:12:18 -04:00
parent 2758af6b5d
commit 491575df52
4 changed files with 56 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
package examples
import (
"encoding/json"
"fmt"
"log"
"math/rand"
@@ -12,7 +13,6 @@ import (
"strings"
"time"
"github.com/tidwall/gjson"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
@@ -23,7 +23,10 @@ func ExampleShowProgress(inFileName, outFileName string) {
if err != nil {
panic(err)
}
totalDuration := gjson.Get(a, "format.duration").Float()
totalDuration, err := probeDuration(a)
if err != nil {
panic(err)
}
err = ffmpeg.Input(inFileName).
Output(outFileName, ffmpeg.KwArgs{"c:v": "libx264", "preset": "veryslow"}).
@@ -81,3 +84,24 @@ func TempSock(totalDuration float64) string {
return sockFileName
}
type probeFormat struct {
Duration string `json:"duration"`
}
type probeData struct {
Format probeFormat `json:"format"`
}
func probeDuration(a string) (float64, error) {
pd := probeData{}
err := json.Unmarshal([]byte(a), &pd)
if err != nil {
return 0, err
}
f, err := strconv.ParseFloat(pd.Format.Duration, 64)
if err != nil {
return 0, err
}
return f, nil
}