Fix transcoder execution time prints

This commit is contained in:
Zoe Roux 2024-01-29 00:01:30 +01:00
parent b33b428d3b
commit 6ba0786608
3 changed files with 22 additions and 8 deletions

View File

@ -3,14 +3,12 @@ package src
import (
"bufio"
"fmt"
"log"
"math"
"os"
"os/exec"
"strconv"
"strings"
"sync"
"time"
)
type FileStream struct {
@ -67,9 +65,8 @@ func NewFileStream(path string) (*FileStream, error) {
}
func GetKeyframes(path string) ([]float64, bool, error) {
log.Printf("Starting ffprobe for keyframes analysis for %s", path)
defer printExecTime("ffprobe analysis for %s", path)()
// run ffprobe to return all IFrames, IFrames are points where we can split the video in segments.
start := time.Now()
// We ask ffprobe to return the time of each frame and it's flags
// We could ask it to return only i-frames (keyframes) with the -skip_frame nokey but using it is extremly slow
// since ffmpeg parses every frames when this flag is set.
@ -89,7 +86,6 @@ func GetKeyframes(path string) ([]float64, bool, error) {
if err != nil {
return nil, false, err
}
log.Printf("%s ffprobe analysis finished in %s", path, time.Since(start))
scanner := bufio.NewScanner(stdout)
@ -194,7 +190,9 @@ func (fs *FileStream) GetMaster() string {
} else {
master += fmt.Sprintf("NAME=\"Audio %d\",", audio.Index)
}
master += "DEFAULT=YES,"
if audio.IsDefault {
master += "DEFAULT=YES,"
}
master += fmt.Sprintf("URI=\"./audio/%d/index.m3u8\"\n", audio.Index)
}
return master

View File

@ -4,7 +4,6 @@ import (
"crypto/sha1"
"encoding/hex"
"fmt"
"log"
"path/filepath"
"strconv"
"strings"
@ -175,7 +174,7 @@ var SubtitleExtensions = map[string]string{
}
func GetInfo(path string) (*MediaInfo, error) {
log.Printf("Running mediainfo for %s", path)
defer printExecTime("mediainfo for %s", path)()
mi, err := mediainfo.Open(path)
if err != nil {

17
transcoder/src/utils.go Normal file
View File

@ -0,0 +1,17 @@
package src
import (
"fmt"
"log"
"time"
)
func printExecTime(message string, args ...any) func() {
msg := fmt.Sprintf(message, args...)
start := time.Now()
log.Printf("Running %s", msg)
return func() {
log.Printf("%s finished in %s", msg, time.Since(start))
}
}