diff --git a/internal/api/client/instance/instancepatch_test.go b/internal/api/client/instance/instancepatch_test.go index e309ff4ca..5eb15820e 100644 --- a/internal/api/client/instance/instancepatch_test.go +++ b/internal/api/client/instance/instancepatch_test.go @@ -858,7 +858,7 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() { "static_url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/attachment/small/`+instanceAccount.AvatarMediaAttachment.ID+`.webp",`+` "thumbnail_static_type": "image/webp", "thumbnail_description": "A bouncing little green peglin.", - "blurhash": "LE9801Rl4Yt5%dWCV]t5Dmoex?WC" + "blurhash": "LF9Hm*Rl4Yt5.4RlRSt5IXkBxsj[" }`, string(instanceV2ThumbnailJson)) // double extra special bonus: now update the image description without changing the image diff --git a/internal/media/ffmpeg.go b/internal/media/ffmpeg.go index f1c277934..ba251bd26 100644 --- a/internal/media/ffmpeg.go +++ b/internal/media/ffmpeg.go @@ -78,23 +78,17 @@ func ffmpegGenerateWebpThumb(ctx context.Context, inpath, outpath string, width, // (NOT as libwebp_anim). "-codec:v", "libwebp", - // Select thumb from first 7 frames. - // (in particular <= 7 reduced memory usage, marginally) - // (thumb filter: https://ffmpeg.org/ffmpeg-filters.html#thumbnail) - "-filter:v", "thumbnail=n=7,"+ + // Only one frame + "-frames:v", "1", - // Scale to dimensions - // (scale filter: https://ffmpeg.org/ffmpeg-filters.html#scale) - "scale="+strconv.Itoa(width)+ - ":"+strconv.Itoa(height)+","+ + // Scale to dimensions + // (scale filter: https://ffmpeg.org/ffmpeg-filters.html#scale) + "-filter:v", "scale="+strconv.Itoa(width)+":"+strconv.Itoa(height)+","+ // Attempt to use original pixel format // (format filter: https://ffmpeg.org/ffmpeg-filters.html#format) "format=pix_fmts="+pixfmt, - // Only one frame - "-frames:v", "1", - // Quality not specified, // i.e. use default which // should be 75% webp quality. diff --git a/internal/media/manager_test.go b/internal/media/manager_test.go index 29ed95ffa..c281b1000 100644 --- a/internal/media/manager_test.go +++ b/internal/media/manager_test.go @@ -428,7 +428,7 @@ func (suite *ManagerTestSuite) TestSlothVineProcess() { suite.Equal("video/mp4", attachment.File.ContentType) suite.Equal("image/webp", attachment.Thumbnail.ContentType) suite.Equal(312453, attachment.File.FileSize) - suite.Equal(5648, attachment.Thumbnail.FileSize) + suite.Equal(5598, attachment.Thumbnail.FileSize) suite.Equal("LgIYH}xtNsofxtfPW.j[_4axn+of", attachment.Blurhash) // now make sure the attachment is in the database @@ -441,6 +441,71 @@ func (suite *ManagerTestSuite) TestSlothVineProcess() { equalFiles(suite.T(), suite.state.Storage, dbAttachment.Thumbnail.Path, "./test/test-mp4-thumbnail.webp") } +func (suite *ManagerTestSuite) TestAnimatedGifProcess() { + ctx := context.Background() + + data := func(_ context.Context) (io.ReadCloser, error) { + // load bytes from a test image + b, err := os.ReadFile("./test/clock-original.gif") + if err != nil { + panic(err) + } + return io.NopCloser(bytes.NewBuffer(b)), nil + } + + accountID := "01FS1X72SK9ZPW0J1QQ68BD264" + + // process the media with no additional info provided + processing, err := suite.manager.CreateMedia(ctx, + accountID, + data, + media.AdditionalMediaInfo{}, + ) + suite.NoError(err) + suite.NotNil(processing) + + // do a blocking call to fetch the attachment + attachment, err := processing.Load(ctx) + suite.NoError(err) + suite.NotNil(attachment) + + // make sure it's got the stuff set on it that we expect + // the attachment ID and accountID we expect + suite.Equal(processing.ID(), attachment.ID) + suite.Equal(accountID, attachment.AccountID) + + // file meta should be correctly derived from the image + suite.EqualValues(gtsmodel.Original{ + Width: 528, + Height: 528, + Size: 278784, + Aspect: 1, + Duration: util.Ptr(float32(8.58)), + Framerate: util.Ptr(float32(16)), + Bitrate: util.Ptr(uint64(114092)), + }, attachment.FileMeta.Original) + suite.EqualValues(gtsmodel.Small{ + Width: 512, + Height: 512, + Size: 262144, + Aspect: 1, + }, attachment.FileMeta.Small) + suite.Equal("image/gif", attachment.File.ContentType) + suite.Equal("image/webp", attachment.Thumbnail.ContentType) + suite.Equal(122364, attachment.File.FileSize) + suite.Equal(12962, attachment.Thumbnail.FileSize) + suite.Equal("LmKUZkt700ofoffQofj[00WBj[WB", attachment.Blurhash) + + // now make sure the attachment is in the database + dbAttachment, err := suite.db.GetAttachmentByID(ctx, attachment.ID) + suite.NoError(err) + suite.NotNil(dbAttachment) + + // ensure the files contain the expected data. + equalFiles(suite.T(), suite.state.Storage, dbAttachment.File.Path, "./test/clock-processed.gif") + equalFiles(suite.T(), suite.state.Storage, dbAttachment.Thumbnail.Path, "./test/clock-thumbnail.webp") +} + func (suite *ManagerTestSuite) TestLongerMp4Process() { ctx := context.Background() @@ -488,8 +553,8 @@ func (suite *ManagerTestSuite) TestLongerMp4Process() { suite.Equal("video/mp4", attachment.File.ContentType) suite.Equal("image/webp", attachment.Thumbnail.ContentType) suite.Equal(109569, attachment.File.FileSize) - suite.Equal(2976, attachment.Thumbnail.FileSize) - suite.Equal("LIQJfl_3IU?b~qM{ofayWBWVofRj", attachment.Blurhash) + suite.Equal(2958, attachment.Thumbnail.FileSize) + suite.Equal("LIQ9}}_3IU?b~qM{ofayWBWVofRj", attachment.Blurhash) // now make sure the attachment is in the database dbAttachment, err := suite.db.GetAttachmentByID(ctx, attachment.ID) @@ -548,8 +613,8 @@ func (suite *ManagerTestSuite) TestBirdnestMp4Process() { suite.Equal("video/mp4", attachment.File.ContentType) suite.Equal("image/webp", attachment.Thumbnail.ContentType) suite.Equal(1409625, attachment.File.FileSize) - suite.Equal(14478, attachment.Thumbnail.FileSize) - suite.Equal("LLF$qyaeRO.9DgM_RPaetkV@WCMw", attachment.Blurhash) + suite.Equal(15056, attachment.Thumbnail.FileSize) + suite.Equal("LLF$nqafRO.9DgM_RPadtkV@WCMx", attachment.Blurhash) // now make sure the attachment is in the database dbAttachment, err := suite.db.GetAttachmentByID(ctx, attachment.ID) diff --git a/internal/media/test/birdnest-thumbnail.webp b/internal/media/test/birdnest-thumbnail.webp index d59e5c26e..3c8861a8f 100644 Binary files a/internal/media/test/birdnest-thumbnail.webp and b/internal/media/test/birdnest-thumbnail.webp differ diff --git a/internal/media/test/clock-original.gif b/internal/media/test/clock-original.gif new file mode 100644 index 000000000..be6a3fdec Binary files /dev/null and b/internal/media/test/clock-original.gif differ diff --git a/internal/media/test/clock-processed.gif b/internal/media/test/clock-processed.gif new file mode 100644 index 000000000..be6a3fdec Binary files /dev/null and b/internal/media/test/clock-processed.gif differ diff --git a/internal/media/test/clock-thumbnail.webp b/internal/media/test/clock-thumbnail.webp new file mode 100644 index 000000000..03b74b622 Binary files /dev/null and b/internal/media/test/clock-thumbnail.webp differ diff --git a/internal/media/test/longer-mp4-thumbnail.webp b/internal/media/test/longer-mp4-thumbnail.webp index a7527c1ec..01a8fa991 100644 Binary files a/internal/media/test/longer-mp4-thumbnail.webp and b/internal/media/test/longer-mp4-thumbnail.webp differ diff --git a/internal/media/test/test-mp4-thumbnail.webp b/internal/media/test/test-mp4-thumbnail.webp index 8b28714c6..11b8f9d89 100644 Binary files a/internal/media/test/test-mp4-thumbnail.webp and b/internal/media/test/test-mp4-thumbnail.webp differ