From 26ce39aca9b1d781b932e103adb4abddd6cce844 Mon Sep 17 00:00:00 2001 From: gioelecerati <50955448+gioelecerati@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:20:19 +0200 Subject: [PATCH] thumbnails: png output (#1345) * thumbnails: png output * fix tests * lower resolution to 360 * fix tests --- thumbnails/thumbnails.go | 6 ++---- thumbnails/thumbnails_test.go | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/thumbnails/thumbnails.go b/thumbnails/thumbnails.go index a3c6cd44e..306717a22 100644 --- a/thumbnails/thumbnails.go +++ b/thumbnails/thumbnails.go @@ -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" @@ -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()) @@ -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 } diff --git a/thumbnails/thumbnails_test.go b/thumbnails/thumbnails_test.go index 1fc29d5ad..8d7146093 100644 --- a/thumbnails/thumbnails_test.go +++ b/thumbnails/thumbnails_test.go @@ -104,13 +104,13 @@ 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 ` @@ -118,17 +118,17 @@ keyframes_2.jpg 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) } } @@ -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 {