test: ffmpeg meta and export golden tests

This commit is contained in:
Adrian Shum 2022-09-15 23:43:18 +08:00
parent e0b3c6e4a9
commit 33b76d536d
25 changed files with 82 additions and 0 deletions

74
ffmpeg/ffmpeg_test.go Normal file
View file

@ -0,0 +1,74 @@
package ffmpeg
import (
"context"
"encoding/json"
"github.com/cshum/imagor/vips"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"reflect"
"testing"
)
var files = []struct {
file string
}{
{file: "everybody-betray-me.mkv"},
{file: "alpha-webm.webm"},
{file: "schizo.flv"},
{file: "macabre.mp4"},
{file: "schizo_0.mp4"},
{file: "schizo_90.mp4"},
{file: "schizo_180.mp4"},
{file: "schizo_270.mp4"},
}
var baseDir = "../testdata/"
func TestAVContextMeta(t *testing.T) {
vips.Startup(nil)
require.NoError(t, os.MkdirAll(baseDir+"golden/meta", 0755))
require.NoError(t, os.MkdirAll(baseDir+"golden/result", 0755))
t.Parallel()
for _, tt := range files {
t.Run(tt.file, func(t *testing.T) {
ctx := context.Background()
path := baseDir + tt.file
reader, err := os.Open(path)
require.NoError(t, err)
stats, err := os.Stat(path)
require.NoError(t, err)
av, err := LoadAVContext(ctx, reader, stats.Size())
require.NoError(t, err)
meta := av.Metadata()
metaBuf, err := json.Marshal(meta)
require.NoError(t, err)
goldenFile := baseDir + "golden/meta/" + tt.file + ".meta.json"
if curr, err := os.ReadFile(goldenFile); err == nil {
assert.Equal(t, string(curr), string(metaBuf))
} else {
require.NoError(t, os.WriteFile(goldenFile, metaBuf, 0666))
}
buf, err := av.Export()
require.NoError(t, err)
bands := 3
if meta.HasAlpha {
bands = 4
}
img, err := vips.LoadImageFromMemory(buf, meta.Width, meta.Height, bands)
require.NoError(t, err)
buf, err = img.ExportJpeg(nil)
require.NoError(t, err)
goldenFile = baseDir + "golden/result/" + tt.file + ".jpg"
if curr, err := os.ReadFile(goldenFile); err == nil {
assert.True(t, reflect.DeepEqual(curr, buf))
} else {
require.NoError(t, os.WriteFile(goldenFile, buf, 0666))
}
})
}
}

BIN
testdata/alpha-webm.webm vendored Normal file

Binary file not shown.

BIN
testdata/everybody-betray-me.mkv vendored Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
{"orientation":1,"duration":12040000000,"width":720,"height":576,"has_video":true,"has_audio":false,"has_alpha":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":7407000000,"width":640,"height":480,"has_video":true,"has_audio":true,"has_alpha":false}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":3925000000,"width":492,"height":360,"has_video":true,"has_audio":true,"has_alpha":false}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2560000000,"width":480,"height":360,"has_video":true,"has_audio":true,"has_alpha":false}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2544000000,"width":480,"height":360,"has_video":true,"has_audio":true,"has_alpha":false}

View file

@ -0,0 +1 @@
{"orientation":3,"duration":2544000000,"width":480,"height":360,"has_video":true,"has_audio":true,"has_alpha":false}

View file

@ -0,0 +1 @@
{"orientation":6,"duration":2544000000,"width":360,"height":480,"has_video":true,"has_audio":true,"has_alpha":false}

View file

@ -0,0 +1 @@
{"orientation":8,"duration":2544000000,"width":360,"height":480,"has_video":true,"has_audio":true,"has_alpha":false}

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
testdata/golden/result/macabre.mp4.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
testdata/golden/result/schizo.flv.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
testdata/golden/result/schizo_0.mp4.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
testdata/golden/result/schizo_90.mp4.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
testdata/macabre.mp4 vendored Normal file

Binary file not shown.

BIN
testdata/schizo.flv vendored Normal file

Binary file not shown.

BIN
testdata/schizo_0.mp4 vendored Normal file

Binary file not shown.

BIN
testdata/schizo_180.mp4 vendored Normal file

Binary file not shown.

BIN
testdata/schizo_270.mp4 vendored Normal file

Binary file not shown.

BIN
testdata/schizo_90.mp4 vendored Normal file

Binary file not shown.