Skip to content

Commit

Permalink
phasher: initialize ffmpeg and ffprobe only once
Browse files Browse the repository at this point in the history
  • Loading branch information
aghoulcoder committed Jul 4, 2023
1 parent e5b2bbe commit f5a5db4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cmd/phasher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ func customUsage() {
flag.PrintDefaults()
}

func printPhash(inputfile string, quiet *bool) error {
ffmpegPath, ffprobePath := ffmpeg.GetPaths(nil)
FFMPEG := ffmpeg.NewEncoder(ffmpegPath)
FFMPEG.InitHWSupport(context.TODO())

FFPROBE := ffmpeg.FFProbe(ffprobePath)
ffvideoFile, err := FFPROBE.NewVideoFile(inputfile)
func printPhash(ff *ffmpeg.FFMpeg, ffp ffmpeg.FFProbe, inputfile string, quiet *bool) error {
ffvideoFile, err := ffp.NewVideoFile(inputfile)
if err != nil {
return err
}
Expand All @@ -38,7 +33,7 @@ func printPhash(inputfile string, quiet *bool) error {
Duration: ffvideoFile.FileDuration,
}

phash, err := videophash.Generate(FFMPEG, vf)
phash, err := videophash.Generate(ff, vf)
if err != nil {
return err
}
Expand Down Expand Up @@ -75,8 +70,13 @@ func main() {
fmt.Fprintf(os.Stderr, "Example: parallel %v ::: *.mp4\n", os.Args[0])
}

ffmpegPath, ffprobePath := ffmpeg.GetPaths(nil)
FFMPEG := ffmpeg.NewEncoder(ffmpegPath)
FFMPEG.InitHWSupport(context.TODO())
FFPROBE := ffmpeg.FFProbe(ffprobePath)

for _, item := range args {
if err := printPhash(item, quiet); err != nil {
if err := printPhash(FFMPEG, FFPROBE, item, quiet); err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
Expand Down

0 comments on commit f5a5db4

Please sign in to comment.