From 252ef43f6202bec44ff46fc4c0a2510938cfa457 Mon Sep 17 00:00:00 2001 From: David Thorpe Date: Sun, 30 Jun 2024 19:50:20 +0200 Subject: [PATCH] Some more fixes --- go.mod | 1 + manager.go | 29 +--------------------- manager_test.go | 14 ----------- pkg/ffmpeg/rescaler_test.go | 2 +- pkg/generator/yuv420p_test.go | 6 ++--- pkg/version/version.go | 45 +++++++++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 46 deletions(-) diff --git a/go.mod b/go.mod index f0e0ff2..56f2997 100755 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/djthorpe/go-tablewriter v0.0.8 github.com/mutablelogic/go-client v1.0.8 github.com/stretchr/testify v1.9.0 + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 ) require ( diff --git a/manager.go b/manager.go index 10af4e6..bf1373f 100644 --- a/manager.go +++ b/manager.go @@ -4,10 +4,8 @@ import ( "errors" "fmt" "io" - "runtime" // Package imports - version "github.com/mutablelogic/go-media/pkg/version" ff "github.com/mutablelogic/go-media/sys/ffmpeg61" ) @@ -312,32 +310,7 @@ func (manager *manager) Write(w io.Writer, format Format, metadata []Metadata, p // Return version information for the media manager as a set of metadata func (manager *manager) Version() []Metadata { - metadata := []Metadata{ - newMetadata("libavcodec_version", ffVersionAsString(ff.AVCodec_version())), - newMetadata("libavformat_version", ffVersionAsString(ff.AVFormat_version())), - newMetadata("libavutil_version", ffVersionAsString(ff.AVUtil_version())), - newMetadata("libavdevice_version", ffVersionAsString(ff.AVDevice_version())), - // newMetadata("libavfilter_version", ff.AVFilter_version()), - newMetadata("libswscale_version", ffVersionAsString(ff.SWScale_version())), - newMetadata("libswresample_version", ffVersionAsString(ff.SWResample_version())), - } - if version.GitSource != "" { - metadata = append(metadata, newMetadata("git_source", version.GitSource)) - } - if version.GitBranch != "" { - metadata = append(metadata, newMetadata("git_branch", version.GitBranch)) - } - if version.GitTag != "" { - metadata = append(metadata, newMetadata("git_tag", version.GitTag)) - } - if version.GoBuildTime != "" { - metadata = append(metadata, newMetadata("go_build_time", version.GoBuildTime)) - } - if runtime.Version() != "" { - metadata = append(metadata, newMetadata("go_version", runtime.Version())) - metadata = append(metadata, newMetadata("go_arch", runtime.GOOS+"/"+runtime.GOARCH)) - } - return metadata + return nil } // Log error messages diff --git a/manager_test.go b/manager_test.go index 37f1994..9bf3a8e 100644 --- a/manager_test.go +++ b/manager_test.go @@ -39,20 +39,6 @@ func Test_manager_002(t *testing.T) { t.Log(formats) } -func Test_manager_003(t *testing.T) { - assert := assert.New(t) - - manager, err := NewManager() - if !assert.NoError(err) { - t.SkipNow() - } - - version := manager.Version() - assert.NotNil(version) - - tablewriter.New(os.Stderr, tablewriter.OptHeader(), tablewriter.OptOutputText()).Write(version) -} - func Test_manager_004(t *testing.T) { assert := assert.New(t) diff --git a/pkg/ffmpeg/rescaler_test.go b/pkg/ffmpeg/rescaler_test.go index 46930e3..e90307e 100644 --- a/pkg/ffmpeg/rescaler_test.go +++ b/pkg/ffmpeg/rescaler_test.go @@ -53,7 +53,7 @@ func Test_rescaler_002(t *testing.T) { assert := assert.New(t) // Create an image generator - image, err := generator.NewYUV420P(ffmpeg.VideoPar("yuva420p", "1280x720", 25)) + image, err := generator.NewYUV420P(ffmpeg.VideoPar("yuv420p", "1280x720", 25)) if !assert.NoError(err) { t.FailNow() } diff --git a/pkg/generator/yuv420p_test.go b/pkg/generator/yuv420p_test.go index 8d037d1..32b46da 100644 --- a/pkg/generator/yuv420p_test.go +++ b/pkg/generator/yuv420p_test.go @@ -14,7 +14,7 @@ import ( func Test_yuv420p_001(t *testing.T) { assert := assert.New(t) - image, err := generator.NewYUV420P(25, ffmpeg.VideoPar("yuva420p", "1280x720")) + image, err := generator.NewYUV420P(ffmpeg.VideoPar("yuv420p", "1280x720", 25)) if !assert.NoError(err) { t.FailNow() } @@ -25,7 +25,7 @@ func Test_yuv420p_001(t *testing.T) { func Test_yuv420p_002(t *testing.T) { assert := assert.New(t) - image, err := generator.NewYUV420P(25, ffmpeg.VideoPar("yuva420p", "1280x720")) + image, err := generator.NewYUV420P(ffmpeg.VideoPar("yuv420p", "1280x720", 25)) if !assert.NoError(err) { t.FailNow() } @@ -39,7 +39,7 @@ func Test_yuv420p_002(t *testing.T) { func Test_yuv420p_003(t *testing.T) { assert := assert.New(t) - image, err := generator.NewYUV420P(25, ffmpeg.VideoPar("yuva420p", "1280x720")) + image, err := generator.NewYUV420P(ffmpeg.VideoPar("yuv420p", "1280x720", 25)) if !assert.NoError(err) { t.FailNow() } diff --git a/pkg/version/version.go b/pkg/version/version.go index cc3e270..cb16017 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,8 +1,53 @@ package version +import ( + "fmt" + "runtime" + + ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg" + ff "github.com/mutablelogic/go-media/sys/ffmpeg61" +) + var ( GitSource string GitTag string GitBranch string GoBuildTime string ) + +// Return version information as a set of metadata +func Version() []*ffmpeg.Metadata { + metadata := []*ffmpeg.Metadata{ + ffmpeg.NewMetadata("libavcodec_version", ffVersionAsString(ff.AVCodec_version())), + ffmpeg.NewMetadata("libavformat_version", ffVersionAsString(ff.AVFormat_version())), + ffmpeg.NewMetadata("libavutil_version", ffVersionAsString(ff.AVUtil_version())), + ffmpeg.NewMetadata("libavdevice_version", ffVersionAsString(ff.AVDevice_version())), + // newMetadata("libavfilter_version", ff.AVFilter_version()), + ffmpeg.NewMetadata("libswscale_version", ffVersionAsString(ff.SWScale_version())), + ffmpeg.NewMetadata("libswresample_version", ffVersionAsString(ff.SWResample_version())), + } + if GitSource != "" { + metadata = append(metadata, ffmpeg.NewMetadata("git_source", GitSource)) + } + if GitBranch != "" { + metadata = append(metadata, ffmpeg.NewMetadata("git_branch", GitBranch)) + } + if GitTag != "" { + metadata = append(metadata, ffmpeg.NewMetadata("git_tag", GitTag)) + } + if GoBuildTime != "" { + metadata = append(metadata, ffmpeg.NewMetadata("go_build_time", GoBuildTime)) + } + if runtime.Version() != "" { + metadata = append(metadata, ffmpeg.NewMetadata("go_version", runtime.Version())) + metadata = append(metadata, ffmpeg.NewMetadata("go_arch", runtime.GOOS+"/"+runtime.GOARCH)) + } + return metadata +} + +//////////////////////////////////////////////////////////////////////////// +// PRIVATE METHODS + +func ffVersionAsString(version uint) string { + return fmt.Sprintf("%d.%d.%d", version&0xFF0000>>16, version&0xFF00>>8, version&0xFF) +}