2021-02-18 14:39:08 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-04-06 17:46:41 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/ffmpeg"
|
|
|
|
|
2021-02-18 14:39:08 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_FFmpegEncoder(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
2022-04-06 17:46:41 +02:00
|
|
|
assert.Equal(t, ffmpeg.SoftwareEncoder, c.FFmpegEncoder())
|
|
|
|
c.options.FFmpegEncoder = "nvidia"
|
|
|
|
assert.Equal(t, ffmpeg.NvidiaEncoder, c.FFmpegEncoder())
|
|
|
|
c.options.FFmpegEncoder = "intel"
|
|
|
|
assert.Equal(t, ffmpeg.IntelEncoder, c.FFmpegEncoder())
|
|
|
|
c.options.FFmpegEncoder = "xxx"
|
|
|
|
assert.Equal(t, ffmpeg.SoftwareEncoder, c.FFmpegEncoder())
|
|
|
|
c.options.FFmpegEncoder = ""
|
|
|
|
assert.Equal(t, ffmpeg.SoftwareEncoder, c.FFmpegEncoder())
|
2021-02-18 14:39:08 +01:00
|
|
|
}
|
|
|
|
|
2021-08-24 19:09:09 +02:00
|
|
|
func TestConfig_FFmpegEnabled(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, true, c.FFmpegEnabled())
|
|
|
|
|
|
|
|
c.options.DisableFFmpeg = true
|
|
|
|
assert.Equal(t, false, c.FFmpegEnabled())
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:39:08 +01:00
|
|
|
func TestConfig_FFmpegBitrate(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, 50, c.FFmpegBitrate())
|
|
|
|
|
|
|
|
c.options.FFmpegBitrate = 1000
|
|
|
|
assert.Equal(t, 960, c.FFmpegBitrate())
|
|
|
|
|
|
|
|
c.options.FFmpegBitrate = -5
|
|
|
|
assert.Equal(t, 50, c.FFmpegBitrate())
|
|
|
|
|
|
|
|
c.options.FFmpegBitrate = 800
|
|
|
|
assert.Equal(t, 800, c.FFmpegBitrate())
|
|
|
|
}
|
2022-06-26 19:47:12 +02:00
|
|
|
|
2023-06-28 15:22:52 +02:00
|
|
|
func TestConfig_FFmpegResolution(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
2023-06-28 16:45:53 +02:00
|
|
|
assert.Equal(t, 4320, c.FFmpegResolution())
|
2023-06-28 15:22:52 +02:00
|
|
|
|
|
|
|
c.options.FFmpegResolution = 1920
|
|
|
|
assert.Equal(t, 1920, c.FFmpegResolution())
|
|
|
|
|
|
|
|
c.options.FFmpegResolution = 8640
|
|
|
|
assert.Equal(t, 4320, c.FFmpegResolution())
|
|
|
|
}
|
|
|
|
|
2022-06-26 19:47:12 +02:00
|
|
|
func TestConfig_FFmpegBitrateExceeded(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
c.options.FFmpegBitrate = 0
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(0.95))
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(1.05))
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(2.05))
|
|
|
|
c.options.FFmpegBitrate = 1
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(0.95))
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(1.0))
|
|
|
|
assert.True(t, c.FFmpegBitrateExceeded(1.05))
|
|
|
|
assert.True(t, c.FFmpegBitrateExceeded(2.05))
|
|
|
|
c.options.FFmpegBitrate = 50
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(0.95))
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(1.05))
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(2.05))
|
|
|
|
c.options.FFmpegBitrate = -5
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(0.95))
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(1.05))
|
|
|
|
assert.False(t, c.FFmpegBitrateExceeded(2.05))
|
|
|
|
}
|
2023-03-14 18:00:55 +01:00
|
|
|
|
|
|
|
func TestConfig_FFmpegMapVideo(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, ffmpeg.MapVideoDefault, c.FFmpegMapVideo())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_FFmpegMapAudio(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
assert.Equal(t, ffmpeg.MapAudioDefault, c.FFmpegMapAudio())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_FFmpegOptions(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
bitrate := "25M"
|
2023-06-28 15:22:52 +02:00
|
|
|
resolution := "1080"
|
|
|
|
opt, err := c.FFmpegOptions(ffmpeg.SoftwareEncoder, bitrate, resolution)
|
2023-03-14 18:00:55 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, c.FFmpegBin(), opt.Bin)
|
|
|
|
assert.Equal(t, ffmpeg.SoftwareEncoder, opt.Encoder)
|
|
|
|
assert.Equal(t, bitrate, opt.Bitrate)
|
|
|
|
assert.Equal(t, ffmpeg.MapVideoDefault, opt.MapVideo)
|
|
|
|
assert.Equal(t, ffmpeg.MapAudioDefault, opt.MapAudio)
|
|
|
|
assert.Equal(t, c.FFmpegMapVideo(), opt.MapVideo)
|
|
|
|
assert.Equal(t, c.FFmpegMapAudio(), opt.MapAudio)
|
2023-06-28 15:22:52 +02:00
|
|
|
assert.Equal(t, resolution, opt.Resolution)
|
2023-03-14 18:00:55 +01:00
|
|
|
}
|