Skip to content

Commit 5e49103

Browse files
committed
Fixing timecode formatting for ffmpeg
1 parent 4f6dca3 commit 5e49103

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

main.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ func (args *Args) renderFfmpeg(_ io.Reader, pathName string) (image.Image, error
310310
return nil, errors.New("ffmpeg not in path")
311311
}
312312
// ffmpeg -loglevel panic -hide_banner -ss $t -i *.mkv -vframes 1 -q:v 1
313+
tc := args.ffprobeTimecode(pathName)
314+
args.logger("snapshot at %v", tc)
313315
params := []string{
314316
`-hide_banner`,
315-
`-ss`, args.ffprobeTimecode(pathName),
317+
`-ss`, tc,
316318
`-i`, pathName,
317319
`-vframes`, `1`,
318320
`-q:v`, `1`,
@@ -365,7 +367,9 @@ func (args *Args) ffprobeTimecode(pathName string) string {
365367
if err != nil {
366368
return "00:00"
367369
}
368-
switch dur := time.Duration(f * float64(time.Second)); {
370+
dur := time.Duration(f * float64(time.Second))
371+
args.logger("ffprobe duration: %v / %s", dur, formatTimecode(dur))
372+
switch {
369373
case dur >= 1*time.Hour:
370374
return "10:00"
371375
case dur >= 30*time.Minute:
@@ -390,8 +394,8 @@ func formatTimecode(d time.Duration) string {
390394
if d == 0 {
391395
return "00:00"
392396
}
393-
secs := int64(float64(d) / float64(time.Minute))
394-
rem := int64((float64(d) / float64(time.Minute)) * float64(time.Minute))
397+
secs := int64(d / time.Minute)
398+
rem := int64((d % time.Minute) / time.Second)
395399
return fmt.Sprintf("%02d:%02d", secs, rem)
396400
}
397401

0 commit comments

Comments
 (0)