test: ffmpeg select frame and frame(n) filter

This commit is contained in:
Adrian Shum 2022-10-13 17:29:24 +08:00 committed by GitHub
parent a4f23c6560
commit f1b58fd8da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 76 additions and 37 deletions

View file

@ -3,6 +3,7 @@ package ffmpeg
import (
"context"
"encoding/json"
"fmt"
"github.com/cshum/imagor/vips"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -47,7 +48,12 @@ func TestAVContext(t *testing.T) {
require.NoError(t, os.MkdirAll(baseDir+"golden/export", 0755))
t.Parallel()
for _, filename := range files {
t.Run(filename, func(t *testing.T) {
for _, frame := range []int{-1, 5, 9999, 99999} {
name := filename
if frame > -1 {
name = fmt.Sprintf("%s-%d", filename, frame)
}
t.Run(name, func(t *testing.T) {
ctx := context.Background()
path := baseDir + filename
reader, err := os.Open(path)
@ -57,12 +63,19 @@ func TestAVContext(t *testing.T) {
av, err := LoadAVContext(ctx, reader, stats.Size())
require.NoError(t, err)
defer av.Close()
err = av.ProcessFrames()
require.NoError(t, err)
if frame == 9999 {
require.NoError(t, av.ProcessFrames())
}
if frame > -1 {
require.NoError(t, av.SelectFrame(frame))
}
if frame != 9999 {
require.NoError(t, av.ProcessFrames())
}
meta := av.Metadata()
metaBuf, err := json.Marshal(meta)
require.NoError(t, err)
goldenFile := baseDir + "golden/meta/" + filename + ".meta.json"
goldenFile := baseDir + "golden/meta/" + name + ".meta.json"
if curr, err := os.ReadFile(goldenFile); err == nil {
assert.Equal(t, string(curr), string(metaBuf))
} else {
@ -75,13 +88,13 @@ func TestAVContext(t *testing.T) {
require.NoError(t, err)
buf, err = img.ExportJpeg(nil)
require.NoError(t, err)
goldenFile = baseDir + "golden/export/" + filename + ".jpg"
goldenFile = baseDir + "golden/export/" + name + ".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))
}
})
}
}
}

View file

@ -117,12 +117,12 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
for _, filter := range params.Filters {
switch filter.Name {
case "format":
if s := strings.ToLower(filter.Args); s == "webp" || s == "png" {
switch strings.ToLower(filter.Args) {
case "webp", "png", "gif":
switch mime.Extension() {
case ".webm", ".flv", ".mov", ".avi":
bands = 4
}
break
}
case "process_frames":
if err = av.ProcessFrames(); err != nil {

View file

@ -42,6 +42,8 @@ func TestProcessor(t *testing.T) {
})
doGoldenTests(t, filepath.Join(testDataDir, "golden/result"), []test{
{name: "mkv", path: "fit-in/100x100/everybody-betray-me.mkv"},
{name: "mkv specific frame", path: "fit-in/100x100/filters:frame(3)/everybody-betray-me.mkv"},
{name: "mkv specific frame exceeded", path: "fit-in/100x100/filters:frame(99999)/everybody-betray-me.mkv"},
{name: "mkv meta process_frames", path: "meta/filters:process_frames()/everybody-betray-me.mkv"},
{name: "mkv meta", path: "meta/everybody-betray-me.mkv"},
{name: "mp4", path: "200x100/schizo_0.mp4"},

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
testdata/golden/export/macabre.mp4-5.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
testdata/golden/export/schizo.flv-5.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

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

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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View file

@ -0,0 +1 @@
{"orientation":1,"duration":12040,"width":720,"height":576,"fps":25,"selected_frame":5,"has_video":true,"has_audio":false}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":12040,"width":720,"height":576,"fps":25,"selected_frame":99,"has_video":true,"has_audio":false}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":12040,"width":720,"height":576,"fps":25,"selected_frame":99,"has_video":true,"has_audio":false}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":7407,"width":640,"height":480,"fps":30,"selected_frame":5,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":7407,"width":640,"height":480,"fps":30,"selected_frame":99,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":7407,"width":640,"height":480,"fps":30,"selected_frame":99,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":3925,"width":492,"height":360,"fps":30,"selected_frame":5,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":3925,"width":492,"height":360,"fps":30,"selected_frame":29,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":3925,"width":492,"height":360,"fps":30,"selected_frame":29,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2560,"width":480,"height":360,"fps":26,"selected_frame":5,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2560,"width":480,"height":360,"fps":30,"selected_frame":75,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2560,"width":480,"height":360,"fps":30,"selected_frame":75,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2544,"width":480,"height":360,"fps":30,"selected_frame":5,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2544,"width":480,"height":360,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":1,"duration":2544,"width":480,"height":360,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":3,"duration":2544,"width":480,"height":360,"fps":30,"selected_frame":5,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":3,"duration":2544,"width":480,"height":360,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":3,"duration":2544,"width":480,"height":360,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":6,"duration":2544,"width":360,"height":480,"fps":30,"selected_frame":5,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":6,"duration":2544,"width":360,"height":480,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":6,"duration":2544,"width":360,"height":480,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":8,"duration":2544,"width":360,"height":480,"fps":30,"selected_frame":5,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":8,"duration":2544,"width":360,"height":480,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

View file

@ -0,0 +1 @@
{"orientation":8,"duration":2544,"width":360,"height":480,"fps":30,"selected_frame":19,"has_video":true,"has_audio":true}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB