diff --git a/internal/photoprism/convert_test.go b/internal/photoprism/convert_test.go index e4094d4a1..6e2afa1e6 100644 --- a/internal/photoprism/convert_test.go +++ b/internal/photoprism/convert_test.go @@ -314,3 +314,92 @@ func TestConvert_AvcBitrate(t *testing.T) { assert.Equal(t, "50M", convert.AvcBitrate(mf)) }) } + +func TestConvert_AvcConvertCommand(t *testing.T) { + conf := config.TestConfig() + convert := NewConvert(conf) + + t.Run(".mp4", func(t *testing.T) { + fileName := filepath.Join(conf.ExamplesPath(), "gopher-video.mp4") + mf, err := NewMediaFile(fileName) + + if err != nil { + t.Fatal(err) + } + + r, _, err := convert.AvcConvertCommand(mf, "avc1", "") + + if err != nil { + t.Fatal(err) + } + assert.Contains(t, r.Path, "ffmpeg") + assert.Contains(t, r.Args, "mp4") + }) + t.Run(".jpg", func(t *testing.T) { + fileName := filepath.Join(conf.ExamplesPath(), "cat_black.jpg") + mf, err := NewMediaFile(fileName) + + if err != nil { + t.Fatal(err) + } + + r, _, err := convert.AvcConvertCommand(mf, "avc1", "") + assert.Error(t, err) + assert.Nil(t, r) + }) +} + +func TestConvert_ToAvc(t *testing.T) { + t.Run("gopher-video.mp4", func(t *testing.T) { + conf := config.TestConfig() + convert := NewConvert(conf) + + fileName := filepath.Join(conf.ExamplesPath(), "gopher-video.mp4") + outputName := filepath.Join(conf.SidecarPath(), conf.ExamplesPath(), "gopher-video.mp4.avc") + + _ = os.Remove(outputName) + + assert.Truef(t, fs.FileExists(fileName), "input file does not exist: %s", fileName) + + mf, err := NewMediaFile(fileName) + + if err != nil { + t.Fatal(err) + } + + avcFile, err := convert.ToAvc(mf, "") + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, avcFile.FileName(), outputName) + assert.Truef(t, fs.FileExists(avcFile.FileName()), "output file does not exist: %s", avcFile.FileName()) + + t.Logf("video metadata: %+v", avcFile.MetaData()) + + _ = os.Remove(outputName) + }) + + t.Run("jpg", func(t *testing.T) { + conf := config.TestConfig() + convert := NewConvert(conf) + + fileName := filepath.Join(conf.ExamplesPath(), "cat_black.jpg") + outputName := filepath.Join(conf.SidecarPath(), conf.ExamplesPath(), "cat_black.jpg.avc") + + _ = os.Remove(outputName) + + assert.Truef(t, fs.FileExists(fileName), "input file does not exist: %s", fileName) + + mf, err := NewMediaFile(fileName) + + if err != nil { + t.Fatal(err) + } + + avcFile, err := convert.ToAvc(mf, "") + assert.Error(t, err) + assert.Nil(t, avcFile) + }) +}