Skip to content

Commit

Permalink
thumbnails: png output (#1345)
Browse files Browse the repository at this point in the history
* thumbnails: png output

* fix tests

* lower resolution to 360

* fix tests
  • Loading branch information
gioelecerati authored Aug 2, 2024
1 parent 19a04f7 commit 26ce39a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 2 additions & 4 deletions thumbnails/thumbnails.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"golang.org/x/sync/errgroup"
)

const resolution = "854:480"
const resolution = "640:360"
const vttFilename = "thumbnails.vtt"
const outputDir = "thumbnails"

Expand Down Expand Up @@ -219,8 +219,6 @@ func processSegment(input string, thumbOut string) error {
"vframes": "1",
// video filter to resize
"vf": fmt.Sprintf("scale=%s:force_original_aspect_ratio=decrease", resolution),
// set quality
"q:v": "2",
},
).OverWriteOutput().WithErrorOutput(&ffmpegErr).Run()
}, clients.DownloadRetryBackoff())
Expand Down Expand Up @@ -254,5 +252,5 @@ func thumbFilename(segmentURI string, segmentOffset int64) (string, error) {
if err != nil {
return "", err
}
return fmt.Sprintf("keyframes_%d.jpg", i-segmentOffset), nil
return fmt.Sprintf("keyframes_%d.png", i-segmentOffset), nil
}
20 changes: 10 additions & 10 deletions thumbnails/thumbnails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,31 @@ func testGenerateThumbsRun(t *testing.T, outDir, input string) {

expectedVtt := `WEBVTT
00:00:00.000 --> 00:00:10.000
keyframes_0.jpg
keyframes_0.png
00:00:10.000 --> 00:00:20.000
keyframes_1.jpg
keyframes_1.png
00:00:20.000 --> 00:00:30.000
keyframes_2.jpg
keyframes_2.png
`

vtt, err := os.ReadFile(filepath.Join(outDir, "thumbnails/thumbnails.vtt"))
require.NoError(t, err)
require.Equal(t, expectedVtt, string(vtt))

files, err := filepath.Glob(filepath.Join(outDir, "thumbnails", "*.jpg"))
files, err := filepath.Glob(filepath.Join(outDir, "thumbnails", "*.png"))
require.NoError(t, err)
require.Len(t, files, 3)

for _, file := range files {
data, err := ffprobe.ProbeURL(context.Background(), file)
require.NoError(t, err)
require.Equal(t, "image2", data.Format.FormatName)
require.Equal(t, "png_pipe", data.Format.FormatName)
require.NotNil(t, data.FirstVideoStream())
require.Equal(t, 853, data.FirstVideoStream().Width)
require.Equal(t, 480, data.FirstVideoStream().Height)
require.Equal(t, 640, data.FirstVideoStream().Width)
require.Equal(t, 360, data.FirstVideoStream().Height)
}
}

Expand All @@ -143,19 +143,19 @@ func Test_thumbFilename(t *testing.T) {
name: "index",
segmentURI: "index0.ts",
segmentOffset: 0,
want: "keyframes_0.jpg",
want: "keyframes_0.png",
},
{
name: "clip",
segmentURI: "clip_1.ts",
segmentOffset: 0,
want: "keyframes_1.jpg",
want: "keyframes_1.png",
},
{
name: "clip",
segmentURI: "clip_101.ts",
segmentOffset: 100,
want: "keyframes_1.jpg",
want: "keyframes_1.png",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 26ce39a

Please sign in to comment.