diff options
Diffstat (limited to 'internal/media')
| -rw-r--r-- | internal/media/ffmpeg.go | 15 | ||||
| -rw-r--r-- | internal/media/manager.go | 1 | ||||
| -rw-r--r-- | internal/media/manager_test.go | 56 | ||||
| -rw-r--r-- | internal/media/test/gotosocial-processed.avif | bin | 0 -> 3815 bytes | |||
| -rw-r--r-- | internal/media/test/gotosocial-thumbnail.webp | bin | 0 -> 4198 bytes | |||
| -rw-r--r-- | internal/media/test/gotosocial.avif | bin | 0 -> 3815 bytes |
6 files changed, 67 insertions, 5 deletions
diff --git a/internal/media/ffmpeg.go b/internal/media/ffmpeg.go index 676eba9be..05e8c69a6 100644 --- a/internal/media/ffmpeg.go +++ b/internal/media/ffmpeg.go @@ -342,16 +342,21 @@ func (res *result) GetFileType() (gtsmodel.FileType, string, string) { case "mov,mp4,m4a,3gp,3g2,mj2": switch { case len(res.video) > 0: - if len(res.audio) == 0 && - res.duration <= 30 { + switch { + case res.video[0].framerate == 0 && res.video[0].stream.codec == "av1": + // Looks like an avif image. + return gtsmodel.FileTypeImage, + "image/avif", "avif" + case len(res.audio) == 0 && res.duration <= 30: // Short, soundless // video file aka gifv. return gtsmodel.FileTypeGifv, "video/mp4", "mp4" + default: + // Video file (with or without audio). + return gtsmodel.FileTypeVideo, + "video/mp4", "mp4" } - // Video file (with or without audio). - return gtsmodel.FileTypeVideo, - "video/mp4", "mp4" case len(res.audio) > 0 && res.audio[0].codec == "aac": // m4a only supports [aac] audio. diff --git a/internal/media/manager.go b/internal/media/manager.go index a7bd8948b..2ec222f3c 100644 --- a/internal/media/manager.go +++ b/internal/media/manager.go @@ -38,6 +38,7 @@ var SupportedMIMETypes = []string{ "image/jpeg", // .jpeg "image/gif", // .gif "image/webp", // .webp + "image/avif", // .avif "audio/mp2", // .mp2 "audio/mp3", // .mp3 diff --git a/internal/media/manager_test.go b/internal/media/manager_test.go index 6182babbb..f6914acf0 100644 --- a/internal/media/manager_test.go +++ b/internal/media/manager_test.go @@ -789,6 +789,62 @@ func (suite *ManagerTestSuite) TestPngAlphaChannelProcess() { equalFiles(suite.T(), suite.state.Storage, dbAttachment.Thumbnail.Path, "./test/test-png-alphachannel-thumbnail.jpeg") } +func (suite *ManagerTestSuite) TestAvifProcess() { + ctx := suite.T().Context() + + data := func(_ context.Context) (io.ReadCloser, error) { + // load bytes from a test image + b, err := os.ReadFile("./test/gotosocial.avif") + 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: 1038, Height: 980, Size: 1017240, Aspect: 1.0591837, + }, attachment.FileMeta.Original) + suite.EqualValues(gtsmodel.Small{ + Width: 512, Height: 483, Size: 247296, Aspect: 1.0591837, + }, attachment.FileMeta.Small) + suite.Equal("image/avif", attachment.File.ContentType) + suite.Equal("image/webp", attachment.Thumbnail.ContentType) + suite.Equal(3815, attachment.File.FileSize) + suite.Equal(4198, attachment.Thumbnail.FileSize) + suite.Equal("LNQJQ7%M?w-;-pj[bbj[?^ofDiWB", 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/gotosocial-processed.avif") + equalFiles(suite.T(), suite.state.Storage, dbAttachment.Thumbnail.Path, "./test/gotosocial-thumbnail.webp") +} + func (suite *ManagerTestSuite) TestSimpleJpegProcessWithCallback() { ctx := suite.T().Context() diff --git a/internal/media/test/gotosocial-processed.avif b/internal/media/test/gotosocial-processed.avif Binary files differnew file mode 100644 index 000000000..f0433b70b --- /dev/null +++ b/internal/media/test/gotosocial-processed.avif diff --git a/internal/media/test/gotosocial-thumbnail.webp b/internal/media/test/gotosocial-thumbnail.webp Binary files differnew file mode 100644 index 000000000..370ca9d0b --- /dev/null +++ b/internal/media/test/gotosocial-thumbnail.webp diff --git a/internal/media/test/gotosocial.avif b/internal/media/test/gotosocial.avif Binary files differnew file mode 100644 index 000000000..f0433b70b --- /dev/null +++ b/internal/media/test/gotosocial.avif |
