Merge 290506ea37
into 2a437685fc
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 15 KiB |
BIN
internal/media/test/clock-original.gif
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
internal/media/test/clock-processed.gif
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
internal/media/test/clock-thumbnail.webp
Normal file
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |